}
+func isForwardDecl(typ ast.Expr) bool {
+ switch t := typ.(type) {
+ case *ast.StructType:
+ return t.Fields == nil;
+ case *ast.InterfaceType:
+ return t.Methods == nil;
+ }
+ return false;
+}
+
+
func (doc *docReader) addType(decl *ast.GenDecl) {
- typ := decl.Specs[0].(*ast.TypeSpec);
- name := typ.Name.Value;
- if _, found := doc.types[name]; !found {
- tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)};
- doc.types[name] = tdoc;
+ spec := decl.Specs[0].(*ast.TypeSpec);
+ name := spec.Name.Value;
+ if tdoc, found := doc.types[name]; found {
+ if !isForwardDecl(tdoc.decl.Specs[0].(*ast.TypeSpec).Type) || isForwardDecl(spec.Type) {
+ // existing type was not a forward-declaration or the
+ // new type is a forward declaration - leave it alone
+ return;
+ }
+ // replace existing type
}
- // If the type was found it may have been added as a forward
- // declaration before, or this is a forward-declaration.
+ tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)};
+ doc.types[name] = tdoc;
}