@@ -205,10 +205,10 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast
205
205
206
206
if scanControllers {
207
207
// Match and add both structs and methods
208
- structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports )
208
+ structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports , fset )
209
209
appendAction (fset , methodSpecs , decl , pkgImportPath , pkg .Name , imports )
210
210
} else if scanTests {
211
- structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports )
211
+ structSpecs = appendStruct (structSpecs , pkgImportPath , pkg , decl , imports , fset )
212
212
}
213
213
214
214
// If this is a func...
@@ -302,9 +302,9 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
302
302
303
303
// If this Decl is a struct type definition, it is summarized and added to specs.
304
304
// Else, specs is returned unchanged.
305
- func appendStruct (specs []* TypeInfo , pkgImportPath string , pkg * ast.Package , decl ast.Decl , imports map [string ]string ) []* TypeInfo {
305
+ func appendStruct (specs []* TypeInfo , pkgImportPath string , pkg * ast.Package , decl ast.Decl , imports map [string ]string , fset * token. FileSet ) []* TypeInfo {
306
306
// Filter out non-Struct type declarations.
307
- spec , found := getStructTypeDecl (decl )
307
+ spec , found := getStructTypeDecl (decl , fset )
308
308
if ! found {
309
309
return specs
310
310
}
@@ -350,7 +350,6 @@ func appendStruct(specs []*TypeInfo, pkgImportPath string, pkg *ast.Package, dec
350
350
return pkgIdent .Name , selectorExpr .Sel .Name
351
351
}
352
352
}
353
-
354
353
return "" , ""
355
354
}()
356
355
@@ -607,7 +606,7 @@ func (s *embeddedTypeName) String() string {
607
606
608
607
// getStructTypeDecl checks if the given decl is a type declaration for a
609
608
// struct. If so, the TypeSpec is returned.
610
- func getStructTypeDecl (decl ast.Decl ) (spec * ast.TypeSpec , found bool ) {
609
+ func getStructTypeDecl (decl ast.Decl , fset * token. FileSet ) (spec * ast.TypeSpec , found bool ) {
611
610
genDecl , ok := decl .(* ast.GenDecl )
612
611
if ! ok {
613
612
return
@@ -617,15 +616,13 @@ func getStructTypeDecl(decl ast.Decl) (spec *ast.TypeSpec, found bool) {
617
616
return
618
617
}
619
618
620
- if len (genDecl .Specs ) != 1 {
621
- revel .TRACE .Printf ("Surprising: Decl does not have 1 Spec: %v " , genDecl )
619
+ if len (genDecl .Specs ) == 0 {
620
+ revel .WARN .Printf ("Surprising: %s:%d Decl contains no specifications " , fset . Position ( decl . Pos ()). Filename , fset . Position ( decl . Pos ()). Line )
622
621
return
623
622
}
624
623
625
624
spec = genDecl .Specs [0 ].(* ast.TypeSpec )
626
- if _ , ok := spec .Type .(* ast.StructType ); ok {
627
- found = true
628
- }
625
+ _ , found = spec .Type .(* ast.StructType )
629
626
630
627
return
631
628
}
0 commit comments