Documentation ¶
Index ¶
- func StackTypes(list []ast.Node) string
- func Walk(n ast.Node, f func(stack []ast.Node))
- func WalkPost(n ast.Node, f func(stack []ast.Node))
- func WalkRange(n ast.Node, lo, hi token.Pos, f func(stack []ast.Node))
- func WalkRangePost(n ast.Node, lo, hi token.Pos, f func(stack []ast.Node))
- type Buffer
- type Config
- type Configs
- type DepsGraph
- type DepsGraphLevel
- type Edit
- type Error
- type ErrorList
- type File
- type Item
- type ItemKind
- type NewImport
- type Package
- type QualName
- type Refactor
- type Snapshot
- func (s *Snapshot) Addr(pos token.Pos) string
- func (s *Snapshot) CheckImportCycle(g *DepsGraph) error
- func (s *Snapshot) CreateFile(p *Package, baseName, text string) *ast.File
- func (s *Snapshot) CreatePackage(pkgpath string) (*Package, error)
- func (s *Snapshot) DeleteAt(pos, end token.Pos)
- func (s *Snapshot) DeleteFile(pos token.Pos)
- func (s *Snapshot) DepsGraph(level DepsGraphLevel) *DepsGraph
- func (s *Snapshot) Diff() ([]byte, error)
- func (s *Snapshot) ErrorAt(pos token.Pos, format string, args ...interface{})
- func (s *Snapshot) Eval(expr string) *Item
- func (s *Snapshot) EvalList(args string) ([]*Item, []string)
- func (s *Snapshot) EvalNext(args string) (*Item, string, string)
- func (s *Snapshot) File(pos token.Pos) string
- func (s *Snapshot) FileAt(pos token.Pos) (*Package, *ast.File)
- func (s *Snapshot) FileByName(name string) (*Package, *ast.File)
- func (s *Snapshot) FileRange(pos token.Pos) (start, end token.Pos)
- func (s *Snapshot) ForEachFile(f func(pkg *Package, file *ast.File))
- func (s *Snapshot) ForEachTargetFile(f func(pkg *Package, file *ast.File))
- func (s *Snapshot) ForceDeleteAt(pos, end token.Pos)
- func (s *Snapshot) Fset() *token.FileSet
- func (s *Snapshot) Gofmt()
- func (s *Snapshot) InsertAt(pos token.Pos, repl string)
- func (s *Snapshot) LookupAt(name string, pos token.Pos) types.Object
- func (s *Snapshot) Modified() []string
- func (s *Snapshot) NeedImport(pos token.Pos, id string, pkg *types.Package) string
- func (s *Snapshot) PackageAt(pos token.Pos) *Package
- func (s *Snapshot) Packages() []*Package
- func (s *Snapshot) Position(pos token.Pos) token.Position
- func (s *Snapshot) QualNameOf(obj types.Object) QualName
- func (s *Snapshot) Refactor() *Refactor
- func (s *Snapshot) ReplaceAt(lo, hi token.Pos, repl string)
- func (s *Snapshot) ReplaceNode(n ast.Node, repl string)
- func (s *Snapshot) Reset()
- func (s *Snapshot) ScopeAt(pos token.Pos) *types.Scope
- func (s *Snapshot) SyntaxAt(pos token.Pos) []ast.Node
- func (s *Snapshot) Target() *Package
- func (s *Snapshot) Text(lo, hi token.Pos) []byte
- func (s *Snapshot) Write() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StackTypes ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
A Buffer is a queue of edits to apply to a file text. It's like edit.Buffer but uses token.Pos as coordinate space.
func (*Buffer) Bytes ¶
Bytes returns a new byte slice containing the original data with the queued edits applied.
func (*Buffer) ForceDelete ¶
type Config ¶
type Config struct { // BuildTags is a list of build tags to set for this configuration. // // Some build tags are propagated specially: // // - GOOS and GOARCH build tags control the GOOS/GOARCH environment // variables. // // - The "race" build tag controls the -race flag. // // - The "cgo" and "!cgo" build tags control the CGO_ENABLED environment // variable. // // TODO: We might need to do something for release tags, too. BuildTags []string }
type Configs ¶
type Configs struct {
// contains filtered or unexported fields
}
func ConfigsAllPlatforms ¶
ConfigsAllPlatforms returns a Configs for all GOOS/GOARCH combinations, including covering both cgo and non-cgo where possible.
func NewConfigs ¶
NewConfigs returns a new Configs consisting of one Config with the given build tags.
type DepsGraph ¶
type DepsGraph struct { Level DepsGraphLevel // G is the graph, where G[p1][n1][p2][n2] is true if p1.n1 references p2.n2. G map[*Package]map[string]map[*Package]map[string]bool }
A DepsGraph records dependency information.
This is a graph over QualName nodes, with edges from each package-level declaration to the identifiers it references. If Level is PkgsRefs, then QualName.Name is always "", so this decays into references between packages.
type DepsGraphLevel ¶
type DepsGraphLevel int
const ( PkgRefs DepsGraphLevel = iota CrossPkgSymRefs SymRefs )
type Edit ¶
type Error ¶
An Error is an error at a particular source position. It may have attached errors at other positions (but those must not have secondary errors).
type ErrorList ¶
type ErrorList struct {
// contains filtered or unexported fields
}
ErrorList is a set of Errors. It is also an error itself. The zero value is an empty list, ready to use.
func (*ErrorList) Add ¶
Add adds and error to l. If the error is an Error, scanner.Error, or types.Error, it uses the position information from the error. If the error is an ErrorList or a scanner.ErrorList, it merges all errors from that list into this list. Otherwise, it adds the error with no position information. It suppresses duplicate errors (same position and message).
type File ¶
type File struct { Name string // Short path (either relative to r.dir or absolute) Text []byte Syntax *ast.File // Parsed form of Text Imports []string // Local import paths, derived from Syntax Modified bool // Modified from on-disk file (or does not exist on disk) Deleted bool // Tombstone marking a deleted File. Only Name is valid. Hash string // SHA256(Name+Text) }
File represents a source file, including both its text and parsed forms. Files are tracked by the buildCache and are deeply immutable.
type Item ¶
type ItemKind ¶
type ItemKind int
const ( ItemNotFound ItemKind ItemFile ItemDir ItemConst ItemType ItemVar ItemFunc ItemField ItemMethod ItemPos ItemPkg )
type Package ¶
type Package struct { Name string Dir string ID string PkgPath string ForTest string Files []*File // Sorted by File.Name Imports []string InCurrentModule bool Export string BuildID string ImportMap map[string]string // from local import path to package path (used for vendored packages in std) Types *types.Package TypesInfo *types.Info Sizes types.Sizes }
type Refactor ¶
type Refactor struct { Stdout io.Writer Stderr io.Writer ShowDiff bool Debug map[string]string // debugging settings // Configs is a set of build configurations to refactor. // New returns just the default build configuration, // but a caller can overwrite this. Configs Configs // contains filtered or unexported fields }
A Refactor holds the state for an active refactoring.
func (*Refactor) Apply ¶
Apply applies edits to all Snapshots, type-checks the resulting files, and creates a new set of current Snapshots. If there are any type errors in the new Snapshots, it returns an ErrorList.
func (*Refactor) MergeSnapshots ¶
MergeSnapshots combines all Snapshots. The resulting Snapshot contains only files and cannot be type-checked, but can be written out. If any Snapshots are inconsistent, it prints details to r.Stderr and returns an error.
TODO: Maybe there should be another type representing just the modified file system. Snapshots could use that internally so we can still, e.g., show diffs on errors, and this could return it directly rather than returning a weird Snapshot. That would make it easy to separate out "apply edits" from "build a new Snapshot" in apply, and here we could reuse "apply edits".
type Snapshot ¶
type Snapshot struct { Errors *ErrorList // contains filtered or unexported fields }
A Snapshot is a base set of Packages and their parsed source files, plus a set of concurrent edits to be made to those files.
func (*Snapshot) CheckImportCycle ¶
func (*Snapshot) CreateFile ¶
func (*Snapshot) DeleteFile ¶
func (*Snapshot) DepsGraph ¶
func (s *Snapshot) DepsGraph(level DepsGraphLevel) *DepsGraph