generator

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package generator provides enum code generation functionality.

Index

Constants

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.

Functions

func GetValueName

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

GetValueName returns the display name for an enum value. 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.

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

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

Run processes all packages and generates enum helpers.

func (*Generator) WriteHeader

func (eg *Generator) WriteHeader(g *genkit.GeneratedFile, pkgName string)

WriteHeader writes the file header.

Jump to

Keyboard shortcuts

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