Golang go/ast.FilterDecl() function example

package go/ast

FilterDecl trims the AST for a Go declaration in place by removing all names (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f.

FilterDecl returns true if there are any declared names left after filtering; it returns false otherwise.

Golang go/ast.FilterDecl() function usage example

 func filterFile(src *File, f Filter, export bool) bool {
  j := 0
  for _, d := range src.Decls {
 if filterDecl(d, f, export) { // <-- here
 src.Decls[j] = d
 j++
 }
  }
  src.Decls = src.Decls[0:j]
  return j > 0
 }

References :

http://golang.org/pkg/go/ast/#FilterDecl

https://github.com/DAddYE/igo/blob/master/ast/filter.go

Advertisement