enum

package module
v0.0.0-...-77f9b90 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ItemName  = "Name"
	ItemValue = "Val"
)
View Source
const (
	BlankIdentifier = "_"
)

Variables

View Source
var ErrInvalidAnnotation = errors.New("not a valid Annotation")

Functions

func IndefiniteArticle

func IndefiniteArticle(word string) string

Types

type Annotation

type Annotation string
@Enum {
	Enum = "Enum"
	EnumConfig = "EnumConfig"
}
const (
	// AnnotationEnum is an Annotation of type Enum.
	AnnotationEnum Annotation = "Enum"
	// AnnotationEnumConfig is an Annotation of type EnumConfig.
	AnnotationEnumConfig Annotation = "EnumConfig"
)

func ParseAnnotation

func ParseAnnotation(value string) (Annotation, error)

ParseAnnotation converts a string to an Annotation.

func (Annotation) IsValid

func (x Annotation) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (Annotation) Name

func (x Annotation) Name() string

Name is the attribute of Annotation.

func (Annotation) String

func (x Annotation) String() string

String implements the Stringer interface.

func (Annotation) Val

func (x Annotation) Val() string

Val is the attribute of Annotation.

type Attribute

type Attribute struct {
	Name    string
	Type    reflect.Kind
	Comment string
	// contains filtered or unexported fields
}

func (*Attribute) Attribute2EnumMap

func (ea *Attribute) Attribute2EnumMap() string

func (*Attribute) Attribute2EnumVarName

func (ea *Attribute) Attribute2EnumVarName() string

func (*Attribute) Enum

func (ea *Attribute) Enum() *Enum

func (*Attribute) Enum2AttributeMap

func (ea *Attribute) Enum2AttributeMap() string

func (*Attribute) Enum2AttributeVarName

func (ea *Attribute) Enum2AttributeVarName() string

func (*Attribute) FirstValueBits

func (ea *Attribute) FirstValueBits() int

func (*Attribute) IsValue

func (ea *Attribute) IsValue() bool

func (*Attribute) ParseNumberFuncString

func (ea *Attribute) ParseNumberFuncString() string

type Config

type Config struct {
	Prefix          string
	NoPrefix        bool   `value:"false"` // 所有生成的枚举不携带类型名称前缀
	StringParse     bool   `value:"true"`
	StringParseName string `value:"Name"`
	Flag            bool   `value:"false"`
	MustParse       bool   `value:"false"`
	Marshal         bool   `value:"false"`
	MarshalName     string `value:"Name"`
	Sql             bool   `value:"false"`
	SqlName         string `value:"Val"`
	Names           bool   `value:"false"` // enum name list
	Values          bool   `value:"false"` // enum item list
	NoCase          bool   `value:"false"` // case insensitivity
	NoCamel         bool   `value:"false"`
	NoComments      bool   `value:"false"`
	Ptr             bool   `value:"false"`
	ForceUpper      bool   `value:"false"`
	ForceLower      bool   `value:"false"`
	PanicIfInvalid  bool   `value:"false"`
	// contains filtered or unexported fields
}

func (*Config) CheckValid

func (ec *Config) CheckValid() (err error)

func (*Config) SetFlag

func (ec *Config) SetFlag(flag bool)

func (*Config) SetForceLower

func (ec *Config) SetForceLower(lower bool)

func (*Config) SetForceUpper

func (ec *Config) SetForceUpper(upper bool)

func (*Config) SetStringParse

func (ec *Config) SetStringParse(stringParse bool)

type Enum

type Enum struct {
	Name    string
	Type    reflect.Kind
	Comment string
	Attrs   []*Attribute
	Items   []*Item
	Config  *Config
}

func AnnotationsToEnum

func AnnotationsToEnum(annotations *api.Annotations, ts *ast.TypeSpec, globalConfig *Config) (*Enum, error)

func (*Enum) CheckValid

func (e *Enum) CheckValid() (err error)

func (*Enum) EmptyEnumValue

func (e *Enum) EmptyEnumValue() string

func (*Enum) FindAttributeByName

func (e *Enum) FindAttributeByName(name string) *Attribute

func (*Enum) GetItems

func (e *Enum) GetItems() []*Item

func (*Enum) Names

func (e *Enum) Names() string

func (*Enum) UpdateAttributes

func (e *Enum) UpdateAttributes(a *api.Annotation) error

func (*Enum) UpdateItems

func (e *Enum) UpdateItems(a *api.Annotation) error

type EnumGenerator

type EnumGenerator struct {
	api.BaseGenerator[Enum]
}

func NewEnumGenerator

func NewEnumGenerator(allEnums []*Enum) *EnumGenerator

func (*EnumGenerator) GetImports

func (eg *EnumGenerator) GetImports() []string

type Factory

type Factory struct {
}

@Singleton

func (*Factory) Annotations

func (f *Factory) Annotations() map[string][]api.AnnotationType

func (*Factory) New

func (f *Factory) New(typedAnnotations []*api.TypedAnnotation) (api.Generator, error)

type Item

type Item struct {
	Name              string
	Value             any
	DocComment        string
	LineComment       string
	AttributeData     []any
	IsBlankIdentifier bool
	// contains filtered or unexported fields
}

func (*Item) GetCodeName

func (ei *Item) GetCodeName() string

GetCodeName return the item name used in code

func (*Item) GetConstLine

func (ei *Item) GetConstLine() string

func (*Item) GetName

func (ei *Item) GetName() string

GetName return the item real name, default equals with the code name, or an attribute named `Name`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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