Documentation
¶
Index ¶
- func GenerateUniqueKeyFromGoType(goType types.Type) string
- type AliasLookup
- type AliasManager
- type AliasRenderInfo
- type AnalysisResult
- type CodeEmitter
- type ConversionEngine
- type ConversionTask
- type ExecutionPlan
- type FieldInfo
- type GeneratedCode
- type GenerationResponse
- type Helper
- type ImportManager
- type MethodInfo
- type NameGenerator
- type Planner
- type SignatureInfo
- type TypeAnalyzer
- type TypeConverter
- type TypeFormatter
- type TypeInfo
- func (ti *TypeInfo) BuildQualifiedTypeName(sb *strings.Builder)
- func (ti *TypeInfo) Equals(other *TypeInfo) bool
- func (ti *TypeInfo) FQN() string
- func (ti *TypeInfo) IsNamedType() bool
- func (ti *TypeInfo) IsUltimatelyStruct() bool
- func (ti *TypeInfo) IsValid() bool
- func (ti *TypeInfo) OriginalType() types.Type
- func (ti *TypeInfo) PackageName() string
- func (ti *TypeInfo) String() string
- func (ti *TypeInfo) Type() string
- func (ti *TypeInfo) TypeString() string
- func (ti *TypeInfo) UniqueKey() string
- type TypeKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateUniqueKeyFromGoType ¶
GenerateUniqueKeyFromGoType creates a unique string key for a given Go types.Type.
Types ¶
type AliasLookup ¶
AliasLookup defines the interface for looking up type aliases.
type AliasManager ¶
type AliasManager interface {
AliasLookup
PopulateAliases()
GetAllAliases() map[string]string
GetAliasedTypes() map[string]*TypeInfo
GetAlias(info *TypeInfo) (string, bool)
IsUserDefined(uniqueKey string) bool
GetSourcePath() string
GetTargetPath() string
}
AliasManager defines the interface for creating and managing local type aliases.
type AliasRenderInfo ¶
AliasRenderInfo holds information for rendering a type alias.
type AnalysisResult ¶
type AnalysisResult struct {
TypeInfos map[string]*TypeInfo
ExistingFunctions map[string]bool
ExistingAliases map[string]string
ExecutionPlan *ExecutionPlan
}
AnalysisResult holds all the information gathered during the analysis phase and the final execution plan for the generator.
type CodeEmitter ¶
type CodeEmitter interface {
EmitHeader(buf *bytes.Buffer) error
EmitStubHeader(buf *bytes.Buffer) error
EmitImports(buf *bytes.Buffer, imports map[string]string) error
EmitAliases(buf *bytes.Buffer, aliases []*AliasRenderInfo) error
EmitConversions(buf *bytes.Buffer, funcs []string) error
EmitHelpers(buf *bytes.Buffer, helpers []Helper) error
}
CodeEmitter defines the interface for writing the various sections of the final generated Go file.
type ConversionEngine ¶
type ConversionEngine interface {
GenerateConversionFunction(source, target *TypeInfo, rule *config.ConversionRule) (*GeneratedCode, []*ConversionTask, error)
GenerateSliceConversion(source, target *TypeInfo) (*GeneratedCode, []*ConversionTask, error)
GetStubsToGenerate() map[string]*ConversionTask
}
ConversionEngine defines the interface for the component that generates the body of conversion functions.
type ConversionTask ¶
type ConversionTask struct {
Source *TypeInfo
Target *TypeInfo
Rule *config.ConversionRule
}
ConversionTask represents a task for the code generator to create a conversion function.
type ExecutionPlan ¶
type ExecutionPlan struct {
FinalConfig *config.Config
ActiveRules []*config.ConversionRule
}
ExecutionPlan contains the finalized configuration and rules for generation.
type GeneratedCode ¶
GeneratedCode holds information about a generated code snippet.
type GenerationResponse ¶
type GenerationResponse struct {
GeneratedCode []byte
CustomStubs []byte
RequiredPackages []string
}
GenerationResponse represents the final output of a code generation task.
type Helper ¶
type Helper struct {
Name string
SourceType string
TargetType string
Body string
Dependencies []string
}
Helper represents a built-in conversion function.
type ImportManager ¶
type ImportManager interface {
Add(pkgPath string) string
AddAs(pkgPath, alias string) string
GetAlias(pkgPath string) (string, bool)
GetAllImports() map[string]string
PackageName(pkg *types.Package) string
}
ImportManager defines the interface for managing and generating import statements.
type MethodInfo ¶
type MethodInfo struct {
Name string
Signature *SignatureInfo
}
MethodInfo represents a single method of a type.
type NameGenerator ¶
type NameGenerator interface {
ConversionFunctionName(source, target *TypeInfo) string
FieldConversionFunctionName(sourceParent, targetParent *TypeInfo, sourceField, targetField *FieldInfo) string
}
NameGenerator defines the interface for generating correct Go syntax for names.
type Planner ¶
type Planner interface {
Plan(initialConfig *config.Config, typeInfos map[string]*TypeInfo) *ExecutionPlan
}
Planner defines the interface for the component that creates the final execution plan.
type SignatureInfo ¶
SignatureInfo represents the detailed information of a function or method signature.
type TypeAnalyzer ¶
type TypeAnalyzer interface {
Analyze(sourceDir string) (*AnalysisResult, error)
}
TypeAnalyzer defines the interface for the type analysis component.
type TypeConverter ¶
type TypeConverter interface {
GetConcreteType(info *TypeInfo) *TypeInfo
GetEffectiveType(info *TypeInfo) *TypeInfo
GetElementType(info *TypeInfo) *TypeInfo
GetSliceElementType(info *TypeInfo) *TypeInfo
GetKeyType(info *TypeInfo) *TypeInfo
IsUltimatelyPrimitive(info *TypeInfo) bool
IsPurelyPrimitiveOrCompositeOfPrimitives(info *TypeInfo) bool
}
TypeConverter defines the interface for utility functions that inspect TypeInfo objects.
type TypeFormatter ¶
type TypeInfo ¶
type TypeInfo struct {
Name string
ImportPath string
Kind TypeKind
ArrayLen int
Underlying *TypeInfo
KeyType *TypeInfo
IsAlias bool
Fields []*FieldInfo
Methods []*MethodInfo
Original types.Object
}
TypeInfo represents the detailed information of a resolved Go type.
func GetElementType ¶
GetElementType returns the ultimate element type of pointers, slices, and arrays.
func (*TypeInfo) BuildQualifiedTypeName ¶
BuildQualifiedTypeName builds the qualified type name with package prefix if needed.
func (*TypeInfo) IsNamedType ¶
IsNamedType returns true if the type has a name and an import path, and is not a primitive.
func (*TypeInfo) IsUltimatelyStruct ¶
IsUltimatelyStruct checks if the type is a struct or a named type whose underlying type is a struct.
func (*TypeInfo) OriginalType ¶
func (*TypeInfo) PackageName ¶
PackageName returns the package name of the type.
func (*TypeInfo) TypeString ¶
TypeString reconstructs the Go type string from the TypeInfo, suitable for code generation.