Skip to content

Commit 097ea76

Browse files
committed
Fix parsing field types for when we have generic method receivers
1 parent fd46275 commit 097ea76

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

parser/class_parser.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,19 @@ func (p *ClassParser) parsePackage(node ast.Node) {
220220
for fileName := range pack.Files {
221221
sortedFiles = append(sortedFiles, fileName)
222222
}
223+
223224
sort.Strings(sortedFiles)
224225
for _, fileName := range sortedFiles {
226+
if strings.HasSuffix(fileName, "_test.go") {
227+
continue
228+
}
225229

226-
if !strings.HasSuffix(fileName, "_test.go") {
227-
f := pack.Files[fileName]
228-
for _, d := range f.Imports {
229-
p.parseImports(d)
230-
}
231-
for _, d := range f.Decls {
232-
p.parseFileDeclarations(d)
233-
}
230+
f := pack.Files[fileName]
231+
for _, d := range f.Imports {
232+
p.parseImports(d)
233+
}
234+
for _, d := range f.Decls {
235+
p.parseFileDeclarations(d)
234236
}
235237
}
236238
}

parser/field.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,24 @@ func getFieldType(exp ast.Expr, aliases map[string]string) (string, []string) {
4040
return getFuncType(v, aliases)
4141
case *ast.Ellipsis:
4242
return getEllipsis(v, aliases)
43+
case *ast.IndexExpr:
44+
return getIndexExpr(v, aliases)
4345
}
4446
return "", []string{}
4547
}
4648

49+
func getIndexExpr(v *ast.IndexExpr, aliases map[string]string) (string, []string) {
50+
switch t := v.X.(type) {
51+
case *ast.Ident:
52+
return getIdent(t, aliases)
53+
case *ast.SelectorExpr:
54+
return getSelectorExp(t, aliases)
55+
default:
56+
return "", []string{}
57+
}
58+
59+
}
60+
4761
func getIdent(v *ast.Ident, aliases map[string]string) (string, []string) {
4862
if isPrimitive(v) {
4963
return v.Name, []string{}

0 commit comments

Comments
 (0)