ezast

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqualAstFile

func AssertEqualAstFile(want, got *ast.File) bool

Assert two ASTs are structurally equivalent

Types

type AstFile

type AstFile struct {
	*ast.File
	// contains filtered or unexported fields
}

ast.File with token.FileSet

func NewAstFile

func NewAstFile(file string) (*AstFile, error)

NewAstFile parses the source code of a single Go source file and returns the corresponding ast.File node

func (*AstFile) ChangePackage

func (a *AstFile) ChangePackage(newPkg string) error

Change package name

func (*AstFile) ContainsFunc

func (a *AstFile) ContainsFunc(fn string) bool

ContainsFunc returns true if AST contains func fn

func (*AstFile) GetFuncDecl

func (a *AstFile) GetFuncDecl(fn string) *ast.FuncDecl

GetFuncDecl returns declaration of func named fn.

If there is no declaration, it returns nil.

func (AstFile) SaveTemp

func (a AstFile) SaveTemp(file string) (outFile string, cleaner func(), err error)

Save AST as source code to temp file.

SaveTemp returns filePath, temp file cleaner func , and error. Cleaner func is not always nil, so you may call it any time.

func (AstFile) String

func (a AstFile) String() string

Convert to minimized source code text.

func (*AstFile) SwapSimpleFuncs

func (a *AstFile) SwapSimpleFuncs(fn1, fn2 string, strict bool) error

Swap func name of fn1 and one of f2. * Funcs must not have arguments and return values.

If strict is true, fn1 and fn2 must be present. When either is not present, SwapSimpleFuncs returns error.

If strict is false, only present func is renamed, SwapSimpleFuncs returns no errors.

Jump to

Keyboard shortcuts

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