generator

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package generator provides enum code generation functionality.

Index

Constants

View Source
const (
	ErrCodeUnsupportedType  = "E001"
	ErrCodeNameOnStringType = "E002"
	ErrCodeDuplicateName    = "E003"
	ErrCodeNameMissingParam = "E004"
)

Error codes for diagnostics.

View Source
const ToolName = "enumgen"

ToolName is the name of this tool, used in annotations.

Variables

View Source
var GenerateOptionEnums = _GenerateOptionEnums{
	// contains filtered or unexported fields
}

GenerateOptionEnums is the enum helper for GenerateOption.

View Source
var UnderlyingTypeEnums = _UnderlyingTypeEnums{
	// contains filtered or unexported fields
}

UnderlyingTypeEnums is the enum helper for UnderlyingType.

Functions

func GetValueName

func GetValueName(v *genkit.EnumValue, typeName string) string

GetValueName returns the display name for an enum value (exported for testing). It checks for enumgen:@name annotation first, otherwise uses TrimPrefix.

func TrimPrefix

func TrimPrefix(name, prefix string) string

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.

func (GenerateOption) Value

func (x GenerateOption) Value() (driver.Value, error)

Value implements driver.Valuer.

type Generator

type Generator struct{}

Generator generates enum helper methods.

func New

func New() *Generator

New creates a new Generator.

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) FindEnums

func (eg *Generator) FindEnums(pkg *genkit.Package) []*genkit.Enum

FindEnums finds all enums with enumgen:@enum annotation.

func (*Generator) GenerateEnum

func (eg *Generator) GenerateEnum(g *genkit.GeneratedFile, enum *genkit.Enum) error

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) Name

func (eg *Generator) Name() string

Name returns the tool name.

func (*Generator) ProcessPackage

func (eg *Generator) ProcessPackage(gen *genkit.Generator, pkg *genkit.Package) error

ProcessPackage processes a package and generates enum helpers.

func (*Generator) Rules added in v0.3.0

func (eg *Generator) Rules() []genkit.Rule

Rules implements genkit.RuleTool. Returns AI-friendly documentation for enumgen.

func (*Generator) Run

func (eg *Generator) Run(gen *genkit.Generator, log *genkit.Logger) error

Run processes all packages and generates enum helpers.

func (*Generator) Validate added in v0.2.1

func (eg *Generator) Validate(gen *genkit.Generator, _ *genkit.Logger) []genkit.Diagnostic

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.

Jump to

Keyboard shortcuts

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