sym

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

The sym package provides a way to iterate over and change the symbols in Go source files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	ChangedFiles map[string]*ast.File

	// FileSet holds the fileset used when importing packages.
	FileSet *token.FileSet

	// Logf is used to print warning messages.
	// If it is nil, no warning messages will be printed.
	Logf func(pos token.Pos, f string, a ...interface{})
	// contains filtered or unexported fields
}

Context holds the context for IterateSyms.

func NewContext

func NewContext() *Context

func (*Context) Import

func (ctxt *Context) Import(path, srcDir string) *ast.Package

Import imports and parses the package with the given path. It returns nil if it fails.

func (*Context) IterateSyms

func (ctxt *Context) IterateSyms(f *ast.File, visitf func(info *Info) bool)

IterateSyms calls visitf for each identifier in the given file. If visitf returns false, the iteration stops. If visitf changes info.Ident.Name, the file is added to ctxt.ChangedFiles.

func (*Context) WriteFiles

func (ctxt *Context) WriteFiles(files map[string]*ast.File) error

WriteFiles writes the given files, formatted as with gofmt.

type Info

type Info struct {
	Pos      token.Pos   // position of symbol.
	Expr     ast.Expr    // expression for symbol (*ast.Ident or *ast.SelectorExpr)
	Ident    *ast.Ident  // identifier in parse tree (changing ident.Name changes the parse tree)
	ExprType types.Type  // type of expression.
	ReferPos token.Pos   // position of referred-to symbol.
	ReferObj *ast.Object // object referred to.
	Local    bool        // whether referred-to object is function-local.
	Universe bool        // whether referred-to object is in universe.
}

Info holds information about an identifier.

Jump to

Keyboard shortcuts

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