Documentation
¶
Index ¶
- func FindStmtInBody(stmt dst.Stmt, body []dst.Stmt) (int, error)
- func GenerateUniqueName(scope *types.Scope, base string) string
- func GetEnclosingFile(pos token.Pos, packageFiles []*ast.File) *ast.File
- func GetEnclosingFunction(pos token.Pos, packageFiles []*ast.File) (*ast.FuncDecl, *ast.File)
- func GetParamNameByType(funcDecl *dst.FuncDecl, paramTypes ...dst.Expr) (string, error)
- func GetStmtWithSameIndex(stmt dst.Stmt, parentBody, newBody []dst.Stmt) (dst.Stmt, error)
- func IsBasicType(typ types.Type, info types.BasicInfo) bool
- func IsNameUsed(scope *types.Scope, name string) bool
- func IsPointer(t types.Type) bool
- func IsSelectorFuncCall(stmt dst.Stmt, owner, name string) (bool, *dst.CallExpr)
- func MatchSelectorExpr(expr dst.Expr, owner, name string) bool
- func NewCallExprStmt(fun dst.Expr, args []dst.Expr) *dst.ExprStmt
- func NewSelectorExpr(owner, name string) dst.Expr
- func NodeToString(node dst.Node) string
- func ReplaceFuncDecl(old, new *dst.FuncDecl, file *dst.File) error
- func SaveFileContents(path string, newFile *dst.File) error
- func StringToNode(str string) (dst.Node, error)
- func UnderlyingType(t types.Type) types.Type
- func Unpointer(t types.Type) types.Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindStmtInBody ¶
Returns the index of the given statement within a function body, or an error if the statement is not found. The contents of the statement (but not necessarily its underlying pointers) must exactly match a statement in the provided body.
func GenerateUniqueName ¶ added in v1.2.2
Generates a unique name for a variable in the given scope by appending a number to the base name until it is unique. For example, if the base name is "x" and a variable named "x" is already defined in the scope, the next attempt will be "x1", then "x2", and so on. If the base name is not already defined, it will be returned without modification.
func GetEnclosingFile ¶
Returns the AST file containing the given position in the provided package files. Returns nil if none of the provided files contain the position.
func GetEnclosingFunction ¶
Returns the AST function declaration (and corresponding file) enclosing the given position in the provided package files. Returns nil if no function declaration is found, or if none of the provided files contain the position.
func GetParamNameByType ¶
Returns the name of the first detected parameter in the function declaration that exactly matches any of the provided parameter types. If no matching parameter is found, returns an error.
func GetStmtWithSameIndex ¶
Returns the i-th statement in the new body, where i is the index of the provided statement within its own parent body. For example, if the given statement is at index 2 in its parent body, this returns the statement at index 2 in the new body.
func IsBasicType ¶
Returns whether a Type is Basic and has the specified info. See `go/types.Basic` for more details.
func IsNameUsed ¶ added in v1.2.2
Returns whether a variable with the given name is used in the given scope, any of the scope's parents (upward), or any nested scopes (downward). This indicates whether the name is at risk of being redeclared or shadowed.
func IsSelectorFuncCall ¶
Returns a boolean indicating whether a statement is a function call expression of the form `owner.name(...)`, as well as a reference to the `dst.CallExpr` if the statement matches.
func MatchSelectorExpr ¶
Returns a boolean indicating whether a selector expression has the form `owner.name`.
func NewCallExprStmt ¶
Creates a DST call expression statement using the provided function and arguments.
func NewSelectorExpr ¶
Creates a DST selector expression of the form `owner.name`.
func NodeToString ¶
Converts a DST node to a string representation, or returns an empty string if formatting fails todo CLEANUP should return actual errors
func ReplaceFuncDecl ¶
Replace the reference to the `old` FuncDecl in its parent file with a reference to the `new` FuncDecl, without modifying either of the FuncDecls themselves. The function must be a top-level declaration in the file. Note that the contents of the functions are not compared, only their names. Returns an error if the replacement was not successful.
func SaveFileContents ¶
Saves the contents of the specified DST file to the disk using the specified path, overwriting any existing data at the specified path.
func StringToNode ¶
Parses a string (usually from JSON) into the corresponding DST expression. This function tries to parse the string as a declaration, statement, or expression in that order. TODO DST - might need to use an existing decorator here to avoid discarding the fset
func UnderlyingType ¶ added in v1.2.2
Returns the underlying type of a type, unwrapping any pointer types.
Types ¶
This section is empty.