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

package decorator

import "github.com/dave/dst/decorator"

Index

Package Files

decorator-fragment-generated.go decorator-fragment.go decorator-info-generated.go decorator-node-generated.go decorator.go helpers.go load.go map.go restorer-generated.go restorer.go

func Decorate Uses

func Decorate(fset *token.FileSet, n ast.Node) (dst.Node, error)

Decorate decorates an ast.Node and returns a dst.Node.

func DecorateFile Uses

func DecorateFile(fset *token.FileSet, f *ast.File) (*dst.File, error)

Decorate decorates a *ast.File and returns a *dst.File.

func Fprint Uses

func Fprint(w io.Writer, f *dst.File) error

Fprint uses format.Node to print a *dst.File to a writer

func Parse Uses

func Parse(src interface{}) (*dst.File, error)

Parse uses parser.ParseFile to parse and decorate a Go source file. The src parameter should be string, []byte, or io.Reader.

func ParseDir Uses

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.

func ParseFile Uses

func ParseFile(fset *token.FileSet, filename string, src interface{}, mode parser.Mode) (*dst.File, error)

ParseFile uses parser.ParseFile to parse and decorate a Go source file. The ParseComments flag is added to mode if it doesn't exist.

func Print Uses

func Print(f *dst.File) error

Print uses format.Node to print a *dst.File to stdout

func RestoreFile Uses

func RestoreFile(file *dst.File) (*token.FileSet, *ast.File, error)

RestoreFile restores a *dst.File to a *token.FileSet and a *ast.File

type AstMap Uses

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 Uses

type Decorator struct {
    Map                            // Mapping between ast and dst Nodes, Objects and Scopes
    Filenames map[*dst.File]string // Source file names
    Fset      *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.
    Resolver resolver.DecoratorResolver
    // Local package path - required if Resolver is set.
    Path string
}

Decorator converts ast nodes into dst nodes, and converts decoration info from the ast fileset to the dst nodes. Create a new Decorator for each package you need to decorate.

func NewDecorator Uses

func NewDecorator(fset *token.FileSet) *Decorator

NewDecorator returns a new decorator. If fset is nil, a new FileSet is created.

func NewDecoratorFromPackage Uses

func NewDecoratorFromPackage(pkg *packages.Package) *Decorator

NewDecoratorFromPackage returns a new decorator configured to decorate files in pkg.

func NewDecoratorWithImports Uses

func NewDecoratorWithImports(fset *token.FileSet, path string, resolver resolver.DecoratorResolver) *Decorator

NewDecoratorWithImports returns a new decorator with import management enabled.

func (*Decorator) DecorateFile Uses

func (d *Decorator) DecorateFile(f *ast.File) (*dst.File, error)

DecorateFile decorates *ast.File and returns *dst.File

func (*Decorator) DecorateNode Uses

func (d *Decorator) DecorateNode(n ast.Node) (dst.Node, error)

DecorateNode decorates ast.Node and returns dst.Node

func (*Decorator) Parse Uses

func (d *Decorator) Parse(src interface{}) (*dst.File, error)

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 Uses

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.

func (*Decorator) ParseFile Uses

func (d *Decorator) ParseFile(filename string, src interface{}, mode parser.Mode) (*dst.File, error)

ParseFile uses parser.ParseFile to parse and decorate a Go source file. The ParseComments flag is added to mode if it doesn't exist.

type DstMap Uses

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 Uses

type FileRestorer struct {
    *Restorer
    Alias map[string]string // Map of package path -> package alias for imports
    Name  string            // 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) Fprint Uses

func (r *FileRestorer) Fprint(w io.Writer, f *dst.File) error

Fprint uses format.Node to print a *dst.File to a writer

func (*FileRestorer) Print Uses

func (r *FileRestorer) Print(f *dst.File) error

Print uses format.Node to print a *dst.File to stdout

func (*FileRestorer) RestoreFile Uses

func (r *FileRestorer) RestoreFile(file *dst.File) (*ast.File, error)

RestoreFile restores a *dst.File to *ast.File

type Map Uses

type Map struct {
    Ast AstMap
    Dst DstMap
}

Map holds a record of the mapping between ast and dst nodes, objects and scopes.

type Package Uses

type Package struct {
    *packages.Package
    Dir       string
    Decorator *Decorator
    Imports   map[string]*Package
    Syntax    []*dst.File
}

func Load Uses

func Load(cfg *packages.Config, patterns ...string) ([]*Package, error)

func (*Package) Save Uses

func (p *Package) Save() error

func (*Package) SaveWithResolver Uses

func (p *Package) SaveWithResolver(resolver resolver.RestorerResolver) error

type Restorer Uses

type Restorer struct {
    Map
    Fset   *token.FileSet // Fset is the *token.FileSet in use. Set this to use a pre-existing FileSet.
    Extras bool           // 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.
    Resolver resolver.RestorerResolver
    // Local package path - required if Resolver is set.
    Path string
}

Restorer restores dst.Node to ast.Node

func NewRestorer Uses

func NewRestorer() *Restorer

NewRestorer returns a restorer.

func NewRestorerWithImports Uses

func NewRestorerWithImports(path string, resolver resolver.RestorerResolver) *Restorer

NewRestorerWithImports returns a restorer with import management attributes set.

func (*Restorer) FileRestorer Uses

func (pr *Restorer) FileRestorer() *FileRestorer

FileRestorer restores a specific file with extra options

func (*Restorer) Fprint Uses

func (pr *Restorer) Fprint(w io.Writer, f *dst.File) error

Fprint uses format.Node to print a *dst.File to a writer

func (*Restorer) Print Uses

func (pr *Restorer) Print(f *dst.File) error

Print uses format.Node to print a *dst.File to stdout

func (*Restorer) RestoreFile Uses

func (pr *Restorer) RestoreFile(file *dst.File) (*ast.File, error)

RestoreFile restores a *dst.File to an *ast.File

Directories

PathSynopsis
resolver
resolver/goast
resolver/gobuild
resolver/gopackages
resolver/gotypes
resolver/guess
resolver/simple

Package decorator imports 19 packages (graph) and is imported by 5 packages. Updated 2019-02-06. Refresh now. Tools for package owners.