1package astwalk 2 3import ( 4 "go/ast" 5) 6 7type localExprWalker struct { 8 visitor LocalExprVisitor 9} 10 11func (w *localExprWalker) WalkFile(f *ast.File) { 12 if !w.visitor.EnterFile(f) { 13 return 14 } 15 16 for _, decl := range f.Decls { 17 decl, ok := decl.(*ast.FuncDecl) 18 if !ok || !w.visitor.EnterFunc(decl) { 19 continue 20 } 21 ast.Inspect(decl.Body, func(x ast.Node) bool { 22 if x, ok := x.(ast.Expr); ok { 23 w.visitor.VisitLocalExpr(x) 24 return !w.visitor.skipChilds() 25 } 26 return true 27 }) 28 } 29} 30