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. Elt Expr Lbrack token.Pos Len Expr (*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 Tok token.Token TokPos token.Pos (*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. From token.Pos To token.Pos (*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. From token.Pos To token.Pos (*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. From token.Pos To token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type BasicLit (struct) A BasicLit node represents a literal of basic type. Kind token.Token Value string ValuePos token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type BinaryExpr (struct) A BinaryExpr node represents a binary expression. Op token.Token OpPos token.Pos X Expr Y Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type BlockStmt (struct) A BlockStmt node represents a braced statement list. Lbrace token.Pos List []Stmt Rbrace token.Pos (*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 *Ident Tok token.Token TokPos token.Pos (*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. Args []Expr Ellipsis token.Pos Fun Expr Lparen token.Pos Rparen token.Pos (*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. Body []Stmt Case token.Pos Colon token.Pos List []Expr (*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. Arrow token.Pos Begin token.Pos Dir ChanDir Value Expr (*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. Body []Stmt Case token.Pos Colon token.Pos Comm Stmt (*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. Slash token.Pos Text string (*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. List []*Comment (*T) End() token.Pos (*T) Pos() token.Pos (*T) Text() string *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. (T) Comments() []*CommentGroup (T) Filter(node Node) CommentMap (T) String() string (T) Update(old, new Node) 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. Elts []Expr Incomplete bool Lbrace token.Pos Rbrace token.Pos Type Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type Decl (interface) All declaration nodes implement the Decl interface. (T) End() token.Pos (T) Pos() token.Pos *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. Decl Decl (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type DeferStmt (struct) A DeferStmt node represents a defer statement. Call *CallExpr Defer token.Pos (*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. Ellipsis token.Pos Elt Expr (*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. Implicit bool Semicolon token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Expr (interface) All expression nodes implement the Expr interface. (T) End() token.Pos (T) Pos() token.Pos *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. X Expr (*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. Comment *CommentGroup Doc *CommentGroup Names []*Ident Tag *BasicLit Type Expr (*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. Closing token.Pos List []*Field Opening token.Pos (*T) End() token.Pos (*T) NumFields() int (*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). Comments []*CommentGroup Decls []Decl Doc *CommentGroup Imports []*ImportSpec Name *Ident Package token.Pos Scope *Scope Unresolved []*Ident (*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 Cond Expr For token.Pos Init Stmt Post Stmt (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type FuncDecl (struct) A FuncDecl node represents a function declaration. Body *BlockStmt Doc *CommentGroup Name *Ident Recv *FieldList Type *FuncType (*T) End() token.Pos (*T) Pos() token.Pos *T : Decl *T : Node
type FuncLit (struct) A FuncLit node represents a function literal. Body *BlockStmt Type *FuncType (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type FuncType (struct) A FuncType node represents a function type. Func token.Pos Params *FieldList Results *FieldList (*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 Doc *CommentGroup Lparen token.Pos Rparen token.Pos Specs []Spec Tok token.Token TokPos token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Decl *T : Node
type GoStmt (struct) A GoStmt node represents a go statement. Call *CallExpr Go token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type Ident (struct) An Ident node represents an identifier. Name string NamePos token.Pos Obj *Object (*T) End() token.Pos (*T) IsExported() bool (*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 Cond Expr Else Stmt If token.Pos Init Stmt (*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. Comment *CommentGroup Doc *CommentGroup EndPos token.Pos Name *Ident Path *BasicLit (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Spec
type IncDecStmt (struct) An IncDecStmt node represents an increment or decrement statement. Tok token.Token TokPos token.Pos 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 Expr Lbrack token.Pos Rbrack token.Pos X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type InterfaceType (struct) An InterfaceType node represents an interface type. Incomplete bool Interface token.Pos Methods *FieldList (*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. Colon token.Pos 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. Colon token.Pos 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 Map token.Pos 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. (T) End() token.Pos (T) Pos() token.Pos *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 Data interface{} Decl interface{} Kind ObjKind Name string Type interface{} (*T) Pos() token.Pos 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. Files map[string]*File Imports map[string]*Object Name string Scope *Scope (*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. Lparen token.Pos Rparen token.Pos X Expr (*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 For token.Pos Key Expr Tok token.Token TokPos token.Pos Value Expr X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type ReturnStmt (struct) A ReturnStmt node represents a return statement. Results []Expr Return token.Pos (*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 (*T) Insert(obj *Object) (alt *Object) (*T) Lookup(name string) *Object (*T) String() string *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. Sel *Ident X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type SelectStmt (struct) A SelectStmt node represents a select statement. Body *BlockStmt Select token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Stmt
type SendStmt (struct) A SendStmt node represents a send statement. Arrow token.Pos 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. High Expr Lbrack token.Pos Low Expr Max Expr Rbrack token.Pos Slice3 bool X Expr (*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. (T) End() token.Pos (T) Pos() token.Pos *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. Star token.Pos X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type Stmt (interface) All statement nodes implement the Stmt interface. (T) End() token.Pos (T) Pos() token.Pos *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. Fields *FieldList Incomplete bool Struct token.Pos (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type SwitchStmt (struct) A SwitchStmt node represents an expression switch statement. Body *BlockStmt Init Stmt Switch token.Pos Tag Expr (*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. Lparen token.Pos Rparen token.Pos Type Expr X Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Expr *T : Node
type TypeSpec (struct) A TypeSpec node represents a type declaration (TypeSpec production). Assign token.Pos Comment *CommentGroup Doc *CommentGroup Name *Ident Type Expr (*T) End() token.Pos (*T) Pos() token.Pos *T : Node *T : Spec
type TypeSwitchStmt (struct) A TypeSwitchStmt node represents a type switch statement. Assign Stmt Body *BlockStmt Init Stmt Switch token.Pos (*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. Op token.Token OpPos token.Pos X Expr (*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). Comment *CommentGroup Doc *CommentGroup Names []*Ident Type Expr Values []Expr (*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).