package ast

Import Path
	go/ast (on golang.org and go.dev)

Dependency Relation
	imports 10 packages, and imported by 7 packages

Involved Source Files
	d-> ast.go
	    commentmap.go
	    filter.go
	    import.go
	    print.go
	    resolve.go
	    scope.go
	    walk.go

Exported Type Names

type ArrayType (struct) An ArrayType node represents an array or slice type. // element type // position of "[" // Ellipsis node for [...]T array types, nil for slice types (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type AssignStmt (struct) An AssignStmt node represents an assignment or a short variable declaration. Lhs []Expr Rhs []Expr // assignment token, DEFINE // position of Tok (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type BadDecl (struct) A BadDecl node is a placeholder for a declaration containing syntax errors for which a correct declaration node cannot be created. // position range of bad expression // position range of bad expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Decl *T : Node
type BadExpr (struct) A BadExpr node is a placeholder for an expression containing syntax errors for which a correct expression node cannot be created. // position range of bad expression // position range of bad expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type BadStmt (struct) A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created. // position range of bad expression // position range of bad expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type BasicLit (struct) A BasicLit node represents a literal of basic type. // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', '\x7f', "foo" or `\m\n\o` // literal position (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type BinaryExpr (struct) A BinaryExpr node represents a binary expression. // operator // position of Op // left operand // right operand (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type BlockStmt (struct) A BlockStmt node represents a braced statement list. // position of "{" List []Stmt // position of "}", if any (may be absent due to syntax error) (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type BranchStmt (struct) A BranchStmt node represents a break, continue, goto, or fallthrough statement. // label name; or nil // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH) // position of Tok (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type CallExpr (struct) A CallExpr node represents an expression followed by an argument list. // function arguments; or nil // position of "..." (token.NoPos if there is no "...") // function expression // position of "(" // position of ")" (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type CaseClause (struct) A CaseClause represents a case of an expression or type switch statement. // statement list; or nil // position of "case" or "default" keyword // position of ":" // list of expressions or types; nil means default case (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type ChanDir int The direction of a channel type is indicated by a bit mask including one or both of the following constants. const RECV const SEND
type ChanType (struct) A ChanType node represents a channel type. // position of "<-" (token.NoPos if there is no "<-") // position of "chan" keyword or "<-" (whichever comes first) // channel direction // value type (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type CommClause (struct) A CommClause node represents a case of a select statement. // statement list; or nil // position of "case" or "default" keyword // position of ":" // send or receive statement; nil means default case (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Comment (struct) A Comment node represents a single //-style or /*-style comment. // position of "/" starting the comment // comment text (excluding '\n' for //-style comments) (*T) End() token.Pos (*T) Pos() token.Pos *T : Node
type CommentGroup (struct) A CommentGroup represents a sequence of comments with no other tokens and no empty lines between. // len(List) > 0 (*T) End() token.Pos (*T) Pos() token.Pos Text returns the text of the comment. Comment markers (//, /*, and */), the first space of a line comment, and leading and trailing empty lines are removed. Comment directives like "//line" and "//go:noinline" are also removed. Multiple empty lines are reduced to one, and trailing space on lines is trimmed. Unless the result is empty, it is newline-terminated. *T : Node func CommentMap.Comments() []*CommentGroup func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap
type CommentMap (map) A CommentMap maps an AST node to a list of comment groups associated with it. See NewCommentMap for a description of the association. Comments returns the list of comment groups in the comment map. The result is sorted in source order. Filter returns a new comment map consisting of only those entries of cmap for which a corresponding node exists in the AST specified by node. ( T) String() string Update replaces an old node in the comment map with the new node and returns the new node. Comments that were associated with the old node are associated with the new node. T : expvar.Var T : fmt.Stringer func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap func CommentMap.Filter(node Node) CommentMap
type CompositeLit (struct) A CompositeLit node represents a composite literal. // list of composite elements; or nil // true if (source) expressions are missing in the Elts list // position of "{" // position of "}" // literal type; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type Decl (interface) All declaration nodes implement the Decl interface. // position of first character immediately after the node // position of first character belonging to the node *BadDecl *FuncDecl *GenDecl T : Node func FilterDecl(decl Decl, f Filter) bool
type DeclStmt (struct) A DeclStmt node represents a declaration in a statement list. // *GenDecl with CONST, TYPE, or VAR token (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type DeferStmt (struct) A DeferStmt node represents a defer statement. Call *CallExpr // position of "defer" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Ellipsis (struct) An Ellipsis node stands for the "..." type in a parameter list or the "..." length in an array type. // position of "..." // ellipsis element type (parameter lists only); or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type EmptyStmt (struct) An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately following (explicit or implicit) semicolon. // if set, ";" was omitted in the source // position of following ";" (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Expr (interface) All expression nodes implement the Expr interface. // position of first character immediately after the node // position of first character belonging to the node *ArrayType *BadExpr *BasicLit *BinaryExpr *CallExpr *ChanType *CompositeLit *Ellipsis *FuncLit *FuncType *Ident *IndexExpr *InterfaceType *KeyValueExpr *MapType *ParenExpr *SelectorExpr *SliceExpr *StarExpr *StructType *TypeAssertExpr *UnaryExpr T : Node func go/parser.ParseExpr(x string) (Expr, error) func go/parser.ParseExprFrom(fset *token.FileSet, filename string, src interface{}, mode parser.Mode) (expr Expr, err error) func go/types.CheckExpr(fset *token.FileSet, pkg *types.Package, pos token.Pos, expr Expr, info *types.Info) (err error) func go/types.ExprString(x Expr) string func go/types.WriteExpr(buf *bytes.Buffer, x Expr) func go/types.(*Info).TypeOf(e Expr) types.Type
type ExprStmt (struct) An ExprStmt node represents a (stand-alone) expression in a statement list. // expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Field (struct) A Field represents a Field declaration list in a struct type, a method list in an interface type, or a parameter/result declaration in a signature. Field.Names is nil for unnamed parameters (parameter lists which only contain types) and embedded struct fields. In the latter case, the field name is the type name. // line comments; or nil // associated documentation; or nil // field/method/parameter names; or nil // field tag; or nil // field/method/parameter type (*T) End() token.Pos (*T) Pos() token.Pos *T : Node
type FieldFilter (func) A FieldFilter may be provided to Fprint to control the output. func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) error
type FieldList (struct) A FieldList represents a list of Fields, enclosed by parentheses or braces. // position of closing parenthesis/brace, if any // field list; or nil // position of opening parenthesis/brace, if any (*T) End() token.Pos NumFields returns the number of parameters or struct fields represented by a FieldList. (*T) Pos() token.Pos *T : Node
type File (struct) A File node represents a Go source file. The Comments list contains all comments in the source file in order of appearance, including the comments that are pointed to from other nodes via Doc and Comment fields. For correct printing of source code containing comments (using packages go/format and go/printer), special care must be taken to update comments when a File's syntax tree is modified: For printing, comments are interspersed between tokens based on their position. If syntax tree nodes are removed or moved, relevant comments in their vicinity must also be removed (from the File.Comments list) or moved accordingly (by updating their positions). A CommentMap may be used to facilitate some of these operations. Whether and how a comment is associated with a node depends on the interpretation of the syntax tree by the manipulating program: Except for Doc and Comment comments directly associated with nodes, the remaining comments are "free-floating" (see also issues #18593, #20744). // list of all comments in the source file // top-level declarations; or nil // associated documentation; or nil // imports in this file // package name // position of "package" keyword // package scope (this file only) // unresolved identifiers in this file (*T) End() token.Pos (*T) Pos() token.Pos *T : Node func MergePackageFiles(pkg *Package, mode MergeMode) *File func go/parser.ParseFile(fset *token.FileSet, filename string, src interface{}, mode parser.Mode) (f *File, err error) func FileExports(src *File) bool func FilterFile(src *File, f Filter) bool func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error) func SortImports(fset *token.FileSet, f *File) func go/doc.Examples(testFiles ...*File) []*doc.Example func go/doc.NewFromFiles(fset *token.FileSet, files []*File, importPath string, opts ...interface{}) (*doc.Package, error) func go/types.(*Checker).Files(files []*File) error func go/types.(*Config).Check(path string, fset *token.FileSet, files []*File, info *types.Info) (*types.Package, error)
type Filter (func) func FilterDecl(decl Decl, f Filter) bool func FilterFile(src *File, f Filter) bool func FilterPackage(pkg *Package, f Filter) bool
type ForStmt (struct) A ForStmt represents a for statement. Body *BlockStmt // condition; or nil // position of "for" keyword // initialization statement; or nil // post iteration statement; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type FuncDecl (struct) A FuncDecl node represents a function declaration. // function body; or nil for external (non-Go) function // associated documentation; or nil // function/method name // receiver (methods); or nil (functions) // function signature: parameters, results, and position of "func" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Decl *T : Node
type FuncLit (struct) A FuncLit node represents a function literal. // function body // function type (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type FuncType (struct) A FuncType node represents a function type. // position of "func" keyword (token.NoPos if there is no "func") // (incoming) parameters; non-nil // (outgoing) results; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type GenDecl (struct) A GenDecl node (generic declaration node) represents an import, constant, type or variable declaration. A valid Lparen position (Lparen.IsValid()) indicates a parenthesized declaration. Relationship between Tok value and Specs element type: token.IMPORT *ImportSpec token.CONST *ValueSpec token.TYPE *TypeSpec token.VAR *ValueSpec // associated documentation; or nil // position of '(', if any // position of ')', if any Specs []Spec // IMPORT, CONST, TYPE, VAR // position of Tok (*T) End() token.Pos (*T) Pos() token.Pos *T : Decl *T : Node
type GoStmt (struct) A GoStmt node represents a go statement. Call *CallExpr // position of "go" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Ident (struct) An Ident node represents an identifier. // identifier name // identifier position // denoted object; or nil (*T) End() token.Pos IsExported reports whether id starts with an upper-case letter. (*T) Pos() token.Pos (*T) String() string *T : Expr *T : Node *T : expvar.Var *T : fmt.Stringer func NewIdent(name string) *Ident func go/types.(*Info).ObjectOf(id *Ident) types.Object
type IfStmt (struct) An IfStmt node represents an if statement. Body *BlockStmt // condition // else branch; or nil // position of "if" keyword // initialization statement; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Importer (func) An Importer resolves import paths to package Objects. The imports map records the packages already imported, indexed by package id (canonical import path). An Importer must determine the canonical import path and check the map to see if it is already present in the imports map. If so, the Importer can return the map entry. Otherwise, the Importer should load the package data for the given path into a new *Object (pkg), record pkg in the imports map, and then return pkg. func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error)
type ImportSpec (struct) An ImportSpec node represents a single package import. // line comments; or nil // associated documentation; or nil // end of spec (overrides Path.Pos if nonzero) // local package name (including "."); or nil // import path (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Spec
type IncDecStmt (struct) An IncDecStmt node represents an increment or decrement statement. // INC or DEC // position of Tok X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type IndexExpr (struct) An IndexExpr node represents an expression followed by an index. // index expression // position of "[" // position of "]" // expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type InterfaceType (struct) An InterfaceType node represents an interface type. // true if (source) methods are missing in the Methods list // position of "interface" keyword // list of methods (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type KeyValueExpr (struct) A KeyValueExpr node represents (key : value) pairs in composite literals. // position of ":" Key Expr Value Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type LabeledStmt (struct) A LabeledStmt node represents a labeled statement. // position of ":" Label *Ident Stmt Stmt (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type MapType (struct) A MapType node represents a map type. Key Expr // position of "map" keyword Value Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type MergeMode uint The MergeMode flags control the behavior of MergePackageFiles. func MergePackageFiles(pkg *Package, mode MergeMode) *File const FilterFuncDuplicates const FilterImportDuplicates const FilterUnassociatedComments
type Node (interface) All node types implement the Node interface. // position of first character immediately after the node // position of first character belonging to the node *ArrayType *AssignStmt *BadDecl *BadExpr *BadStmt *BasicLit *BinaryExpr *BlockStmt *BranchStmt *CallExpr *CaseClause *ChanType *CommClause *Comment *CommentGroup *CompositeLit Decl (interface) *DeclStmt *DeferStmt *Ellipsis *EmptyStmt Expr (interface) *ExprStmt *Field *FieldList *File *ForStmt *FuncDecl *FuncLit *FuncType *GenDecl *GoStmt *Ident *IfStmt *ImportSpec *IncDecStmt *IndexExpr *InterfaceType *KeyValueExpr *LabeledStmt *MapType *Package *ParenExpr *RangeStmt *ReturnStmt *SelectorExpr *SelectStmt *SendStmt *SliceExpr Spec (interface) *StarExpr Stmt (interface) *StructType *SwitchStmt *TypeAssertExpr *TypeSpec *TypeSwitchStmt *UnaryExpr *ValueSpec go/types.(*Scope) func CommentMap.Update(old, new Node) Node func Inspect(node Node, f func(Node) bool) func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap func Walk(v Visitor, node Node) func CommentMap.Filter(node Node) CommentMap func CommentMap.Update(old, new Node) Node func Visitor.Visit(node Node) (w Visitor)
type Object (struct) An Object describes a named language entity such as a package, constant, type, variable, function (incl. methods), or label. The Data fields contains object-specific data: Kind Data type Data value Pkg *Scope package scope Con int iota for the respective declaration // object-specific data; or nil // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil Kind ObjKind // declared name // placeholder for type information; may be nil Pos computes the source position of the declaration of an object name. The result may be an invalid position if it cannot be computed (obj.Decl may be nil or not correct). func NewObj(kind ObjKind, name string) *Object func (*Scope).Insert(obj *Object) (alt *Object) func (*Scope).Lookup(name string) *Object func (*Scope).Insert(obj *Object) (alt *Object)
type ObjKind int ObjKind describes what an object represents. ( T) String() string T : expvar.Var T : fmt.Stringer func NewObj(kind ObjKind, name string) *Object const Bad const Con const Fun const Lbl const Pkg const Typ const Var
type Package (struct) A Package node represents a set of source files collectively building a Go package. // Go source files by filename // map of package id -> package object // package name // package scope across all files (*T) End() token.Pos (*T) Pos() token.Pos *T : Node func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error) func go/parser.ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode parser.Mode) (pkgs map[string]*Package, first error) func FilterPackage(pkg *Package, f Filter) bool func MergePackageFiles(pkg *Package, mode MergeMode) *File func PackageExports(pkg *Package) bool func go/doc.New(pkg *Package, importPath string, mode doc.Mode) *doc.Package
type ParenExpr (struct) A ParenExpr node represents a parenthesized expression. // position of "(" // position of ")" // parenthesized expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type RangeStmt (struct) A RangeStmt represents a for statement with a range clause. Body *BlockStmt // position of "for" keyword // Key, Value may be nil // ILLEGAL if Key == nil, ASSIGN, DEFINE // position of Tok; invalid if Key == nil // Key, Value may be nil // value to range over (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type ReturnStmt (struct) A ReturnStmt node represents a return statement. // result expressions; or nil // position of "return" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Scope (struct) A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope. Objects map[string]*Object Outer *Scope Insert attempts to insert a named object obj into the scope s. If the scope already contains an object alt with the same name, Insert leaves the scope unchanged and returns alt. Otherwise it inserts obj and returns nil. Lookup returns the object with the given name if it is found in scope s, otherwise it returns nil. Outer scopes are ignored. Debugging support *T : expvar.Var *T : fmt.Stringer func NewScope(outer *Scope) *Scope func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error) func NewScope(outer *Scope) *Scope
type SelectorExpr (struct) A SelectorExpr node represents an expression followed by a selector. // field selector // expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type SelectStmt (struct) A SelectStmt node represents a select statement. // CommClauses only // position of "select" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type SendStmt (struct) A SendStmt node represents a send statement. // position of "<-" Chan Expr Value Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type SliceExpr (struct) A SliceExpr node represents an expression followed by slice indices. // end of slice range; or nil // position of "[" // begin of slice range; or nil // maximum capacity of slice; or nil // position of "]" // true if 3-index slice (2 colons present) // expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type Spec (interface) The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec. // position of first character immediately after the node // position of first character belonging to the node *ImportSpec *TypeSpec *ValueSpec T : Node
type StarExpr (struct) A StarExpr node represents an expression of the form "*" Expression. Semantically it could be a unary "*" expression, or a pointer type. // position of "*" // operand (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type Stmt (interface) All statement nodes implement the Stmt interface. // position of first character immediately after the node // position of first character belonging to the node *AssignStmt *BadStmt *BlockStmt *BranchStmt *CaseClause *CommClause *DeclStmt *DeferStmt *EmptyStmt *ExprStmt *ForStmt *GoStmt *IfStmt *IncDecStmt *LabeledStmt *RangeStmt *ReturnStmt *SelectStmt *SendStmt *SwitchStmt *TypeSwitchStmt T : Node
type StructType (struct) A StructType node represents a struct type. // list of field declarations // true if (source) fields are missing in the Fields list // position of "struct" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type SwitchStmt (struct) A SwitchStmt node represents an expression switch statement. // CaseClauses only // initialization statement; or nil // position of "switch" keyword // tag expression; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type TypeAssertExpr (struct) A TypeAssertExpr node represents an expression followed by a type assertion. // position of "(" // position of ")" // asserted type; nil means type switch X.(type) // expression (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type TypeSpec (struct) A TypeSpec node represents a type declaration (TypeSpec production). // position of '=', if any // line comments; or nil // associated documentation; or nil // type name // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Spec
type TypeSwitchStmt (struct) A TypeSwitchStmt node represents a type switch statement. // x := y.(type) or y.(type) // CaseClauses only // initialization statement; or nil // position of "switch" keyword (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type UnaryExpr (struct) A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes. // operator // position of Op // operand (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type ValueSpec (struct) A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production). // line comments; or nil // associated documentation; or nil // value names (len(Names) > 0) // value type; or nil // initial values; or nil (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Spec
type Visitor (interface) A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil). ( T) Visit(node Node) (w Visitor) func Visitor.Visit(node Node) (w Visitor) func Walk(v Visitor, node Node)
Exported Values
const Bad ObjKind = 0 // for error handling The list of possible Object kinds.
const Con ObjKind = 2 // constant The list of possible Object kinds.
func FileExports(src *File) bool FileExports trims the AST for a Go source file in place such that only exported nodes remain: all top-level identifiers which are not exported and their associated information (such as type, initial value, or function body) are removed. Non-exported fields and methods of exported types are stripped. The File.Comments list is not changed. FileExports reports whether there are exported declarations.
func FilterDecl(decl Decl, f Filter) bool 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 reports whether there are any declared names left after filtering.
func FilterFile(src *File, f Filter) bool FilterFile trims the AST for a Go file in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. Import declarations are always removed. The File.Comments list is not changed. FilterFile reports whether there are any top-level declarations left after filtering.
const FilterFuncDuplicates MergeMode = 1 If set, duplicate function declarations are excluded.
const FilterImportDuplicates MergeMode = 4 If set, duplicate import declarations are excluded.
func FilterPackage(pkg *Package, f Filter) bool FilterPackage trims the AST for a Go package in place by removing all names from top-level declarations (including struct field and interface method names, but not from parameter lists) that don't pass through the filter f. If the declaration is empty afterwards, the declaration is removed from the AST. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost. FilterPackage reports whether there are any top-level declarations left after filtering.
const FilterUnassociatedComments MergeMode = 2 If set, comments that are not associated with a specific AST node (as Doc or Comment) are excluded.
func Fprint(w io.Writer, fset *token.FileSet, x interface{}, f FieldFilter) error Fprint prints the (sub-)tree starting at AST node x to w. If fset != nil, position information is interpreted relative to that file set. Otherwise positions are printed as integer values (file set specific offsets). A non-nil FieldFilter f may be provided to control the output: struct fields for which f(fieldname, fieldvalue) is true are printed; all others are filtered from the output. Unexported struct fields are never printed.
const Fun ObjKind = 5 // function or method The list of possible Object kinds.
func Inspect(node Node, f func(Node) bool) Inspect traverses an AST in depth-first order: It starts by calling f(node); node must not be nil. If f returns true, Inspect invokes f recursively for each of the non-nil children of node, followed by a call of f(nil).
func IsExported(name string) bool IsExported reports whether name starts with an upper-case letter.
const Lbl ObjKind = 6 // label The list of possible Object kinds.
func MergePackageFiles(pkg *Package, mode MergeMode) *File MergePackageFiles creates a file AST by merging the ASTs of the files belonging to a package. The mode flags control merging behavior.
func NewCommentMap(fset *token.FileSet, node Node, comments []*CommentGroup) CommentMap NewCommentMap creates a new comment map by associating comment groups of the comments list with the nodes of the AST specified by node. A comment group g is associated with a node n if: - g starts on the same line as n ends - g starts on the line immediately following n, and there is at least one empty line after g and before the next node - g starts before n and is not associated to the node before n via the previous rules NewCommentMap tries to associate a comment group to the "largest" node possible: For instance, if the comment is a line comment trailing an assignment, the comment is associated with the entire assignment rather than just the last operand in the assignment.
func NewIdent(name string) *Ident NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the Go parser.
func NewObj(kind ObjKind, name string) *Object NewObj creates a new object of a given kind and name.
func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer, universe *Scope) (*Package, error) NewPackage creates a new Package node from a set of File nodes. It resolves unresolved identifiers across files and updates each file's Unresolved list accordingly. If a non-nil importer and universe scope are provided, they are used to resolve identifiers not declared in any of the package files. Any remaining unresolved identifiers are reported as undeclared. If the files belong to different packages, one package name is selected and files with different package names are reported and then ignored. The result is a package node and a scanner.ErrorList if there were errors.
func NewScope(outer *Scope) *Scope NewScope creates a new scope nested in the outer scope.
func NotNilFilter(_ string, v reflect.Value) bool NotNilFilter returns true for field values that are not nil; it returns false otherwise.
func PackageExports(pkg *Package) bool PackageExports trims the AST for a Go package in place such that only exported nodes remain. The pkg.Files list is not changed, so that file names and top-level package comments don't get lost. PackageExports reports whether there are exported declarations; it returns false otherwise.
const Pkg ObjKind = 1 // package The list of possible Object kinds.
func Print(fset *token.FileSet, x interface{}) error Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).
const RECV ChanDir = 2
const SEND ChanDir = 1
func SortImports(fset *token.FileSet, f *File) SortImports sorts runs of consecutive import lines in import blocks in f. It also removes duplicate imports when it is possible to do so without data loss.
const Typ ObjKind = 3 // type The list of possible Object kinds.
const Var ObjKind = 4 // variable The list of possible Object kinds.
func Walk(v Visitor, node Node) Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).