@@ -3,6 +3,8 @@ package interfaces
33import (
44 "fmt"
55 "go/types"
6+ "path"
7+ "strings"
68)
79
810// Type is a simple representation of a single parameter type.
@@ -12,6 +14,7 @@ type Type struct {
1214 ImportPath string `json:"importPath,omitempty"` // import path of the package
1315 IsPointer bool `json:"isPointer,omitempty"` // whether the parameter is a pointer
1416 IsComposite bool `json:"isComposite,omitempty"` // whether the type is map, slice, chan or array
17+ IsFunc bool `json:"isFunc,omitempty"` // whether the type if function
1518}
1619
1720// String gives Go code representation of the type.
@@ -51,6 +54,9 @@ func (typ *Type) setFromType(t types.Type, depth int, orig types.Type) {
5154 typ .setFromStruct (t )
5255 case * types.Named :
5356 typ .setFromNamed (t )
57+ case * types.Signature :
58+ typ .IsFunc = true
59+ typ .setFromSignature (t )
5460 case * types.Pointer :
5561 if depth == 0 {
5662 typ .IsPointer = true
@@ -84,6 +90,12 @@ func (typ *Type) setFromStruct(t *types.Struct) {
8490 }
8591}
8692
93+ func (typ * Type ) setFromSignature (t * types.Signature ) {
94+ if typ .Name == "" {
95+ typ .Name = t .String ()
96+ }
97+ }
98+
8799func (typ * Type ) setFromNamed (t * types.Named ) {
88100 if typ .Name == "" {
89101 typ .Name = t .Obj ().Name ()
@@ -104,3 +116,16 @@ func (typ *Type) setFromComposite(t compositeType, depth int, orig types.Type) {
104116 }
105117 typ .setFromType (t .Elem (), depth + 1 , orig )
106118}
119+
120+ func fixup (typ * Type , q * Query ) {
121+ // Hacky fixup for renaming:
122+ //
123+ // GeoAdd(string, []*github.com/go-redis/redis.GeoLocation) *redis.IntCmd
124+ //
125+ // to:
126+ //
127+ // GeoAdd(string, []*redis.GeoLocation) *redis.IntCmd
128+ //
129+ // Should be fixed layer below, in type.go.
130+ typ .Name = strings .Replace (typ .Name , q .Package , path .Base (q .Package ), - 1 )
131+ }
0 commit comments