Documentation
¶
Overview ¶
Package generator provides enum code generation functionality.
Index ¶
- Constants
- Variables
- func GetValueName(v *genkit.EnumValue, typeName string) string
- func TrimPrefix(name, prefix string) string
- type GenerateOption
- func (x GenerateOption) IsValid() bool
- func (x GenerateOption) MarshalJSON() ([]byte, error)
- func (x GenerateOption) MarshalText() ([]byte, error)
- func (x *GenerateOption) Scan(src any) error
- func (x GenerateOption) String() string
- func (x *GenerateOption) UnmarshalJSON(data []byte) error
- func (x *GenerateOption) UnmarshalText(data []byte) error
- func (x GenerateOption) Value() (driver.Value, error)
- type Generator
- func (eg *Generator) Config() genkit.ToolConfig
- func (eg *Generator) FindEnums(pkg *genkit.Package) []*genkit.Enum
- func (eg *Generator) GenerateEnum(g *genkit.GeneratedFile, enum *genkit.Enum) error
- func (eg *Generator) GenerateEnumTest(g *genkit.GeneratedFile, enum *genkit.Enum)
- func (eg *Generator) Name() string
- func (eg *Generator) ProcessPackage(gen *genkit.Generator, pkg *genkit.Package) error
- func (eg *Generator) Rules() []genkit.Rule
- func (eg *Generator) Run(gen *genkit.Generator, log *genkit.Logger) error
- func (eg *Generator) Validate(gen *genkit.Generator, _ *genkit.Logger) []genkit.Diagnostic
- func (eg *Generator) WriteHeader(g *genkit.GeneratedFile, pkgName string)
- func (eg *Generator) WriteTestHeader(g *genkit.GeneratedFile, pkgName string)
- type UnderlyingType
Constants ¶
const ( ErrCodeUnsupportedType = "E001" ErrCodeNameOnStringType = "E002" ErrCodeDuplicateName = "E003" ErrCodeNameMissingParam = "E004" )
Error codes for diagnostics.
const ToolName = "enumgen"
ToolName is the name of this tool, used in annotations.
Variables ¶
var GenerateOptionEnums = _GenerateOptionEnums{ // contains filtered or unexported fields }
GenerateOptionEnums is the enum helper for GenerateOption.
var UnderlyingTypeEnums = _UnderlyingTypeEnums{ // contains filtered or unexported fields }
UnderlyingTypeEnums is the enum helper for UnderlyingType.
Functions ¶
func GetValueName ¶
GetValueName returns the display name for an enum value (exported for testing). It checks for enumgen:@name annotation first, otherwise uses TrimPrefix.
func TrimPrefix ¶
TrimPrefix removes the type name prefix from an enum value name. Unlike strings.TrimPrefix, it returns the original name if the result would be empty. Example: TrimPrefix("StatusActive", "Status") -> "Active"
TrimPrefix("Status", "Status") -> "Status" (not "")
Types ¶
type GenerateOption ¶
type GenerateOption int
GenerateOption represents an enum generation option. enumgen:@enum(string, json, text, sql)
const ( // enumgen:@name(string) GenerateOptionString GenerateOption = iota + 1 // enumgen:@name(json) GenerateOptionJSON // enumgen:@name(text) GenerateOptionText // enumgen:@name(sql) GenerateOptionSQL )
func (GenerateOption) IsValid ¶
func (x GenerateOption) IsValid() bool
IsValid reports whether x is a valid GenerateOption.
func (GenerateOption) MarshalJSON ¶
func (x GenerateOption) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (GenerateOption) MarshalText ¶
func (x GenerateOption) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (*GenerateOption) Scan ¶
func (x *GenerateOption) Scan(src any) error
Scan implements sql.Scanner.
func (GenerateOption) String ¶
func (x GenerateOption) String() string
String returns the string representation of GenerateOption.
func (*GenerateOption) UnmarshalJSON ¶
func (x *GenerateOption) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (*GenerateOption) UnmarshalText ¶
func (x *GenerateOption) UnmarshalText(data []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Generator ¶
type Generator struct{}
Generator generates enum helper methods.
func (*Generator) Config ¶ added in v0.2.0
func (eg *Generator) Config() genkit.ToolConfig
Config returns the tool configuration for VSCode extension integration.
func (*Generator) GenerateEnum ¶
GenerateEnum generates helper code for a single enum.
func (*Generator) GenerateEnumTest ¶ added in v0.3.1
func (eg *Generator) GenerateEnumTest(g *genkit.GeneratedFile, enum *genkit.Enum)
GenerateEnumTest generates table-driven tests for a single enum.
func (*Generator) ProcessPackage ¶
ProcessPackage processes a package and generates enum helpers.
func (*Generator) Rules ¶ added in v0.3.0
Rules implements genkit.RuleTool. Returns AI-friendly documentation for enumgen.
func (*Generator) Validate ¶ added in v0.2.1
Validate implements genkit.ValidatableTool. It checks for errors without generating files, returning diagnostics for IDE integration.
func (*Generator) WriteHeader ¶
func (eg *Generator) WriteHeader(g *genkit.GeneratedFile, pkgName string)
WriteHeader writes the file header.
func (*Generator) WriteTestHeader ¶ added in v0.3.1
func (eg *Generator) WriteTestHeader(g *genkit.GeneratedFile, pkgName string)
WriteTestHeader writes the test file header.
type UnderlyingType ¶ added in v0.2.1
type UnderlyingType string
UnderlyingType represents supported underlying types for enums. enumgen:@enum(string)
const ( UnderlyingTypeInt UnderlyingType = "int" UnderlyingTypeInt8 UnderlyingType = "int8" UnderlyingTypeInt16 UnderlyingType = "int16" UnderlyingTypeInt32 UnderlyingType = "int32" UnderlyingTypeInt64 UnderlyingType = "int64" UnderlyingTypeUint UnderlyingType = "uint" UnderlyingTypeUint8 UnderlyingType = "uint8" UnderlyingTypeUint16 UnderlyingType = "uint16" UnderlyingTypeUint32 UnderlyingType = "uint32" UnderlyingTypeUint64 UnderlyingType = "uint64" UnderlyingTypeString UnderlyingType = "string" )
func (UnderlyingType) IsValid ¶ added in v0.2.1
func (x UnderlyingType) IsValid() bool
IsValid reports whether x is a valid UnderlyingType.
func (UnderlyingType) String ¶ added in v0.2.1
func (x UnderlyingType) String() string
String returns the string representation of UnderlyingType.