ast

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCaller

func GetCaller(n *ast.CallExpr) (string, bool)

GetCaller 获取调用者

func GetExprTypeName

func GetExprTypeName(expr ast.Expr) string

GetExprTypeName 返回带有指针指示的类型名称字符串

func GetFunctionChain

func GetFunctionChain(n *ast.CallExpr) string

GetFunctionChain 获取完整的函数调用链

func GetPackageImportPaths

func GetPackageImportPaths(f *ast.File) map[string]string

GetPackageImportPaths 获取包导入路径

func GetReceiverTypeName

func GetReceiverTypeName(fn *ast.FuncDecl, ignorePointer ...bool) string

GetReceiverTypeName 获取函数的receiver类型, 如果ignorePointer为true, 则去除前面的*号 e,g: (*Person) hello() {}, 传入hello的ast.FuncDecl, 返回Person

func GetStructInfo

func GetStructInfo(n *ast.GenDecl) (string, *ast.StructType, bool)

GetStructInfo 获取结构信息

func GetVarDeclsFromFile

func GetVarDeclsFromFile(file *ast.File) map[string]*ast.ValueSpec

GetVarDeclsFromFile 查找变量声明

func GetVarDeclsFromFunc

func GetVarDeclsFromFunc(body *ast.BlockStmt) map[string]*ast.ValueSpec

GetVarDeclsFromFunc 从函数体中提取所有 *ast.ValueSpec 提取函数体内所有ValueSpec(包括转换短声明)

func GetVarTypes

func GetVarTypes(node ast.Node) map[string]string

GetVarTypes 收集所有变量声明中的类型信息

func InspectPackage

func InspectPackage(srcDir string, excludeDirs []string) (map[string]*Package, error)

InspectPackage 从源代码目录中获取包的信息, 包相对路径=>包信息

func MatchCall

func MatchCall(n *ast.CallExpr, signature *CallSignature, imports map[string]string) bool

func MatchFunction

func MatchFunction(fn *ast.FuncDecl, signature *FunctionSignature) bool

func ParseFunctionCallChain

func ParseFunctionCallChain(n *ast.CallExpr) []string

ParseFunctionCallChain 递归解析链式函数调用,最近的Ident.Name作为包名,最先调用的函数在slice的最前面

func ResolveVarType

func ResolveVarType(expr ast.Expr) string

ResolveVarType 解析表达式的实际类型名(如 v2_captcha)

Types

type ASTUtils

type ASTUtils interface {
	InspectFunction(srcPath string, fnParams, fnResults []string, annotationPrefix string) ([]*Function, error) // 从源代码目录中获取fnParams和fnResults匹配的函数的信息,并解析函数对应的注解
	InspectPackage(rootDir string, excludeDirs []string) (map[string]*Package, error)                           // 从源代码中获取包的相对路径到包信息的map
}

type Annotation

type Annotation struct {
	Name  string
	Value string
}

Annotation 注释中的注解

type CallSignature

type CallSignature struct {
	FunctionChain      string         // 必传
	Package            string         // 可选
	ArgCount           int            // 可选, -1不去检查
	ArgIndex2Signature map[int]string // 可选, nil不去检查
}

type Function

type Function struct {
	Receiver      string
	Function      string
	Annotations   map[string]*Annotation // annotationName->*AstAnnotation
	PlainComments []string               // 去除注解后的注释
}

func InspectFunction

func InspectFunction(srcPath string, fnParams, fnResults []string, annotationPrefix string) ([]*Function, error)

InspectFunction 从源代码目录中获取fnParams和fnResults匹配的函数的信息,并解析函数对应的注解 handlerName=>*moduleInfo

type FunctionSignature

type FunctionSignature struct {
	NamePattern *regexp.Regexp
	Params      []string
	Results     []string
}

type Package

type Package struct {
	Name    string
	Files   map[string]*ast.File
	FileSet *token.FileSet
}

Jump to

Keyboard shortcuts

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