@@ -212,10 +212,10 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
212
212
213
213
if scanControllers {
214
214
// Match and add both structs and methods
215
- structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports )
215
+ structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports , fset )
216
216
appendAction (fset , methodSpecs , decl , pkgImportPath , pkg .Name , imports )
217
217
} else if scanTests {
218
- structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports )
218
+ structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports , fset )
219
219
}
220
220
221
221
// If this is a func...
@@ -309,9 +309,9 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
309
309
310
310
// If this Decl is a struct type definition, it is summarized and added to specs.
311
311
// Else, specs is returned unchanged.
312
- func appendStruct (specs []* TypeInfo , pkgImportPath string , pkg * ast.Package , decl ast.Decl , imports map [string ]string ) []* TypeInfo {
312
+ func appendStruct (specs []* TypeInfo , pkgImportPath string , pkg * ast.Package , decl ast.Decl , imports map [string ]string , fset * token. FileSet ) []* TypeInfo {
313
313
// Filter out non-Struct type declarations.
314
- spec , found := getStructTypeDecl (decl )
314
+ spec , found := getStructTypeDecl (decl , fset )
315
315
if ! found {
316
316
return specs
317
317
}
@@ -357,7 +357,6 @@ func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, dec
357
357
return pkgIdent .Name , selectorExpr .Sel .Name
358
358
}
359
359
}
360
-
361
360
return "" , ""
362
361
}()
363
362
@@ -614,7 +613,7 @@ func (s *embeddedTypeName) String() string {
614
613
615
614
// getStructTypeDecl checks if the given decl is a type declaration for a
616
615
// struct. If so, the TypeSpec is returned.
617
- func getStructTypeDecl (decl ast.Decl ) (spec * ast.TypeSpec , found bool ) {
616
+ func getStructTypeDecl (decl ast.Decl , fset * token. FileSet ) (spec * ast.TypeSpec , found bool ) {
618
617
genDecl , ok := decl .(* ast.GenDecl )
619
618
if ! ok {
620
619
return
@@ -624,15 +623,13 @@ func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
624
623
return
625
624
}
626
625
627
- if len (genDecl .Specs ) != 1 {
628
- revel .TRACE .Printf ("Surprising: Decl does not have 1 Spec: %v " , genDecl )
626
+ if len (genDecl .Specs ) == 0 {
627
+ revel .WARN .Printf ("Surprising: %s:%d Decl contains no specifications " , fset . Position ( decl . Pos ()). Filename , fset . Position ( decl . Pos ()). Line )
629
628
return
630
629
}
631
630
632
631
spec = genDecl .Specs [0 ].(* ast.TypeSpec )
633
- if _ , ok := spec .Type .(* ast.StructType ); ok {
634
- found = true
635
- }
632
+ _ , found = spec .Type .(* ast.StructType )
636
633
637
634
return
638
635
}
0 commit comments