dst: github.com/dave/dst Index | Examples | Files | Directories

package dst

import "github.com/dave/dst"

Package dst declares the types used to represent decorated syntax trees for Go packages.

Index

Examples

Package Files

clone-generated.go clone.go decorations-node-generated.go decorations-types-generated.go decorations.go dst.go print.go readme.go resolve.go scope.go walk.go

func Fprint Uses

func Fprint(w io.Writer, 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.

func Inspect Uses

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).

This example demonstrates how to inspect the AST of a Go program.

Code:

// src is the input for which we want to inspect the AST.
src := `
package p
const c = 1.0
var X = f(3.14)*2 + c
`

// Create the AST by parsing src.
fset := token.NewFileSet() // positions are relative to fset
f, err := decorator.ParseFile(fset, "src.go", src, 0)
if err != nil {
    panic(err)
}

// Inspect the AST and print all identifiers and literals.
dst.Inspect(f, func(n dst.Node) bool {
    var s string
    switch x := n.(type) {
    case *dst.BasicLit:
        s = x.Value
    case *dst.Ident:
        s = x.Name
    }
    if s != "" {
        fmt.Println(s)
    }
    return true
})

Output:

p
c
1.0
X
f
3.14
2
c

func IsExported Uses

func IsExported(name string) bool

IsExported reports whether name is an exported Go symbol (that is, whether it begins with an upper-case letter).

func NotNilFilter Uses

func NotNilFilter(_ string, v reflect.Value) bool

NotNilFilter returns true for field values that are not nil; it returns false otherwise.

func Print Uses

func Print(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).

func Walk Uses

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).

type ArrayType Uses

type ArrayType struct {
    Len  Expr // Ellipsis node for [...]T array types, nil for slice types
    Elt  Expr // element type
    Decs ArrayTypeDecorations
}

An ArrayType node represents an array or slice type.

func (*ArrayType) Decorations Uses

