Documentation ¶
Index ¶
- func Decorate(fset *token.FileSet, n ast.Node) (dst.Node, error)
- func DecorateFile(fset *token.FileSet, f *ast.File) (*dst.File, error)
- func Fprint(w io.Writer, f *dst.File) error
- func Parse(src interface{}) (*dst.File, error)
- func ParseDir(fset *token.FileSet, dir string, filter func(os.FileInfo) bool, ...) (map[string]*dst.Package, error)
- func ParseFile(fset *token.FileSet, filename string, src interface{}, mode parser.Mode) (*dst.File, error)
- func Print(f *dst.File) error
- func Restore(file *dst.File) (*token.FileSet, *ast.File, error)
- type AstMap
- type Decorator
- func (d *Decorator) DecorateFile(f *ast.File) (*dst.File, error)
- func (d *Decorator) DecorateNode(n ast.Node) (dst.Node, error)
- func (d *Decorator) Parse(src interface{}) (*dst.File, error)
- func (d *Decorator) ParseDir(dir string, filter func(os.FileInfo) bool, mode parser.Mode) (map[string]*dst.Package, error)
- func (d *Decorator) ParseFile(filename string, src interface{}, mode parser.Mode) (*dst.File, error)
- type DstMap
- type FileRestorer
- type Map
- type Package
- type Restorer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecorateFile ¶ added in v0.1.0
Decorate decorates a *ast.File and returns a *dst.File.
func Parse ¶
Parse uses parser.ParseFile to parse and decorate a Go source file. The src parameter should be string, []byte, or io.Reader.
func ParseDir ¶ added in v0.1.0
func ParseDir(fset *token.FileSet, dir string, filter func(os.FileInfo) bool, mode parser.Mode) (map[string]*dst.Package, error)
ParseDir uses parser.ParseDir to parse and decorate a directory containing Go source. The ParseComments flag is added to mode if it doesn't exist.
Types ¶
type AstMap ¶ added in v0.9.0
type AstMap struct { Nodes map[dst.Node]ast.Node // Mapping from dst to ast Nodes Objects map[*dst.Object]*ast.Object // Mapping from dst to ast Objects Scopes map[*dst.Scope]*ast.Scope // Mapping from dst to ast Scopes }
AstMap holds a record of the mapping from dst to ast nodes, objects and scopes.
type Decorator ¶ added in v0.1.0
type Decorator struct { Map Filenames map[*dst.File]string // Source file names Fset *token.FileSet // If a Resolver is provided, it is used to resolve remote identifiers from *ast.Ident and // *ast.SelectorExpr nodes. Usually a remote identifier is a SelectorExpr qualified identifier, // but in the case of dot-imports they can be simply Ident nodes. During decoration, remote // identifiers are replaced with *dst.Ident with Path set to the path of imported package. Resolver resolver.IdentResolver // Local package path - required if Resolver is set. Path string }
func NewWithImports ¶ added in v0.11.0
NewWithImports returns a new package decorator with import management attributes set.
func (*Decorator) DecorateFile ¶ added in v0.11.0
func (*Decorator) DecorateNode ¶ added in v0.11.0
Decorate decorates an ast.Node and returns a dst.Node
func (*Decorator) Parse ¶ added in v0.12.2
Parse uses parser.ParseFile to parse and decorate a Go source file. The src parameter should be string, []byte, or io.Reader.
func (*Decorator) ParseDir ¶ added in v0.12.2
func (d *Decorator) ParseDir(dir string, filter func(os.FileInfo) bool, mode parser.Mode) (map[string]*dst.Package, error)
ParseDir uses parser.ParseDir to parse and decorate a directory containing Go source. The ParseComments flag is added to mode if it doesn't exist.
type DstMap ¶ added in v0.9.0
type DstMap struct { Nodes map[ast.Node]dst.Node // Mapping from ast to dst Nodes Objects map[*ast.Object]*dst.Object // Mapping from ast to dst Objects Scopes map[*ast.Scope]*dst.Scope // Mapping from ast to dst Scopes }
DstMap holds a record of the mapping from ast to dst nodes, objects and scopes.
type FileRestorer ¶ added in v0.11.0
type Map ¶ added in v0.9.0
Map holds a record of the mapping between ast and dst nodes, objects and scopes.
type Restorer ¶ added in v0.1.0
type Restorer struct { Map Fset *token.FileSet // Fset is the *token.FileSet in use. Set this to use a pre-existing FileSet. // If a Resolver is provided, the names of all imported packages are resolved, and the imports // block is updated. All remote identifiers are updated (sometimes this involves changing // SelectorExpr.X.Name, or even swapping between Ident and SelectorExpr). To force specific // import alias names, use the FileRestorer.Alias map. Resolver resolver.PackageResolver // Local package path - required if Resolver is set. Path string }
func NewRestorerWithImports ¶ added in v0.11.0
NewRestorerWithImports returns a restorer with import management attributes set.
func (*Restorer) FileRestorer ¶ added in v0.11.0
func (pr *Restorer) FileRestorer(name string, file *dst.File) *FileRestorer