Simplify generate.go to only look at ast nodes Ident, TypeSwitchStmt,

and FuncDecl.
This commit is contained in:
Greg 2018-08-06 13:58:12 -04:00
parent 4c5821c7d5
commit 384de4d02c

View File

@ -40,8 +40,8 @@ func sub(dst *string,spec subspec) {
func (g *Generator) Visit(node ast.Node) ast.Visitor { func (g *Generator) Visit(node ast.Node) ast.Visitor {
switch n := node.(type) { switch n := node.(type) {
case *ast.Ident: case *ast.Ident:
subs(&n.Name,g.nspecs)
if n.Obj != nil && n.Obj.Kind == ast.Typ { if n.Obj != nil && n.Obj.Kind == ast.Typ {
subs(&n.Name,g.nspecs)
subs(&n.Obj.Name,g.nspecs) subs(&n.Obj.Name,g.nspecs)
} }
case *ast.TypeSwitchStmt: case *ast.TypeSwitchStmt:
@ -52,34 +52,8 @@ func (g *Generator) Visit(node ast.Node) ast.Visitor {
subs(&ci.Name,g.nspecs) subs(&ci.Name,g.nspecs)
} }
} }
case *ast.TypeAssertExpr:
nt, ok := n.Type.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.Ellipsis:
nt, ok := n.Elt.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.Field:
nt, ok := n.Type.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.StarExpr:
nt, ok := n.X.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.ValueSpec:
nt, ok := n.Type.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.ArrayType:
nt, ok := n.Elt.(*ast.Ident); if !ok { return g }
subs(&nt.Name,g.nspecs)
case *ast.MapType:
nt, ok := n.Key.(*ast.Ident); if ok {
subs(&nt.Name,g.nspecs)
}
nt, ok = n.Value.(*ast.Ident); if ok {
subs(&nt.Name,g.nspecs)
}
case *ast.FuncDecl: case *ast.FuncDecl:
sub(&n.Name.Name,g.fspec) sub(&n.Name.Name,g.fspec)
//ast.Print(g.fset,n)
} }
return g return g
} }