decorator
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
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 RestoreFile(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¶
funcDecorateFile¶added inv0.1.0
Decorate decorates a *ast.File and returns a *dst.File.
funcParse¶
Parse uses parser.ParseFile to parse and decorate a Go source file. The src parameter shouldbe string, []byte, or io.Reader.
funcParseDir¶added inv0.1.0
func ParseDir(fset *token.FileSet, dirstring, filter func(os.FileInfo)bool, modeparser.Mode) (map[string]*dst.Package,error)
ParseDir uses parser.ParseDir to parse and decorate a directory containing Go source. TheParseComments flag is added to mode if it doesn't exist.
Types¶
typeAstMap¶added inv0.9.0
type AstMap struct {Nodes map[dst.Node]ast.Node// Mapping from dst to ast NodesObjects map[*dst.Object]*ast.Object// Mapping from dst to ast ObjectsScopes 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.
typeDecorator¶added inv0.1.0
type Decorator struct {Map// Mapping between ast and dst Nodes, Objects and ScopesFilenames map[*dst.File]string// Source file namesFset *token.FileSet// The ast FileSet containing ast decoration info for the files// 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.Resolverresolver.DecoratorResolver// Local package path - required if Resolver is set.Pathstring// By default local idents are left with an empty Path, so they stay local if the local package// is renamed. Setting ResolveLocalPath to true prevents this, so all idents will have the// package path added.ResolveLocalPathbool}Decorator converts ast nodes into dst nodes, and converts decoration info from the ast filesetto the dst nodes. Create a new Decorator for each package you need to decorate.
funcNewDecorator¶added inv0.16.0
NewDecorator returns a new decorator. If fset is nil, a new FileSet is created.
funcNewDecoratorFromPackage¶added inv0.16.0
NewDecoratorFromPackage returns a new decorator configured to decorate files in pkg.
funcNewDecoratorWithImports¶added inv0.16.0
func NewDecoratorWithImports(fset *token.FileSet, pathstring, resolverresolver.DecoratorResolver) *Decorator
NewDecoratorWithImports returns a new decorator with import management enabled.
func (*Decorator)DecorateFile¶added inv0.11.0
DecorateFile decorates *ast.File and returns *dst.File
func (*Decorator)DecorateNode¶added inv0.11.0
DecorateNode decorates ast.Node and returns dst.Node
func (*Decorator)Parse¶added inv0.12.2
Parse uses parser.ParseFile to parse and decorate a Go source file. The src parameter shouldbe string, []byte, or io.Reader.
func (*Decorator)ParseDir¶added inv0.12.2
func (d *Decorator) ParseDir(dirstring, filter func(os.FileInfo)bool, modeparser.Mode) (map[string]*dst.Package,error)
ParseDir uses parser.ParseDir to parse and decorate a directory containing Go source. TheParseComments flag is added to mode if it doesn't exist.
typeDstMap¶added inv0.9.0
type DstMap struct {Nodes map[ast.Node]dst.Node// Mapping from ast to dst NodesObjects map[*ast.Object]*dst.Object// Mapping from ast to dst ObjectsScopes 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.
typeFileRestorer¶added inv0.11.0
type FileRestorer struct {*RestorerAlias map[string]string// Map of package path -> package alias for importsNamestring// The name of the restored file in the FileSet. Can usually be left empty.// contains filtered or unexported fields}FileRestorer restores a specific file with extra options
func (*FileRestorer)Print¶added inv0.16.0
func (r *FileRestorer) Print(f *dst.File)error
Print uses format.Node to print a *dst.File to stdout
func (*FileRestorer)RestoreFile¶added inv0.16.0
RestoreFile restores a *dst.File to *ast.File
typeMap¶added inv0.9.0
Map holds a record of the mapping between ast and dst nodes, objects and scopes.
typePackage¶added inv0.11.0
type Package struct {*packages.PackageDirstringDecorator *DecoratorImports map[string]*PackageSyntax []*dst.File}func (*Package)SaveWithResolver¶added inv0.19.0
func (p *Package) SaveWithResolver(resolverresolver.RestorerResolver)error
typeRestorer¶added inv0.1.0
type Restorer struct {MapFset *token.FileSet// Fset is the *token.FileSet in use. Set this to use a pre-existing FileSet.Extrasbool// Resore Objects, Scopes etc. Not needed for printing the resultant AST. If set to true, Objects and Scopes must be carefully managed to avoid duplicate nodes.// 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.Resolverresolver.RestorerResolver// Local package path - required if Resolver is set.Pathstring}Restorer restores dst.Node to ast.Node
funcNewRestorerWithImports¶added inv0.11.0
func NewRestorerWithImports(pathstring, resolverresolver.RestorerResolver) *Restorer
NewRestorerWithImports returns a restorer with import management attributes set.
func (*Restorer)FileRestorer¶added inv0.11.0
func (pr *Restorer) FileRestorer() *FileRestorer
FileRestorer restores a specific file with extra options