Documentation
¶
Overview ¶
Package refactor provides operators to compute common textual edits for refactoring tools.
This package should not use features of the analysis API other than analysis.TextEdit.
Index ¶
- func AddImport(info *types.Info, file *ast.File, preferredName, pkgpath, member string, ...) (prefix string, edits []analysis.TextEdit)
- func DeleteDecl(tokFile *token.File, curDecl inspector.Cursor) []analysis.TextEdit
- func DeleteSpec(tokFile *token.File, curSpec inspector.Cursor) []analysis.TextEdit
- func DeleteStmt(tokFile *token.File, curStmt inspector.Cursor) []analysis.TextEdit
- func DeleteVar(tokFile *token.File, info *types.Info, curId inspector.Cursor) []analysis.TextEdit
- func FreshName(scope *types.Scope, pos token.Pos, preferred string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddImport ¶
func AddImport(info *types.Info, file *ast.File, preferredName, pkgpath, member string, pos token.Pos) (prefix string, edits []analysis.TextEdit)
AddImport returns the prefix (either "pkg." or "") that should be used to qualify references to the desired symbol (member) imported from the specified package, plus any necessary edits to the file's import declaration to add a new import.
If the import already exists, and is accessible at pos, AddImport returns the existing name and no edits. (If the existing import is a dot import, the prefix is "".)
Otherwise, it adds a new import, using a local name derived from the preferred name. To request a blank import, use a preferredName of "_", and discard the prefix result; member is ignored in this case.
AddImport accepts the caller's implicit claim that the imported package declares member.
AddImport does not mutate its arguments.
func DeleteDecl ¶
DeleteDecl returns edits to delete the ast.Decl identified by curDecl.
TODO(adonovan): add test suite.
func DeleteSpec ¶
DeleteSpec returns edits to delete the ValueSpec identified by curSpec.
TODO(adonovan): add test suite. Test for consts as well.
func DeleteStmt ¶
DeleteStmt returns the edits to remove the ast.Stmt identified by curStmt, if it is contained within a BlockStmt, CaseClause, CommClause, or is the STMT in switch STMT; ... {...}. It returns nil otherwise.
func DeleteVar ¶
DeleteVar returns edits to delete the declaration of a variable whose defining identifier is curId.
It handles variants including: - GenDecl > ValueSpec versus AssignStmt; - RHS expression has effects, or not; - entire statement/declaration may be eliminated; and removes associated comments.
If it cannot make the necessary edits, such as for a function parameter or result, it returns nil.
Types ¶
This section is empty.