model

package
v0.0.0-...-8cb7f69 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateUniqueKeyFromGoType

func GenerateUniqueKeyFromGoType(goType types.Type) string

GenerateUniqueKeyFromGoType creates a unique string key for a given Go types.Type.

Types

type AliasLookup

type AliasLookup interface {
	LookupAlias(uniqueKey string) (string, bool)
}

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

type AliasRenderInfo struct {
	AliasName        string
	OriginalTypeName string
}

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 FieldInfo

type FieldInfo struct {
	Name       string
	Type       *TypeInfo
	Tag        string
	IsEmbedded bool
}

FieldInfo represents a single field within a struct.

func (*FieldInfo) Equals

func (fi *FieldInfo) Equals(other *FieldInfo) bool

Equals checks if two FieldInfo objects are equal.

type GeneratedCode

type GeneratedCode struct {
	FunctionBody    string
	RequiredHelpers []Helper
}

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

type SignatureInfo struct {
	Params     []*TypeInfo
	Results    []*TypeInfo
	IsVariadic bool
}

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 TypeFormatter interface {
	Format(info *TypeInfo) string
	FormatWithoutAlias(info *TypeInfo) string
}

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

func GetElementType(info *TypeInfo) *TypeInfo

GetElementType returns the ultimate element type of pointers, slices, and arrays.

func (*TypeInfo) BuildQualifiedTypeName

func (ti *TypeInfo) BuildQualifiedTypeName(sb *strings.Builder)

BuildQualifiedTypeName builds the qualified type name with package prefix if needed.

func (*TypeInfo) Equals

func (ti *TypeInfo) Equals(other *TypeInfo) bool

Equals checks if two TypeInfo objects represent the same type.

func (*TypeInfo) FQN

func (ti *TypeInfo) FQN() string

FQN returns the Fully Qualified Name for named types.

func (*TypeInfo) IsNamedType

func (ti *TypeInfo) IsNamedType() bool

IsNamedType returns true if the type has a name and an import path, and is not a primitive.

func (*TypeInfo) IsUltimatelyStruct

func (ti *TypeInfo) IsUltimatelyStruct() bool

IsUltimatelyStruct checks if the type is a struct or a named type whose underlying type is a struct.

func (*TypeInfo) IsValid

func (ti *TypeInfo) IsValid() bool

IsValid checks if the TypeInfo contains valid data.

func (*TypeInfo) OriginalType

func (ti *TypeInfo) OriginalType() types.Type

func (*TypeInfo) PackageName

func (ti *TypeInfo) PackageName() string

PackageName returns the package name of the type.

func (*TypeInfo) String

func (ti *TypeInfo) String() string

String returns a string representation of the type.

func (*TypeInfo) Type

func (ti *TypeInfo) Type() string

func (*TypeInfo) TypeString

func (ti *TypeInfo) TypeString() string

TypeString reconstructs the Go type string from the TypeInfo, suitable for code generation.

func (*TypeInfo) UniqueKey

func (ti *TypeInfo) UniqueKey() string

UniqueKey returns a string that uniquely identifies the type.

type TypeKind

type TypeKind int

TypeKind defines the kind of a Go type.

const (
	Unknown TypeKind = iota
	Primitive
	Struct
	Interface
	Map
	Chan
	Func
	Slice
	Array
	Pointer
	Named // For any type introduced with the 'type' keyword
)

Constants for the different kinds of types.

func (TypeKind) String

func (k TypeKind) String() string

Jump to

Keyboard shortcuts

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