decorator

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2018 License: MIT Imports: 20 Imported by: 210

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decorate

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

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

func DecorateFile added in v0.1.0

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

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

func Fprint

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

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

func Parse

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

func ParseFile added in v0.1.0

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

func Print(f *dst.File) error

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

func Restore

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

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

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
}

type Decorator added in v0.1.0

type Decorator struct {
	Map
	Filenames map[*dst.File]string // Source file names
	Fset      *token.FileSet

	Path string // local package path, used to ensure the local path is not set in idents

	// If a Resolver is provided, it is used to resolve Ident nodes. During decoration, remote
	// identifiers (e.g. usually part of a qualified identifier SelectorExpr, but sometimes on
	// their own for dot-imported packages) are updated with the path of the package they are
	// imported from.
	Resolver resolver.IdentResolver
	// contains filtered or unexported fields
}

func New added in v0.1.0

func New(fset *token.FileSet) *Decorator

New returns a new package decorator

func NewWithImports added in v0.11.0

func NewWithImports(pkg *packages.Package) *Decorator

NewWithImports returns a new package decorator with import management attributes set.

func (*Decorator) DecorateFile added in v0.11.0

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

func (*Decorator) DecorateNode added in v0.11.0

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

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

func (*Decorator) Parse added in v0.12.2

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

func (*Decorator) ParseFile added in v0.12.2

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 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
}

type FileRestorer added in v0.11.0

type FileRestorer struct {
	*Restorer
	Alias map[string]string // map of package path -> package alias for imports
	// contains filtered or unexported fields
}

func (*FileRestorer) Restore added in v0.11.0

func (fr *FileRestorer) Restore() *ast.File

type Map added in v0.9.0

type Map struct {
	Ast AstMap
	Dst DstMap
}

type Package added in v0.11.0

type Package struct {
	*packages.Package
	Dir       string
	Decorator *Decorator
	Files     []*dst.File
}

func Load added in v0.11.0

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

func (*Package) Save added in v0.11.0

func (p *Package) Save() error

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
}

func NewRestorer added in v0.1.0

func NewRestorer() *Restorer

NewRestorer returns a restorer.

func NewRestorerWithImports added in v0.11.0

func NewRestorerWithImports(path, dir string) *Restorer

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

func (*Restorer) Fprint added in v0.11.0

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 added in v0.11.0

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

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

func (*Restorer) RestoreFile added in v0.1.0

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL