mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
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:
+19
-7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user