func (n *ArrayType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ArrayTypeDecorations Uses

type ArrayTypeDecorations struct {
    NodeDecs
    Lbrack Decorations
    Len    Decorations
}

ArrayTypeDecorations holds decorations for ArrayType:

type R /*Start*/ [ /*Lbrack*/ 1] /*Len*/ int /*End*/

type AssignStmt Uses

type AssignStmt struct {
    Lhs  []Expr
    Tok  token.Token // assignment token, DEFINE
    Rhs  []Expr
    Decs AssignStmtDecorations
}

An AssignStmt node represents an assignment or a short variable declaration.

func (*AssignStmt) Decorations Uses

func (n *AssignStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type AssignStmtDecorations Uses

type AssignStmtDecorations struct {
    NodeDecs
    Tok Decorations
}

AssignStmtDecorations holds decorations for AssignStmt:

/*Start*/
i = /*Tok*/ 1 /*End*/

type BadDecl Uses

type BadDecl struct {
    Length int // position range of bad declaration
    Decs   BadDeclDecorations
}

A BadDecl node is a placeholder for declarations containing syntax errors for which no correct declaration nodes can be created.

func (*BadDecl) Decorations Uses

func (n *BadDecl) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BadDeclDecorations Uses

type BadDeclDecorations struct {
    NodeDecs
}

BadDeclDecorations holds decorations for BadDecl:

type BadExpr Uses

type BadExpr struct {
    Length int // position range of bad expression
    Decs   BadExprDecorations
}

A BadExpr node is a placeholder for expressions containing syntax errors for which no correct expression nodes can be created.

func (*BadExpr) Decorations Uses

func (n *BadExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BadExprDecorations Uses

type BadExprDecorations struct {
    NodeDecs
}

BadExprDecorations holds decorations for BadExpr:

type BadStmt Uses

type BadStmt struct {
    Length int // position range of bad statement
    Decs   BadStmtDecorations
}

A BadStmt node is a placeholder for statements containing syntax errors for which no correct statement nodes can be created.

func (*BadStmt) Decorations Uses

func (n *BadStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BadStmtDecorations Uses

type BadStmtDecorations struct {
    NodeDecs
}

BadStmtDecorations holds decorations for BadStmt:

type BasicLit Uses

type BasicLit struct {
    Kind  token.Token // token.INT, token.FLOAT, token.IMAG, token.CHAR, or token.STRING
    Value string      // literal string; e.g. 42, 0x7f, 3.14, 1e-9, 2.4i, 'a', '\x7f', "foo" or `\m\n\o`
    Decs  BasicLitDecorations
}

A BasicLit node represents a literal of basic type.

func (*BasicLit) Decorations Uses

func (n *BasicLit) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BasicLitDecorations Uses

type BasicLitDecorations struct {
    NodeDecs
}

BasicLitDecorations holds decorations for BasicLit:

type BinaryExpr Uses

type BinaryExpr struct {
    X    Expr        // left operand
    Op   token.Token // operator
    Y    Expr        // right operand
    Decs BinaryExprDecorations
}

A BinaryExpr node represents a binary expression.

func (*BinaryExpr) Decorations Uses

func (n *BinaryExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BinaryExprDecorations Uses

type BinaryExprDecorations struct {
    NodeDecs
    X   Decorations
    Op  Decorations
}

BinaryExprDecorations holds decorations for BinaryExpr:

var P = /*Start*/ 1 /*X*/ & /*Op*/ 2 /*End*/

type BlockStmt Uses

type BlockStmt struct {
    List           []Stmt
    RbraceHasNoPos bool // Sometimes (after a BadExpr?) the rbrace has a zero position, and this causes the brace to render in a different position. We duplicate this in the output for compatibility.
    Decs           BlockStmtDecorations
}

A BlockStmt node represents a braced statement list.

func (*BlockStmt) Decorations Uses

func (n *BlockStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BlockStmtDecorations Uses

type BlockStmtDecorations struct {
    NodeDecs
    Lbrace Decorations
}

BlockStmtDecorations holds decorations for BlockStmt:

if true /*Start*/ { /*Lbrace*/
	i++
} /*End*/

func() /*Start*/ { /*Lbrace*/ i++ } /*End*/ ()

type BranchStmt Uses

type BranchStmt struct {
    Tok   token.Token // keyword token (BREAK, CONTINUE, GOTO, FALLTHROUGH)
    Label *Ident      // label name; or nil
    Decs  BranchStmtDecorations
}

A BranchStmt node represents a break, continue, goto, or fallthrough statement.

func (*BranchStmt) Decorations Uses

func (n *BranchStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type BranchStmtDecorations Uses

type BranchStmtDecorations struct {
    NodeDecs
    Tok Decorations
}

BranchStmtDecorations holds decorations for BranchStmt:

/*Start*/
goto /*Tok*/ A /*End*/

type CallExpr Uses

type CallExpr struct {
    Fun      Expr   // function expression
    Args     []Expr // function arguments; or nil
    Ellipsis bool
    Decs     CallExprDecorations
}

A CallExpr node represents an expression followed by an argument list.

func (*CallExpr) Decorations Uses

func (n *CallExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type CallExprDecorations Uses

type CallExprDecorations struct {
    NodeDecs
    Fun      Decorations
    Lparen   Decorations
    Ellipsis Decorations
}

CallExprDecorations holds decorations for CallExpr:

var L = /*Start*/ C /*Fun*/ ( /*Lparen*/ 0, []int{}... /*Ellipsis*/) /*End*/

type CaseClause Uses

type CaseClause struct {
    List []Expr // list of expressions or types; nil means default case
    Body []Stmt // statement list; or nil
    Decs CaseClauseDecorations
}

A CaseClause represents a case of an expression or type switch statement.

func (*CaseClause) Decorations Uses

func (n *CaseClause) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type CaseClauseDecorations Uses

type CaseClauseDecorations struct {
    NodeDecs
    Case  Decorations
    Colon Decorations
}

CaseClauseDecorations holds decorations for CaseClause:

switch i {
/*Start*/ case /*Case*/ 1: /*Colon*/
	i++ /*End*/
}

type ChanDir Uses

type ChanDir int

The direction of a channel type is indicated by a bit mask including one or both of the following constants.

const (
    SEND ChanDir = 1 << iota
    RECV
)

type ChanType Uses

type ChanType struct {
    Dir   ChanDir // channel direction
    Value Expr    // value type
    Decs  ChanTypeDecorations
}

A ChanType node represents a channel type.

func (*ChanType) Decorations Uses

func (n *ChanType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ChanTypeDecorations Uses

type ChanTypeDecorations struct {
    NodeDecs
    Begin Decorations
    Arrow Decorations
}

ChanTypeDecorations holds decorations for ChanType:

type W /*Start*/ chan /*Begin*/ int /*End*/

type X /*Start*/ <-chan /*Begin*/ int /*End*/

type Y /*Start*/ chan /*Begin*/ <- /*Arrow*/ int /*End*/

type CommClause Uses

type CommClause struct {
    Comm Stmt   // send or receive statement; nil means default case
    Body []Stmt // statement list; or nil
    Decs CommClauseDecorations
}

A CommClause node represents a case of a select statement.

func (*CommClause) Decorations Uses

func (n *CommClause) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type CommClauseDecorations Uses

type CommClauseDecorations struct {
    NodeDecs
    Case  Decorations
    Comm  Decorations
    Colon Decorations
}

CommClauseDecorations holds decorations for CommClause:

select {
/*Start*/ case /*Case*/ a := <-c /*Comm*/ : /*Colon*/
	print(a) /*End*/
}

type CompositeLit Uses

type CompositeLit struct {
    Type       Expr   // literal type; or nil
    Elts       []Expr // list of composite elements; or nil
    Incomplete bool   // true if (source) expressions are missing in the Elts list
    Decs       CompositeLitDecorations
}

A CompositeLit node represents a composite literal.

func (*CompositeLit) Decorations Uses

func (n *CompositeLit) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type CompositeLitDecorations Uses

type CompositeLitDecorations struct {
    NodeDecs
    Type   Decorations
    Lbrace Decorations
}

CompositeLitDecorations holds decorations for CompositeLit:

var D = /*Start*/ A /*Type*/ { /*Lbrace*/ A: 0} /*End*/

type Decl Uses

type Decl interface {
    Node
    // contains filtered or unexported methods
}

All declaration nodes implement the Decl interface.

type DeclStmt Uses

type DeclStmt struct {
    Decl Decl // *GenDecl with CONST, TYPE, or VAR token
    Decs DeclStmtDecorations
}

A DeclStmt node represents a declaration in a statement list.

func (*DeclStmt) Decorations Uses

func (n *DeclStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type DeclStmtDecorations Uses

type DeclStmtDecorations struct {
    NodeDecs
}

DeclStmtDecorations holds decorations for DeclStmt:

type Decorations Uses

type Decorations []string

Decorations is a slice of strings which are rendered with the node. Decorations can be comments (starting "//" or "/*") or newlines ("\n").

Code:

code := `package main

	func main() {
		var a int
		a++
		print(a)
	}`
f, err := decorator.Parse(code)
if err != nil {
    panic(err)
}

body := f.Decls[0].(*dst.FuncDecl).Body
for i, stmt := range body.List {
    stmt.Decorations().Before = dst.EmptyLine
    stmt.Decorations().Start.Append(fmt.Sprintf("// foo %d", i))
}

call := body.List[2].(*dst.ExprStmt).X.(*dst.CallExpr)
call.Args = append(call.Args, dst.NewIdent("b"), dst.NewIdent("c"))
for i, expr := range call.Args {
    expr.Decorations().Before = dst.NewLine
    expr.Decorations().After = dst.NewLine
    expr.Decorations().Start.Append(fmt.Sprintf("/* bar %d */", i))
    expr.Decorations().End.Append(fmt.Sprintf("// baz %d", i))
}

if err := decorator.Print(f); err != nil {
    panic(err)
}

Output:

package main

func main() {

	// foo 0
	var a int

	// foo 1
	a++

	// foo 2
	print(
		/* bar 0 */ a, // baz 0
		/* bar 1 */ b, // baz 1
		/* bar 2 */ c, // baz 2
	)
}

func (*Decorations) All Uses

func (d *Decorations) All() []string

All returns the decorations as a string slice

func (*Decorations) Append Uses

func (d *Decorations) Append(decs ...string)

Append adds one or more decorations to the end of the list.

func (*Decorations) Clear Uses

func (d *Decorations) Clear()

Clear removes all decorations from this item

func (*Decorations) Prepend Uses

func (d *Decorations) Prepend(decs ...string)

Prepend adds one or more decorations to the start of the list.

func (*Decorations) Replace Uses

func (d *Decorations) Replace(decs ...string)

Replace replaces all decorations with decs.

type DeferStmt Uses

type DeferStmt struct {
    Call *CallExpr
    Decs DeferStmtDecorations
}

A DeferStmt node represents a defer statement.

func (*DeferStmt) Decorations Uses

func (n *DeferStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type DeferStmtDecorations Uses

type DeferStmtDecorations struct {
    NodeDecs
    Defer Decorations
}

DeferStmtDecorations holds decorations for DeferStmt:

/*Start*/
defer /*Defer*/ func() {}() /*End*/

type Ellipsis Uses

type Ellipsis struct {
    Elt  Expr // ellipsis element type (parameter lists only); or nil
    Decs EllipsisDecorations
}

An Ellipsis node stands for the "..." type in a parameter list or the "..." length in an array type.

func (*Ellipsis) Decorations Uses

func (n *Ellipsis) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type EllipsisDecorations Uses

type EllipsisDecorations struct {
    NodeDecs
    Ellipsis Decorations
}

EllipsisDecorations holds decorations for Ellipsis:

func B(a /*Start*/ ... /*Ellipsis*/ int /*End*/) {}

type EmptyStmt Uses

type EmptyStmt struct {
    Implicit bool // if set, ";" was omitted in the source
    Decs     EmptyStmtDecorations
}

An EmptyStmt node represents an empty statement. The "position" of the empty statement is the position of the immediately following (explicit or implicit) semicolon.

func (*EmptyStmt) Decorations Uses

func (n *EmptyStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type EmptyStmtDecorations Uses

type EmptyStmtDecorations struct {
    NodeDecs
}

EmptyStmtDecorations holds decorations for EmptyStmt:

type Expr Uses

type Expr interface {
    Node
    // contains filtered or unexported methods
}

All expression nodes implement the Expr interface.

type ExprStmt Uses

type ExprStmt struct {
    X    Expr // expression
    Decs ExprStmtDecorations
}

An ExprStmt node represents a (stand-alone) expression in a statement list.

func (*ExprStmt) Decorations Uses

func (n *ExprStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ExprStmtDecorations Uses

type ExprStmtDecorations struct {
    NodeDecs
}

ExprStmtDecorations holds decorations for ExprStmt:

type Field Uses

type Field struct {
    Names []*Ident  // field/method/parameter names; or nil
    Type  Expr      // field/method/parameter type
    Tag   *BasicLit // field tag; or nil
    Decs  FieldDecorations
}

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.

func (*Field) Decorations Uses

func (n *Field) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type FieldDecorations Uses

type FieldDecorations struct {
    NodeDecs
    Type Decorations
}

FieldDecorations holds decorations for Field:

type A struct {
	/*Start*/ A int /*Type*/ `a:"a"` /*End*/
}

type FieldFilter Uses

type FieldFilter func(name string, value reflect.Value) bool

A FieldFilter may be provided to Fprint to control the output.

type FieldList Uses

type FieldList struct {
    Opening bool
    List    []*Field // field list; or nil
    Closing bool
    Decs    FieldListDecorations
}

A FieldList represents a list of Fields, enclosed by parentheses or braces.

func (*FieldList) Decorations Uses

func (n *FieldList) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

func (*FieldList) NumFields Uses

func (f *FieldList) NumFields() int

NumFields returns the number of parameters or struct fields represented by a FieldList.

type FieldListDecorations Uses

type FieldListDecorations struct {
    NodeDecs
    Opening Decorations
}

FieldListDecorations holds decorations for FieldList:

type A1 struct /*Start*/ { /*Opening*/
	a, b int
	c    string
} /*End*/

type File Uses

type File struct {
    Name       *Ident        // package name
    Decls      []Decl        // top-level declarations; or nil
    Scope      *Scope        // package scope (this file only)
    Imports    []*ImportSpec // imports in this file
    Unresolved []*Ident      // unresolved identifiers in this file
    Decs       FileDecorations
}

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).

func (*File) Decorations Uses

func (n *File) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type FileDecorations Uses

type FileDecorations struct {
    NodeDecs
    Package Decorations
    Name    Decorations
}

FileDecorations holds decorations for File:

/*Start*/ package /*Package*/ data /*Name*/

type ForStmt Uses

type ForStmt struct {
    Init Stmt // initialization statement; or nil
    Cond Expr // condition; or nil
    Post Stmt // post iteration statement; or nil
    Body *BlockStmt
    Decs ForStmtDecorations
}

A ForStmt represents a for statement.

func (*ForStmt) Decorations Uses

func (n *ForStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ForStmtDecorations Uses

type ForStmtDecorations struct {
    NodeDecs
    For  Decorations
    Init Decorations
    Cond Decorations
    Post Decorations
}

ForStmtDecorations holds decorations for ForStmt:

/*Start*/
for /*For*/ {
	i++
} /*End*/

/*Start*/
for /*For*/ i < 1 /*Cond*/ {
	i++
} /*End*/

/*Start*/
for /*For*/ i = 0; /*Init*/ i < 10; /*Cond*/ i++ /*Post*/ {
	i++
} /*End*/

type FuncDecl Uses

type FuncDecl struct {
    Recv *FieldList // receiver (methods); or nil (functions)
    Name *Ident     // function/method name
    Type *FuncType  // function signature: parameters, results, and position of "func" keyword
    Body *BlockStmt // function body; or nil for external (non-Go) function
    Decs FuncDeclDecorations
}

A FuncDecl node represents a function declaration.

func (*FuncDecl) Decorations Uses

func (n *FuncDecl) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type FuncDeclDecorations Uses

type FuncDeclDecorations struct {
    NodeDecs
    Func    Decorations
    Recv    Decorations
    Name    Decorations
    Params  Decorations
    Results Decorations
}

FuncDeclDecorations holds decorations for FuncDecl:

/*Start*/
func /*Func*/ d /*Name*/ (d, e int) /*Params*/ {
	return
} /*End*/

/*Start*/
func /*Func*/ (a *A) /*Recv*/ e /*Name*/ (d, e int) /*Params*/ {
	return
} /*End*/

/*Start*/
func /*Func*/ (a *A) /*Recv*/ f /*Name*/ (d, e int) /*Params*/ (f, g int) /*Results*/ {
	return
} /*End*/

type FuncLit Uses

type FuncLit struct {
    Type *FuncType  // function type
    Body *BlockStmt // function body
    Decs FuncLitDecorations
}

A FuncLit node represents a function literal.

func (*FuncLit) Decorations Uses

func (n *FuncLit) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type FuncLitDecorations Uses

type FuncLitDecorations struct {
    NodeDecs
    Type Decorations
}

FuncLitDecorations holds decorations for FuncLit:

var C = /*Start*/ func(a int, b ...int) (c int) /*Type*/ { return 0 } /*End*/

type FuncType Uses

type FuncType struct {
    Func    bool
    Params  *FieldList // (incoming) parameters; non-nil
    Results *FieldList // (outgoing) results; or nil
    Decs    FuncTypeDecorations
}

A FuncType node represents a function type.

func (*FuncType) Decorations Uses

func (n *FuncType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type FuncTypeDecorations Uses

type FuncTypeDecorations struct {
    NodeDecs
    Func   Decorations
    Params Decorations
}

FuncTypeDecorations holds decorations for FuncType:

type T /*Start*/ func /*Func*/ (a int) /*Params*/ (b int) /*End*/

type GenDecl Uses

type GenDecl struct {
    Tok    token.Token // IMPORT, CONST, TYPE, VAR
    Lparen bool
    Specs  []Spec
    Rparen bool
    Decs   GenDeclDecorations
}

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

func (*GenDecl) Decorations Uses

func (n *GenDecl) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type GenDeclDecorations Uses

type GenDeclDecorations struct {
    NodeDecs
    Tok    Decorations
    Lparen Decorations
}

GenDeclDecorations holds decorations for GenDecl:

/*Start*/
const /*Tok*/ ( /*Lparen*/
	a, b = 1, 2
	c    = 3
) /*End*/

/*Start*/
const /*Tok*/ d = 1 /*End*/

type GoStmt Uses

type GoStmt struct {
    Call *CallExpr
    Decs GoStmtDecorations
}

A GoStmt node represents a go statement.

func (*GoStmt) Decorations Uses

func (n *GoStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type GoStmtDecorations Uses

type GoStmtDecorations struct {
    NodeDecs
    Go  Decorations
}

GoStmtDecorations holds decorations for GoStmt:

/*Start*/
go /*Go*/ func() {}() /*End*/

type Ident Uses

type Ident struct {
    Name string  // identifier name
    Obj  *Object // denoted object; or nil
    Path string  // path of the imported package, if this identifier is not local
    Decs IdentDecorations
}

An Ident node represents an identifier.

func NewIdent Uses

func NewIdent(name string) *Ident

NewIdent creates a new Ident without position. Useful for ASTs generated by code other than the Go parser.

func (*Ident) Decorations Uses

func (n *Ident) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

func (*Ident) IsExported Uses

func (id *Ident) IsExported() bool

IsExported reports whether id is an exported Go symbol (that is, whether it begins with an uppercase letter).

func (*Ident) String Uses

func (id *Ident) String() string

type IdentDecorations Uses

type IdentDecorations struct {
    NodeDecs
    X   Decorations
}

IdentDecorations holds decorations for Ident:

/*Start*/
i /*End*/ ++

/*Start*/
fmt. /*X*/ Print /*End*/ ()

type IfStmt Uses

type IfStmt struct {
    Init Stmt // initialization statement; or nil
    Cond Expr // condition
    Body *BlockStmt
    Else Stmt // else branch; or nil
    Decs IfStmtDecorations
}

An IfStmt node represents an if statement.

func (*IfStmt) Decorations Uses

func (n *IfStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type IfStmtDecorations Uses

type IfStmtDecorations struct {
    NodeDecs
    If   Decorations
    Init Decorations
    Cond Decorations
    Else Decorations
}

IfStmtDecorations holds decorations for IfStmt:

/*Start*/
if /*If*/ a := b; /*Init*/ a /*Cond*/ {
	i++
} else /*Else*/ {
	i++
} /*End*/

type ImportSpec Uses

type ImportSpec struct {
    Name *Ident    // local package name (including "."); or nil
    Path *BasicLit // import path
    Decs ImportSpecDecorations
}

An ImportSpec node represents a single package import.

func (*ImportSpec) Decorations Uses

func (n *ImportSpec) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ImportSpecDecorations Uses

type ImportSpecDecorations struct {
    NodeDecs
    Name Decorations
}

ImportSpecDecorations holds decorations for ImportSpec:

import (
	/*Start*/ fmt /*Name*/ "fmt" /*End*/
)

type Importer Uses

type Importer func(imports map[string]*Object, path string) (pkg *Object, err error)

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.

type IncDecStmt Uses

type IncDecStmt struct {
    X    Expr
    Tok  token.Token // INC or DEC
    Decs IncDecStmtDecorations
}

An IncDecStmt node represents an increment or decrement statement.

func (*IncDecStmt) Decorations Uses

func (n *IncDecStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type IncDecStmtDecorations Uses

type IncDecStmtDecorations struct {
    NodeDecs
    X   Decorations
}

IncDecStmtDecorations holds decorations for IncDecStmt:

/*Start*/
i /*X*/ ++ /*End*/

type IndexExpr Uses

type IndexExpr struct {
    X     Expr // expression
    Index Expr // index expression
    Decs  IndexExprDecorations
}

An IndexExpr node represents an expression followed by an index.

func (*IndexExpr) Decorations Uses

func (n *IndexExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type IndexExprDecorations Uses

type IndexExprDecorations struct {
    NodeDecs
    X      Decorations
    Lbrack Decorations
    Index  Decorations
}

IndexExprDecorations holds decorations for IndexExpr:

var G = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 0 /*Index*/] /*End*/

type InterfaceType Uses

type InterfaceType struct {
    Methods    *FieldList // list of methods
    Incomplete bool       // true if (source) methods are missing in the Methods list
    Decs       InterfaceTypeDecorations
}

An InterfaceType node represents an interface type.

func (*InterfaceType) Decorations Uses

func (n *InterfaceType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type InterfaceTypeDecorations Uses

type InterfaceTypeDecorations struct {
    NodeDecs
    Interface Decorations
}

InterfaceTypeDecorations holds decorations for InterfaceType:

type U /*Start*/ interface /*Interface*/ {
	A()
} /*End*/

type KeyValueExpr Uses

type KeyValueExpr struct {
    Key   Expr
    Value Expr
    Decs  KeyValueExprDecorations
}

A KeyValueExpr node represents (key : value) pairs in composite literals.

func (*KeyValueExpr) Decorations Uses

func (n *KeyValueExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type KeyValueExprDecorations Uses

type KeyValueExprDecorations struct {
    NodeDecs
    Key   Decorations
    Colon Decorations
}

KeyValueExprDecorations holds decorations for KeyValueExpr:

var Q = map[string]string{
	/*Start*/ "a" /*Key*/ : /*Colon*/ "a", /*End*/
}

type LabeledStmt Uses

type LabeledStmt struct {
    Label *Ident
    Stmt  Stmt
    Decs  LabeledStmtDecorations
}

A LabeledStmt node represents a labeled statement.

func (*LabeledStmt) Decorations Uses

func (n *LabeledStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type LabeledStmtDecorations Uses

type LabeledStmtDecorations struct {
    NodeDecs
    Label Decorations
    Colon Decorations
}

LabeledStmtDecorations holds decorations for LabeledStmt:

/*Start*/
A /*Label*/ : /*Colon*/
	print("Stmt") /*End*/

type MapType Uses

type MapType struct {
    Key   Expr
    Value Expr
    Decs  MapTypeDecorations
}

A MapType node represents a map type.

func (*MapType) Decorations Uses

func (n *MapType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type MapTypeDecorations Uses

type MapTypeDecorations struct {
    NodeDecs
    Map Decorations
    Key Decorations
}

MapTypeDecorations holds decorations for MapType:

type V /*Start*/ map[ /*Map*/ int] /*Key*/ int /*End*/

type Node Uses

type Node interface {
    // Decorations returns the common Node decorations (Before, After, Start, End). This returns nil for Package nodes.
    Decorations() *NodeDecs
}

Node is satisfied by all nodes types.

func Clone Uses

func Clone(n Node) Node

Clone returns a deep copy of the node, ready to be re-used elsewhere in the tree.

Code:

code := `package main

	var i /* a */ int`

f, err := decorator.Parse(code)
if err != nil {
    panic(err)
}

cloned := dst.Clone(f.Decls[0]).(*dst.GenDecl)

cloned.Decs.Before = dst.NewLine
cloned.Specs[0].(*dst.ValueSpec).Names[0].Name = "j"
cloned.Specs[0].(*dst.ValueSpec).Names[0].Decs.End.Replace("/* b */")

f.Decls = append(f.Decls, cloned)

if err := decorator.Print(f); err != nil {
    panic(err)
}

Output:

package main

var i /* a */ int
var j /* b */ int

type NodeDecs Uses

type NodeDecs struct {
    Before SpaceType
    Start  Decorations
    End    Decorations
    After  SpaceType
}

NodeDecs holds the decorations that are common to all nodes (except Package).

type ObjKind Uses

type ObjKind int

ObjKind describes what an object represents.

const (
    Bad ObjKind = iota // for error handling
    Pkg                // package
    Con                // constant
    Typ                // type
    Var                // variable
    Fun                // function or method
    Lbl                // label
)

The list of possible Object kinds.

func (ObjKind) String Uses

func (kind ObjKind) String() string

type Object Uses

type Object struct {
    Kind ObjKind
    Name string      // declared name
    Decl interface{} // corresponding Field, XxxSpec, FuncDecl, LabeledStmt, AssignStmt, Scope; or nil
    Data interface{} // object-specific data; or nil
    Type interface{} // placeholder for type information; may be nil
}

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

func CloneObject Uses

func CloneObject(o *Object) *Object

CloneObject returns nil: After cloning a node, it should not be attached to the same object / scope.

func NewObj Uses

func NewObj(kind ObjKind, name string) *Object

NewObj creates a new object of a given kind and name.

type Package Uses

type Package struct {
    Name    string             // package name
    Scope   *Scope             // package scope across all files
    Imports map[string]*Object // map of package id -> package object
    Files   map[string]*File   // Go source files by filename
}

A Package node represents a set of source files collectively building a Go package.

func NewPackage Uses

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 (*Package) Decorations Uses

func (n *Package) Decorations() *NodeDecs

Decorations is nil for Package nodes.

type PackageDecorations Uses

type PackageDecorations struct {
    NodeDecs
}

PackageDecorations holds decorations for Package:

type ParenExpr Uses

type ParenExpr struct {
    X    Expr // parenthesized expression
    Decs ParenExprDecorations
}

A ParenExpr node represents a parenthesized expression.

func (*ParenExpr) Decorations Uses

func (n *ParenExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ParenExprDecorations Uses

type ParenExprDecorations struct {
    NodeDecs
    Lparen Decorations
    X      Decorations
}

ParenExprDecorations holds decorations for ParenExpr:

var E = /*Start*/ ( /*Lparen*/ 1 + 1 /*X*/) /*End*/ / 2

type RangeStmt Uses

type RangeStmt struct {
    Key, Value Expr        // Key, Value may be nil
    Tok        token.Token // ILLEGAL if Key == nil, ASSIGN, DEFINE
    X          Expr        // value to range over
    Body       *BlockStmt
    Decs       RangeStmtDecorations
}

A RangeStmt represents a for statement with a range clause.

func (*RangeStmt) Decorations Uses

func (n *RangeStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type RangeStmtDecorations Uses

type RangeStmtDecorations struct {
    NodeDecs
    For   Decorations
    Key   Decorations
    Value Decorations
    Range Decorations
    X     Decorations
}

RangeStmtDecorations holds decorations for RangeStmt:

/*Start*/
for range /*Range*/ a /*X*/ {
} /*End*/

/*Start*/
for /*For*/ k /*Key*/ := range /*Range*/ a /*X*/ {
	print(k)
} /*End*/

/*Start*/
for /*For*/ k /*Key*/, v /*Value*/ := range /*Range*/ a /*X*/ {
	print(k, v)
} /*End*/

type ReturnStmt Uses

type ReturnStmt struct {
    Results []Expr // result expressions; or nil
    Decs    ReturnStmtDecorations
}

A ReturnStmt node represents a return statement.

func (*ReturnStmt) Decorations Uses

func (n *ReturnStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ReturnStmtDecorations Uses

type ReturnStmtDecorations struct {
    NodeDecs
    Return Decorations
}

ReturnStmtDecorations holds decorations for ReturnStmt:

func() int {
	/*Start*/ return /*Return*/ 1 /*End*/
}()

type Scope Uses

type Scope struct {
    Outer   *Scope
    Objects map[string]*Object
}

A Scope maintains the set of named language entities declared in the scope and a link to the immediately surrounding (outer) scope.

func CloneScope Uses

func CloneScope(s *Scope) *Scope

CloneScope returns nil: After cloning a node, it should not be attached to the same object / scope.

func NewScope Uses

func NewScope(outer *Scope) *Scope

NewScope creates a new scope nested in the outer scope.

func (*Scope) Insert Uses

func (s *Scope) Insert(obj *Object) (alt *Object)

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.

func (*Scope) Lookup Uses

func (s *Scope) Lookup(name string) *Object

Lookup returns the object with the given name if it is found in scope s, otherwise it returns nil. Outer scopes are ignored.

func (*Scope) String Uses

func (s *Scope) String() string

Debugging support

type SelectStmt Uses

type SelectStmt struct {
    Body *BlockStmt // CommClauses only
    Decs SelectStmtDecorations
}

An SelectStmt node represents a select statement.

func (*SelectStmt) Decorations Uses

func (n *SelectStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type SelectStmtDecorations Uses

type SelectStmtDecorations struct {
    NodeDecs
    Select Decorations
}

SelectStmtDecorations holds decorations for SelectStmt:

/*Start*/
select /*Select*/ {
} /*End*/

type SelectorExpr Uses

type SelectorExpr struct {
    X    Expr   // expression
    Sel  *Ident // field selector
    Decs SelectorExprDecorations
}

A SelectorExpr node represents an expression followed by a selector.

func (*SelectorExpr) Decorations Uses

func (n *SelectorExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type SelectorExprDecorations Uses

type SelectorExprDecorations struct {
    NodeDecs
    X   Decorations
}

SelectorExprDecorations holds decorations for SelectorExpr:

var F = /*Start*/ tt. /*X*/ F /*End*/ ()

type SendStmt Uses

type SendStmt struct {
    Chan  Expr
    Value Expr
    Decs  SendStmtDecorations
}

A SendStmt node represents a send statement.

func (*SendStmt) Decorations Uses

func (n *SendStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type SendStmtDecorations Uses

type SendStmtDecorations struct {
    NodeDecs
    Chan  Decorations
    Arrow Decorations
}

SendStmtDecorations holds decorations for SendStmt:

/*Start*/
c /*Chan*/ <- /*Arrow*/ 0 /*End*/

type SliceExpr Uses

type SliceExpr struct {
    X      Expr // expression
    Low    Expr // begin of slice range; or nil
    High   Expr // end of slice range; or nil
    Max    Expr // maximum capacity of slice; or nil
    Slice3 bool // true if 3-index slice (2 colons present)
    Decs   SliceExprDecorations
}

An SliceExpr node represents an expression followed by slice indices.

func (*SliceExpr) Decorations Uses

func (n *SliceExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type SliceExprDecorations Uses

type SliceExprDecorations struct {
    NodeDecs
    X      Decorations
    Lbrack Decorations
    Low    Decorations
    High   Decorations
    Max    Decorations
}

SliceExprDecorations holds decorations for SliceExpr:

var H = /*Start*/ []int{0, 1, 2} /*X*/ [ /*Lbrack*/ 1: /*Low*/ 2: /*High*/ 3 /*Max*/] /*End*/

var H1 = /*Start*/ []int{0, 1, 2} /*X*/ [ /*Lbrack*/ 1: /*Low*/ 2 /*High*/] /*End*/

var H2 = /*Start*/ []int{0} /*X*/ [: /*Low*/] /*End*/

var H3 = /*Start*/ []int{0} /*X*/ [ /*Lbrack*/ 1: /*Low*/] /*End*/

var H4 = /*Start*/ []int{0, 1, 2} /*X*/ [: /*Low*/ 2 /*High*/] /*End*/

var H5 = /*Start*/ []int{0, 1, 2} /*X*/ [: /*Low*/ 2: /*High*/ 3 /*Max*/] /*End*/

type SpaceType Uses

type SpaceType int

SpaceType represents the line spacing before or after a node. When the start of one node is adjacent to the end of another node, the SpaceType values are not additive (e.g. two NewLines will render a NewLine and not an EmptyLine).

const (
    None      SpaceType = 0 // None means no extra spacing.
    NewLine   SpaceType = 1 // NewLine is a single "\n"
    EmptyLine SpaceType = 2 // EmptyLine is a double "\n"
)

func (SpaceType) String Uses

func (s SpaceType) String() string

String returns a human readable representation of the space type

type Spec Uses

type Spec interface {
    Node
    // contains filtered or unexported methods
}

The Spec type stands for any of *ImportSpec, *ValueSpec, and *TypeSpec.

type StarExpr Uses

type StarExpr struct {
    X    Expr // operand
    Decs StarExprDecorations
}

A StarExpr node represents an expression of the form "*" Expression. Semantically it could be a unary "*" expression, or a pointer type.

func (*StarExpr) Decorations Uses

func (n *StarExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type StarExprDecorations Uses

type StarExprDecorations struct {
    NodeDecs
    Star Decorations
}

StarExprDecorations holds decorations for StarExpr:

var N = /*Start*/ * /*Star*/ p /*End*/

type Stmt Uses

type Stmt interface {
    Node
    // contains filtered or unexported methods
}

All statement nodes implement the Stmt interface.

type StructType Uses

type StructType struct {
    Fields     *FieldList // list of field declarations
    Incomplete bool       // true if (source) fields are missing in the Fields list
    Decs       StructTypeDecorations
}

A StructType node represents a struct type.

func (*StructType) Decorations Uses

func (n *StructType) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type StructTypeDecorations Uses

type StructTypeDecorations struct {
    NodeDecs
    Struct Decorations
}

StructTypeDecorations holds decorations for StructType:

type S /*Start*/ struct /*Struct*/ {
	A int
} /*End*/

type SwitchStmt Uses

type SwitchStmt struct {
    Init Stmt       // initialization statement; or nil
    Tag  Expr       // tag expression; or nil
    Body *BlockStmt // CaseClauses only
    Decs SwitchStmtDecorations
}

A SwitchStmt node represents an expression switch statement.

func (*SwitchStmt) Decorations Uses

func (n *SwitchStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type SwitchStmtDecorations Uses

type SwitchStmtDecorations struct {
    NodeDecs
    Switch Decorations
    Init   Decorations
    Tag    Decorations
}

SwitchStmtDecorations holds decorations for SwitchStmt:

/*Start*/
switch /*Switch*/ i /*Tag*/ {
} /*End*/

/*Start*/
switch /*Switch*/ a := i; /*Init*/ a /*Tag*/ {
} /*End*/

type TypeAssertExpr Uses

type TypeAssertExpr struct {
    X    Expr // expression
    Type Expr // asserted type; nil means type switch X.(type)
    Decs TypeAssertExprDecorations
}

A TypeAssertExpr node represents an expression followed by a type assertion.

func (*TypeAssertExpr) Decorations Uses

func (n *TypeAssertExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type TypeAssertExprDecorations Uses

type TypeAssertExprDecorations struct {
    NodeDecs
    X      Decorations
    Lparen Decorations
    Type   Decorations
}

TypeAssertExprDecorations holds decorations for TypeAssertExpr:

var J = /*Start*/ f. /*X*/ ( /*Lparen*/ int /*Type*/) /*End*/

type TypeSpec Uses

type TypeSpec struct {
    Name   *Ident // type name
    Assign bool   // position of '=', if any
    Type   Expr   // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
    Decs   TypeSpecDecorations
}

A TypeSpec node represents a type declaration (TypeSpec production).

func (*TypeSpec) Decorations Uses

func (n *TypeSpec) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type TypeSpecDecorations Uses

type TypeSpecDecorations struct {
    NodeDecs
    Name Decorations
}

TypeSpecDecorations holds decorations for TypeSpec:

type (
	/*Start*/ T1 /*Name*/ []int /*End*/
)

type (
	/*Start*/ T2 = /*Name*/ T1 /*End*/
)

type TypeSwitchStmt Uses

type TypeSwitchStmt struct {
    Init   Stmt       // initialization statement; or nil
    Assign Stmt       // x := y.(type) or y.(type)
    Body   *BlockStmt // CaseClauses only
    Decs   TypeSwitchStmtDecorations
}

An TypeSwitchStmt node represents a type switch statement.

func (*TypeSwitchStmt) Decorations Uses

func (n *TypeSwitchStmt) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type TypeSwitchStmtDecorations Uses

type TypeSwitchStmtDecorations struct {
    NodeDecs
    Switch Decorations
    Init   Decorations
    Assign Decorations
}

TypeSwitchStmtDecorations holds decorations for TypeSwitchStmt:

/*Start*/
switch /*Switch*/ f.(type) /*Assign*/ {
} /*End*/

/*Start*/
switch /*Switch*/ g := f.(type) /*Assign*/ {
case int:
	print(g)
} /*End*/

/*Start*/
switch /*Switch*/ g := f; /*Init*/ g := g.(type) /*Assign*/ {
case int:
	print(g)
} /*End*/

type UnaryExpr Uses

type UnaryExpr struct {
    Op   token.Token // operator
    X    Expr        // operand
    Decs UnaryExprDecorations
}

A UnaryExpr node represents a unary expression. Unary "*" expressions are represented via StarExpr nodes.

func (*UnaryExpr) Decorations Uses

func (n *UnaryExpr) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type UnaryExprDecorations Uses

type UnaryExprDecorations struct {
    NodeDecs
    Op  Decorations
}

UnaryExprDecorations holds decorations for UnaryExpr:

var O = /*Start*/ ^ /*Op*/ 1 /*End*/

type ValueSpec Uses

type ValueSpec struct {
    Names  []*Ident // value names (len(Names) > 0)
    Type   Expr     // value type; or nil
    Values []Expr   // initial values; or nil
    Decs   ValueSpecDecorations
}

A ValueSpec node represents a constant or variable declaration (ConstSpec or VarSpec production).

func (*ValueSpec) Decorations Uses

func (n *ValueSpec) Decorations() *NodeDecs

Decorations returns the decorations that are common to all nodes (Before, Start, End, After).

type ValueSpecDecorations Uses

type ValueSpecDecorations struct {
    NodeDecs
    Assign Decorations
}

ValueSpecDecorations holds decorations for ValueSpec:

var (
	/*Start*/ j = /*Assign*/ 1 /*End*/
)

var (
	/*Start*/ k, l = /*Assign*/ 1, 2 /*End*/
)

var (
	/*Start*/ m, n int = /*Assign*/ 1, 2 /*End*/
)

type Visitor Uses

type Visitor interface {
    Visit(node Node) (w Visitor)
}

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).

Directories

PathSynopsis
decorator
decorator/resolver
decorator/resolver/goast
decorator/resolver/gobuild
decorator/resolver/gopackages
decorator/resolver/gotypes
decorator/resolver/guess
decorator/resolver/simple
dstutil
gendst
gendst/data

Package dst imports 10 packages (graph) and is imported by 27 packages. Updated 2020-06-25. Refresh now. Tools for package owners.