Movatterモバイル変換


[0]ホーム

URL:


decorator

package
v0.27.3Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License:BSD-3-Clause, MITImports:20Imported by:247

Details

Repository

github.com/dave/dst

Links

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcDecorate

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

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

funcDecorateFileadded inv0.1.0

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

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

funcFprint

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

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

funcParse

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

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

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

funcParseFileadded inv0.1.0

func ParseFile(fset *token.FileSet, filenamestring, src interface{}, modeparser.Mode) (*dst.File,error)

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

funcPrint

func Print(f *dst.File)error

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

funcRestoreFileadded inv0.16.0

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

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

Types

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

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

funcNewDecoratoradded inv0.16.0

func NewDecorator(fset *token.FileSet) *Decorator

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

funcNewDecoratorFromPackageadded inv0.16.0

func NewDecoratorFromPackage(pkg *packages.Package) *Decorator

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

funcNewDecoratorWithImportsadded inv0.16.0

func NewDecoratorWithImports(fset *token.FileSet, pathstring, resolverresolver.DecoratorResolver) *Decorator

NewDecoratorWithImports returns a new decorator with import management enabled.

func (*Decorator)DecorateFileadded inv0.11.0

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

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

func (*Decorator)DecorateNodeadded inv0.11.0

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

DecorateNode decorates ast.Node and returns dst.Node

func (*Decorator)Parseadded inv0.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 shouldbe string, []byte, or io.Reader.

func (*Decorator)ParseDiradded 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.

func (*Decorator)ParseFileadded inv0.12.2

func (d *Decorator) ParseFile(filenamestring, src interface{}, modeparser.Mode) (*dst.File,error)

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

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

typeFileRestoreradded 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)Fprintadded inv0.16.0

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

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

func (*FileRestorer)Printadded inv0.16.0

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

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

func (*FileRestorer)RestoreFileadded inv0.16.0

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

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

typeMapadded inv0.9.0

type Map struct {AstAstMapDstDstMap}

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

typePackageadded inv0.11.0

type Package struct {*packages.PackageDirstringDecorator *DecoratorImports   map[string]*PackageSyntax    []*dst.File}

funcLoadadded inv0.11.0

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

func (*Package)Saveadded inv0.11.0

func (p *Package) Save()error

func (*Package)SaveWithResolveradded inv0.19.0

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

typeRestoreradded 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

funcNewRestoreradded inv0.1.0

func NewRestorer() *Restorer

NewRestorer returns a restorer.

funcNewRestorerWithImportsadded inv0.11.0

func NewRestorerWithImports(pathstring, resolverresolver.RestorerResolver) *Restorer

NewRestorerWithImports returns a restorer with import management attributes set.

func (*Restorer)FileRestoreradded inv0.11.0

func (pr *Restorer) FileRestorer() *FileRestorer

FileRestorer restores a specific file with extra options

func (*Restorer)Fprintadded inv0.11.0

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

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

func (*Restorer)Printadded inv0.11.0

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

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

func (*Restorer)RestoreFileadded inv0.1.0

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

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

Source Files

View all Source files

Directories

PathSynopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp