Add support for TypeSpec docs

Since doc's can be added on both the generic declaration (GenDecl) as well as on the type declaration (TypeSpec) we need to check both.
In order to check both declaration we copy the GenDecl docs to the TypeSpec docs if the TypeSpec has no documentation.
This commit is contained in:
warnar boekkooi
2019-03-28 17:45:34 +01:00
parent d3fc79bc1b
commit fc8e2d7bfe
+19 -7
View File
@@ -21,8 +21,7 @@ type Parser struct {
type visitor struct {
*Parser
name string
explicit bool
name string
}
func (p *Parser) needType(comments string) bool {
@@ -43,20 +42,33 @@ func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
return v
case *ast.GenDecl:
v.explicit = v.needType(n.Doc.Text())
if !v.explicit && !v.AllStructs {
return nil
explicit := v.needType(n.Doc.Text())
if !explicit {
return v
}
for _, nc := range n.Specs {
switch nct := nc.(type) {
case *ast.TypeSpec:
nct.Doc = n.Doc
}
}
return v
case *ast.TypeSpec:
explicit := v.needType(n.Doc.Text())
if !explicit && !v.AllStructs {
return nil
}
v.name = n.Name.String()
// Allow to specify non-structs explicitly independent of '-all' flag.
if v.explicit {
if explicit {
v.StructNames = append(v.StructNames, v.name)
return nil
}
return v
case *ast.StructType:
v.StructNames = append(v.StructNames, v.name)