github.com/go-generalize/volcago@v1.7.0/generator/replacer.go (about)

     1  package generator
     2  
     3  import (
     4  	"go/types"
     5  
     6  	eptypes "github.com/go-generalize/go-easyparser/types"
     7  )
     8  
     9  type documentRef struct {
    10  	eptypes.Common
    11  }
    12  
    13  var _ eptypes.Type = &documentRef{}
    14  
    15  // UsedAsMapKey returns whether this type can be used as the key for map
    16  func (dr *documentRef) UsedAsMapKey() bool {
    17  	return false
    18  }
    19  
    20  // String returns this type in string representation
    21  func (dr *documentRef) String() string {
    22  	return "firestore.DocumentRef"
    23  }
    24  
    25  type latLng struct {
    26  	eptypes.Common
    27  }
    28  
    29  var _ eptypes.Type = &latLng{}
    30  
    31  // UsedAsMapKey returns whether this type can be used as the key for map
    32  func (dr *latLng) UsedAsMapKey() bool {
    33  	return false
    34  }
    35  
    36  // String returns this type in string representation
    37  func (dr *latLng) String() string {
    38  	return "latlng.LatLng"
    39  }
    40  
    41  type unsupportedFunction struct {
    42  	eptypes.Common
    43  }
    44  
    45  var _ eptypes.Type = &unsupportedFunction{}
    46  
    47  // UsedAsMapKey returns whether this type can be used as the key for map
    48  func (uf *unsupportedFunction) UsedAsMapKey() bool {
    49  	return false
    50  }
    51  
    52  // String returns this type in string representation
    53  func (uf *unsupportedFunction) String() string {
    54  	return "<unsupported function type>"
    55  }
    56  
    57  // replacer replaces eptypes for firestore with specific eptypes in parser
    58  func replacer(t types.Type) eptypes.Type {
    59  	_, ok := t.(*types.Signature)
    60  
    61  	if ok {
    62  		return &unsupportedFunction{}
    63  	}
    64  
    65  	named, ok := t.(*types.Named)
    66  
    67  	if !ok {
    68  		return nil
    69  	}
    70  
    71  	if named.String() == "cloud.google.com/go/firestore.DocumentRef" {
    72  		return &documentRef{}
    73  	}
    74  
    75  	if named.String() == "google.golang.org/genproto/googleapis/type/latlng.LatLng" {
    76  		return &latLng{}
    77  	}
    78  
    79  	return nil
    80  }