rewrite

package
v0.0.0-...-f64633d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite

func Rewrite(
	buildCtx *build.Context,
	srcDir string,
	paths []string,
	getApplyFuncs func(pkg *Package) (pre, post apply.ApplyFunc),
) ([]string, error)

Rewrite reads, parses and type checks the Go code in all the given packages, and traverses the syntax tree of each file, calling pre and post for each node as described in the apply package. Any changes made to the syntax tree will be written to the respective file.

Rewrite returns a slice holding the names of all the packages that have been changed.

Types

type Package

type Package struct {
	Prog *loader.Program
	*loader.PackageInfo
	// contains filtered or unexported fields
}

func (*Package) IsPkgDot

func (pkg *Package) IsPkgDot(t ast.Node, importPath, name string) bool

isPkgDot reports whether t is a selector expression of the form x.name where x refers to the package with the given import path.

func (*Package) IsPkgName

func (pkg *Package) IsPkgName(t ast.Node, importPath string) bool

IsPkgName reports whether t refers to a package with the given import path.

func (*Package) PackageIdent

func (pkg *Package) PackageIdent(importPath, identifier string) *ast.Ident

PackageName returns a new identifier that refers to the given import path. Rewrite will ensure that the named package will be imported by the file being rewritten. The identifier argument holds the preferred identifier for the package, which will be used if the package doesn't already a local identifier. If identifier is empty, a suitable name will be chosen automatically.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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