Documentation
¶
Index ¶
- func FindStmtInBody(stmt ast.Stmt, body []ast.Stmt) (int, error)
- 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 *ast.FuncDecl, paramTypes ...ast.Expr) (string, error)
- func GetStmtWithSameIndex(stmt ast.Stmt, parentBody, newBody []ast.Stmt) (ast.Stmt, error)
- func IsBasicType(typ types.Type, info types.BasicInfo) bool
- func IsSelectorFuncCall(stmt ast.Stmt, owner, name string) (bool, *ast.CallExpr)
- func MatchSelectorExpr(expr ast.Expr, owner, name string) bool
- func NewCallExprStmt(fun ast.Expr, args []ast.Expr) *ast.ExprStmt
- func NewSelectorExpr(owner, name string) ast.Expr
- func NodeToString(node ast.Node, fset *token.FileSet) string
- func ReplaceFuncDecl(old, new *ast.FuncDecl, file *ast.File) error
- func SaveFileContents(path string, newFile *ast.File, fset *token.FileSet) error
- func StringToNode(str string) (ast.Node, error)
- 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 GetEnclosingFile ¶
Returns the 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 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 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 `ast.CallExpr` if the statement matches.
func MatchSelectorExpr ¶
Returns a boolean indicating whether a selector expression has the form `owner.name`.
func NewCallExprStmt ¶
Creates a call expression statement using the provided function and arguments.
func NewSelectorExpr ¶
Creates a selector expression of the form `owner.name`.
func NodeToString ¶
Converts an AST node to a string representation using `go/printer`, or return an error 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 AST file to the disk using the specified path, after formatting the AST data with `go/format` using the provided FileSet. Any existing file at the specified path will be overwritten.
func StringToNode ¶
Parses a string (usually from JSON) into the corresponding AST expression. This function tries to parse the string as a declaration, statement, or expression in that order.
Types ¶
This section is empty.