Documentation ¶
Index ¶
- Constants
- func Apply(root dst.Node, pre, post ApplyFunc) (result dst.Node)
- func NewAssignStmt(lhs, rhs []dst.Expr) *dst.AssignStmt
- func NewBasicLit(kind token.Token, value string) *dst.BasicLit
- func NewBlockStmt(expStmt ...*dst.ExprStmt) *dst.BlockStmt
- func NewCallExpr(f dst.Expr, args []dst.Expr) *dst.CallExpr
- func NewCompositeLit(typ dst.Expr, elts []dst.Expr) *dst.CompositeLit
- func NewDeclStmt(decl dst.Decl) *dst.DeclStmt
- func NewEmptyStmt(pos token.Pos) *dst.EmptyStmt
- func NewExpStmt(x dst.Expr) *dst.ExprStmt
- func NewField(fieldNames []string, typeVal dst.Expr, typeName ExprType, tag *dst.BasicLit) *dst.Field
- func NewFieldList(fields ...*dst.Field) *dst.FieldList
- func NewFieldOfFuncType(fieldNames []string, functype *dst.FuncType, tag *dst.BasicLit) *dst.Field
- func NewFuncDecl(funcName string, blkStmt *dst.BlockStmt, recv, params *dst.FieldList) *dst.FuncDecl
- func NewFuncType(params, results *dst.FieldList) *dst.FuncType
- func NewGenDecl(tok token.Token, specs ...dst.Spec) *dst.GenDecl
- func NewIdent(name string) *dst.Ident
- func NewImportSpec(name string, path string) *dst.ImportSpec
- func NewInterface(fieldList *dst.FieldList) *dst.InterfaceType
- func NewKeyValueExp(key, val dst.Expr) *dst.KeyValueExpr
- func NewReturnStmt(results []dst.Expr) *dst.ReturnStmt
- func NewSelectExp(x dst.Expr, sel *dst.Ident) *dst.SelectorExpr
- func NewShortAssignStmt(lhs, rhs []dst.Expr) *dst.AssignStmt
- func NewStarExp(exp dst.Expr) *dst.StarExpr
- func NewValSpec(name, typ string) *dst.ValueSpec
- func NewValueSpec(ident string, expr dst.Expr) *dst.ValueSpec
- func NewVarDecl(name, typ string) *dst.GenDecl
- func Unparen(e dst.Expr) dst.Expr
- type ApplyFunc
- type Cursor
- func (c *Cursor) Delete()
- func (c *Cursor) Index() int
- func (c *Cursor) InsertAfter(n dst.Node)
- func (c *Cursor) InsertBefore(n dst.Node)
- func (c *Cursor) Name() string
- func (c *Cursor) Node() dst.Node
- func (c *Cursor) Parent() dst.Node
- func (c *Cursor) Replace(n dst.Node)
- func (c *Cursor) Similarity(n dst.Node) (int, int)
- type DecorationPoint
- type ExprType
Constants ¶
const ( ExprTypeIdent ExprType = "Ident" ExprTypeStartExpr = "StartExpr" ExprTypeSelectorExpr = "SelectorExpr" )
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply traverses a syntax tree recursively, starting with root, and calling pre and post for each node as described below. Apply returns the syntax tree, possibly modified.
If pre is not nil, it is called for each node before the node's children are traversed (pre-order). If pre returns false, no children are traversed, and post is not called for that node.
If post is not nil, and a prior call of pre didn't return false, post is called for each node after its children are traversed (post-order). If post returns false, traversal is terminated and Apply returns immediately.
Only fields that refer to AST nodes are considered children; i.e., token.Pos, Scopes, Objects, and fields of basic types (strings, etc.) are ignored.
Children are traversed in the order in which they appear in the respective node's struct definition. A package's files are traversed in the filenames' alphabetical order.
func NewAssignStmt ¶ added in v0.27.1
func NewAssignStmt(lhs, rhs []dst.Expr) *dst.AssignStmt
func NewBasicLit ¶ added in v0.27.1
new basicLit
func NewCompositeLit ¶ added in v0.27.1
new compositeLit
func NewField ¶ added in v0.27.1
func NewField(fieldNames []string, typeVal dst.Expr, typeName ExprType, tag *dst.BasicLit) *dst.Field
example ====>
type svc interface { UserGet(ctx context.Context, reqproto *partnerproto.StaffAuthFetchReqProto)(*partnerproto.StaffAuthFetchRespProto, error) }
====> typeVals: context.Context typeName: StartExpr fieldNames: ctx tag: nil
func NewFieldOfFuncType ¶ added in v0.27.1
func NewFuncDecl ¶ added in v0.27.1
func NewFuncDecl(funcName string, blkStmt *dst.BlockStmt, recv, params *dst.FieldList) *dst.FuncDecl
new funcDecl
func NewFuncType ¶ added in v0.27.1
type svc interface { UserGet() }
func NewGenDecl ¶ added in v0.27.1
new GenDecl
func NewImportSpec ¶ added in v0.27.1
func NewImportSpec(name string, path string) *dst.ImportSpec
new import spec
func NewInterface ¶ added in v0.27.1
func NewInterface(fieldList *dst.FieldList) *dst.InterfaceType
func NewKeyValueExp ¶ added in v0.27.1
func NewKeyValueExp(key, val dst.Expr) *dst.KeyValueExpr
func NewReturnStmt ¶ added in v0.27.1
func NewReturnStmt(results []dst.Expr) *dst.ReturnStmt
func NewSelectExp ¶ added in v0.27.1
func NewShortAssignStmt ¶ added in v0.27.1
func NewShortAssignStmt(lhs, rhs []dst.Expr) *dst.AssignStmt
func NewValSpec ¶ added in v0.27.2
func NewValueSpec ¶ added in v0.27.1
new valueSpec
func NewVarDecl ¶ added in v0.27.2
Types ¶
type ApplyFunc ¶
An ApplyFunc is invoked by Apply for each node n, even if n is nil, before and/or after the node's children, using a Cursor describing the current node and providing operations on it.
The return value of ApplyFunc controls the syntax tree traversal. See Apply for details.
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
A Cursor describes a node encountered during Apply. Information about the node and its parent is available from the Node, Parent, Name, and Index methods.
If p is a variable of type and value of the current parent node c.Parent(), and f is the field identifier with name c.Name(), the following invariants hold:
p.f == c.Node() if c.Index() < 0 p.f[c.Index()] == c.Node() if c.Index() >= 0
The methods Replace, Delete, InsertBefore, and InsertAfter can be used to change the AST without disrupting Apply.
func (*Cursor) Delete ¶
func (c *Cursor) Delete()
Delete deletes the current Node from its containing slice. If the current Node is not part of a slice, Delete panics. As a special case, if the current node is a package file, Delete removes it from the package's Files map.
func (*Cursor) Index ¶
Index reports the index >= 0 of the current Node in the slice of Nodes that contains it, or a value < 0 if the current Node is not part of a slice. The index of the current node changes if InsertBefore is called while processing the current node.
func (*Cursor) InsertAfter ¶
InsertAfter inserts n after the current Node in its containing slice. If the current Node is not part of a slice, InsertAfter panics. Apply does not walk n.
func (*Cursor) InsertBefore ¶
InsertBefore inserts n before the current Node in its containing slice. If the current Node is not part of a slice, InsertBefore panics. Apply will not walk n.
func (*Cursor) Name ¶
Name returns the name of the parent Node field that contains the current Node. If the parent is a *dst.Package and the current Node is a *dst.File, Name returns the filename for the current Node.
type DecorationPoint ¶ added in v0.26.3
DecorationPoint contains the name of the decoration attachment point and a list of decorations attached there
func Decorations ¶ added in v0.26.3
func Decorations(n dst.Node) (before, after dst.SpaceType, info []DecorationPoint)
Decorations returns information about all the decoration attachment points associated with a node