Documentation
¶
Overview ¶
Package astutil provides AST utilities and shared types for Go source analysis.
Index ¶
- func FindAssignments(node ast.Node) []*ast.AssignStmt
- func FindCallExprs(node ast.Node) []*ast.CallExpr
- func FindFuncDecls(file *ast.File) []*ast.FuncDecl
- func FindMethodCalls(node ast.Node, methodName string) []*ast.CallExpr
- func FindVarDecls(node ast.Node) []*ast.GenDecl
- func GetCallArg(call *ast.CallExpr, index int) ast.Expr
- func GetCallName(call *ast.CallExpr) string
- func GetLineNumber(fset *token.FileSet, node ast.Node) int
- func GetReceiverName(fn *ast.FuncDecl) string
- func GetReceiverType(fn *ast.FuncDecl) string
- func GetStringSlice(expr ast.Expr) []string
- func GetStringValue(expr ast.Expr) string
- func IsMethodCall(call *ast.CallExpr, receiverName, methodName string) bool
- type ParsedSource
- type SourceLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAssignments ¶
func FindAssignments(node ast.Node) []*ast.AssignStmt
FindAssignments returns all assignment statements in a node.
func FindCallExprs ¶
FindCallExprs returns all call expressions in a node.
func FindFuncDecls ¶
FindFuncDecls returns all function declarations in a file.
func FindMethodCalls ¶
FindMethodCalls finds all method calls matching a pattern in a node.
func FindVarDecls ¶
FindVarDecls returns all variable declarations in a node.
func GetCallArg ¶
GetCallArg gets a specific argument from a function call (0-indexed).
func GetCallName ¶
GetCallName returns the name of a function call (e.g., "r.GET" or "http.HandleFunc").
func GetLineNumber ¶
GetLineNumber returns the line number for an AST node.
func GetReceiverName ¶
GetReceiverName returns the receiver variable name for a method.
func GetReceiverType ¶
GetReceiverType returns the receiver type name for a method.
func GetStringSlice ¶
GetStringSlice extracts a []string from an array/slice literal.
func GetStringValue ¶
GetStringValue extracts the string value from an expression.
Types ¶
type ParsedSource ¶
type ParsedSource struct {
// FilePath is the path to the source file.
FilePath string
// FileSet is the token file set.
FileSet *token.FileSet
// AST is the parsed AST.
AST *ast.File
// Content is the raw source content.
Content string
// Imports maps import paths to their aliases.
Imports map[string]string
}
ParsedSource represents a parsed Go source file.
func (*ParsedSource) GetImportAlias ¶
func (s *ParsedSource) GetImportAlias(importPath string) string
GetImportAlias returns the alias for an import path, or empty string if not found.
func (*ParsedSource) HasImport ¶
func (s *ParsedSource) HasImport(importPath string) bool
HasImport checks if the source has a specific import path.
func (*ParsedSource) HasImportPrefix ¶
func (s *ParsedSource) HasImportPrefix(prefix string) bool
HasImportPrefix checks if the source has any import with the given prefix.
type SourceLoader ¶
type SourceLoader struct {
// contains filtered or unexported fields
}
SourceLoader handles loading and parsing Go source files.
func NewSourceLoader ¶
func NewSourceLoader() *SourceLoader
NewSourceLoader creates a new SourceLoader.
func (*SourceLoader) ParseContent ¶
func (l *SourceLoader) ParseContent(path, content string) (*ParsedSource, error)
ParseContent parses Go source code from a string.
func (*SourceLoader) ParseFile ¶
func (l *SourceLoader) ParseFile(path string) (*ParsedSource, error)
ParseFile parses a Go source file.
func (*SourceLoader) TryParseFile ¶
func (l *SourceLoader) TryParseFile(path string) (*ParsedSource, string)
TryParseFile attempts to parse a file, returning nil and error string on failure.