From 384de4d02c79ae56d6b0e3d3e6f58ae1b52aa845 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 6 Aug 2018 13:58:12 -0400 Subject: [PATCH] Simplify generate.go to only look at ast nodes Ident, TypeSwitchStmt, and FuncDecl. --- generate/generate.go | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index 5cf188b..dd29ed6 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -40,8 +40,8 @@ func sub(dst *string,spec subspec) { func (g *Generator) Visit(node ast.Node) ast.Visitor { switch n := node.(type) { case *ast.Ident: + subs(&n.Name,g.nspecs) if n.Obj != nil && n.Obj.Kind == ast.Typ { - subs(&n.Name,g.nspecs) subs(&n.Obj.Name,g.nspecs) } case *ast.TypeSwitchStmt: @@ -52,34 +52,8 @@ func (g *Generator) Visit(node ast.Node) ast.Visitor { 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: sub(&n.Name.Name,g.fspec) - //ast.Print(g.fset,n) } return g }