Documentation ¶
Index ¶
- func GetFuncGenericTypeParamsMap(funcDecl *ast.FuncDecl) map[string]ast.Expr
- func GetGenericFuncTypeParamsMap(funcType *ast.FuncType) map[string]ast.Expr
- func GetGenericTypeParamsMap(fields *ast.FieldList) map[string]ast.Expr
- type MakeNameFunction
- type NameTypeElement
- type NameTypeElements
- func ExtractNameTypeElements(fields []*ast.Field, nameFunc MakeNameFunction, source []byte, ...) NameTypeElements
- func GetSimpleArgElements(fields []*ast.Field, sourceCode []byte) NameTypeElements
- func GetSimpleResElements(fields []*ast.Field, sourceCode []byte) NameTypeElements
- func NewNameTypeElements(fieldList *ast.FieldList, nameFunc MakeNameFunction, source []byte, ...) NameTypeElements
- func NewPrefixedNameTypeElements(fieldList *ast.FieldList, prefix string, sourceCode []byte, pkgName string, ...) NameTypeElements
- func (elements NameTypeElements) FormatAddressableNames() StatementParts
- func (elements NameTypeElements) FormatNamesWithKinds() StatementParts
- func (elements NameTypeElements) GenerateFunctionParams() StatementParts
- func (elements NameTypeElements) GenerateVarDefinitions() StatementLines
- func (elements NameTypeElements) GroupVarsByKindToLines() StatementLines
- func (elements NameTypeElements) Kinds() []string
- func (elements NameTypeElements) Names() StatementParts
- type StatementLines
- type StatementParts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFuncGenericTypeParamsMap ¶
GetFuncGenericTypeParamsMap extracts a map of custom generic type parameter names and their associated types from a function declaration's type parameters. GetFuncGenericTypeParamsMap 从函数声明 (FuncDecl) 的泛型类型参数列表中提取自定义泛型类型参数名称及其关联的类型,返回一个以名称为键、类型表达式 (ast.Expr) 为值的映射。
func GetGenericFuncTypeParamsMap ¶
GetGenericFuncTypeParamsMap extracts a map of custom generic type parameter names and their associated types from a function type's type parameters. GetGenericFuncTypeParamsMap 从函数类型 (FuncType) 的泛型类型参数列表中提取自定义泛型类型参数名称及其关联的类型,返回一个以名称为键、类型表达式 (ast.Expr) 为值的映射。
func GetGenericTypeParamsMap ¶
GetGenericTypeParamsMap extracts a map of custom generic type parameter names and their associated types from a type parameter field list. GetGenericTypeParamsMap 从泛型类型参数字段列表 (FieldList) 中提取自定义泛型类型参数名称及其关联的类型,返回一个以名称为键、类型表达式 (ast.Expr) 为值的映射。
Types ¶
type MakeNameFunction ¶
MakeNameFunction generates a name for a parameter or return value. MakeNameFunction 用于为参数或返回值生成名称。
func MakePrefixedNameFunction ¶
func MakePrefixedNameFunction(prefix string) MakeNameFunction
MakePrefixedNameFunction returns a function that generates unique names with a prefix and index. MakePrefixedNameFunction 返回一个通过前缀和序号生成唯一名称的函数。
func SimpleMakeNameFunction ¶
func SimpleMakeNameFunction(prefix string) MakeNameFunction
SimpleMakeNameFunction returns a function that generates names with a specified prefix, handling both normal and error cases. SimpleMakeNameFunction 返回一个函数,该函数生成带有指定前缀的名称,处理正常和错误的情况。
type NameTypeElement ¶
type NameTypeElement struct { Name string // Field name / 字段名称 Kind string // Type description (e.g., int, string, A, utils.A, *B, *pkg.B) / 类型描述 (例如: int, string, A, utils.A, *B, *pkg.B) Type ast.Expr // Go's internal type representation / Go 的内部类型表示 IsEllipsis bool // Whether the type is a variadic (e.g., ...int or ...string) / 是否是变参类型 (例如: ...int 或 ...string) }
NameTypeElement represents a single element with a name, type, and associated information. NameTypeElement 代表一个包含名称、类型和相关信息的元素
func NewNameTypeElement ¶
func NewNameTypeElement( field *ast.Field, paramName string, paramType string, isEllipsis bool, packageName string, genericTypeParams map[string]ast.Expr, ) *NameTypeElement
NewNameTypeElement creates a new NameTypeElement by parsing the source code for parameter/return information and normalizing the data for further code generation. NewNameTypeElement 通过解析源代码中的参数/返回信息并规范化数据来创建一个新的 NameTypeElement,以供进一步的代码生成。
func (*NameTypeElement) AdjustTypeWithPackage ¶
func (element *NameTypeElement) AdjustTypeWithPackage( packageName string, genericTypeParams map[string]ast.Expr, )
AdjustTypeWithPackage adjusts the type to include the package name if needed (for external types). AdjustTypeWithPackage 如果需要(对于外部类型),将类型调整为包含包名。
type NameTypeElements ¶
type NameTypeElements []*NameTypeElement
NameTypeElements is a collection of NameTypeElement. NameTypeElements 是 NameTypeElement 的集合。
func ExtractNameTypeElements ¶
func ExtractNameTypeElements( fields []*ast.Field, nameFunc MakeNameFunction, source []byte, packageName string, genericTypeParams map[string]ast.Expr, ) NameTypeElements
ExtractNameTypeElements extracts NameTypeElements from the AST fields. ExtractNameTypeElements 从 AST 字段中提取 NameTypeElements。
func GetSimpleArgElements ¶
func GetSimpleArgElements(fields []*ast.Field, sourceCode []byte) NameTypeElements
GetSimpleArgElements extracts NameTypeElements from the given fields with an "arg" prefix for names. GetSimpleArgElements 从给定字段中提取 NameTypeElements,并为名称添加 "arg" 前缀。
func GetSimpleResElements ¶
func GetSimpleResElements(fields []*ast.Field, sourceCode []byte) NameTypeElements
GetSimpleResElements extracts NameTypeElements from the given fields with a "res" prefix for names. GetSimpleResElements 从给定字段中提取 NameTypeElements,并为名称添加 "res" 前缀。
func NewNameTypeElements ¶
func NewNameTypeElements( fieldList *ast.FieldList, nameFunc MakeNameFunction, source []byte, packageName string, genericTypeParams map[string]ast.Expr, ) NameTypeElements
NewNameTypeElements creates a list of NameTypeElements based on AST field list. NewNameTypeElements 根据 AST 字段列表创建 NameTypeElements 的列表。
func NewPrefixedNameTypeElements ¶
func NewPrefixedNameTypeElements( fieldList *ast.FieldList, prefix string, sourceCode []byte, pkgName string, genericTypeParams map[string]ast.Expr, ) NameTypeElements
NewPrefixedNameTypeElements creates a NameTypeElements instance using a naming function that adds a prefix and an index. NewPrefixedNameTypeElements 使用添加前缀和序号的命名函数创建一个 NameTypeElements 实例。
func (NameTypeElements) FormatAddressableNames ¶
func (elements NameTypeElements) FormatAddressableNames() StatementParts
FormatAddressableNames returns the names prefixed with "&" (addressable names). FormatAddressableNames 返回带有 "&" 前缀的名称(可寻址名称)。
func (NameTypeElements) FormatNamesWithKinds ¶
func (elements NameTypeElements) FormatNamesWithKinds() StatementParts
FormatNamesWithKinds returns the names with their types (e.g., "a int"). FormatNamesWithKinds 返回名称及其类型(例如:"a int")。
func (NameTypeElements) GenerateFunctionParams ¶
func (elements NameTypeElements) GenerateFunctionParams() StatementParts
GenerateFunctionParams generates the function parameters list. GenerateFunctionParams 生成函数参数列表。
func (NameTypeElements) GenerateVarDefinitions ¶
func (elements NameTypeElements) GenerateVarDefinitions() StatementLines
GenerateVarDefinitions generates variable definitions (e.g., "var a int"). GenerateVarDefinitions 生成变量定义(例如:"var a int")。
func (NameTypeElements) GroupVarsByKindToLines ¶
func (elements NameTypeElements) GroupVarsByKindToLines() StatementLines
GroupVarsByKindToLines groups variables by their type and generates the corresponding definition lines. GroupVarsByKindToLines 按类型分组变量,并生成相应的定义行。
func (NameTypeElements) Kinds ¶
func (elements NameTypeElements) Kinds() []string
Kinds returns a list of types of the elements. Kinds 返回元素类型的列表。
func (NameTypeElements) Names ¶
func (elements NameTypeElements) Names() StatementParts
Names returns a list of names of the elements. Names 返回元素名称的列表。
type StatementLines ¶
type StatementLines []string
StatementLines represents a list of strings that are usually separated by newline characters. StatementLines 通常用于表示一个以换行符分隔的字符串列表,常见于赋值语句、返回语句或函数调用语句。
func (StatementLines) MergeLines ¶
func (stmts StatementLines) MergeLines() string
MergeLines joins the elements in StatementLines with a newline character, and returns the resulting string. MergeLines 将 StatementLines 中的元素用换行符连接,并返回结果字符串。
type StatementParts ¶
type StatementParts []string
StatementParts represents a list of strings that are usually separated by commas. StatementParts 通常用于表示一个以逗号分隔的字符串列表,常见于参数列表或返回值列表。
func (StatementParts) MergeParts ¶
func (stmts StatementParts) MergeParts() string
MergeParts joins the elements in StatementParts with a comma and a space, and returns the resulting string. MergeParts 将 StatementParts 中的元素用逗号和空格连接,并返回结果字符串。