Documentation ¶
Index ¶
- Variables
- func AssignEnumConstBlockToType(node ast.Node, typesInfo *types.Info, genFile *ast.File, enumTypes []*EnumType) (token.Pos, error)
- func DetectGeneratedFile(files []*ast.File) (genFile *ast.File)
- func TypeToString(t types.BasicKind) string
- type AdditionalData
- type AdditionalDataCell
- type AdditionalDataHeader
- type EnumConstBlock
- type EnumType
- func (e *EnumType) CrossValidateConstBlockWithSpec(fset *token.FileSet, typesInfo *types.Info) error
- func (e *EnumType) DetectMagicComment() (c *ast.Comment)
- func (e *EnumType) GetPkgFS(fset *token.FileSet) (fs.FS, bool)
- func (e *EnumType) GetTypeVia(ti *types.Info) types.Type
- func (e *EnumType) HasFileSpec() bool
- func (e *EnumType) HasSimpleBlockSpec() bool
- func (e *EnumType) LoadFileSpec(fset *token.FileSet) error
- func (e *EnumType) LoadSimpleBlockSpec() error
- func (e *EnumType) LoadSpec(fset *token.FileSet) error
- func (e *EnumType) Name() *ast.Ident
- func (e *EnumType) ParseMagicComment(mc *ast.Comment, opts *config.Options) error
- func (e *EnumType) ValidateConstBlock(fset *token.FileSet, typesInfo *types.Info) error
- func (e *EnumType) ValidateEnumTypeConfig(fset *token.FileSet) error
- func (e *EnumType) ValidateSpec(fset *token.FileSet, typesInfo *types.Info) error
- type EnumTypeConfig
- type EnumTypeSpec
- type EnumTypeSpecValue
- type EnumValueSpec
- type SpecType
Constants ¶
This section is empty.
Variables ¶
var ( ErrIsNaN = errors.New("typed value is NaN") ErrIsPosInf = errors.New("typed value is +Inf") ErrIsNegInf = errors.New("typed value is -Inf") )
var ( MAGIC_MARKER = regexp.MustCompile(`^//go:enum[ ]?`) GEN_ENUMER_FILE = regexp.MustCompile(`^// Code generated by "go-enumer \(github\.com/mvrahden/go-enumer\)"; DO NOT EDIT\.(?:$|\n)`) IS_NUMERIC_VALUE = regexp.MustCompile(`^\-?\d+`) IS_TYPED_HEADER = regexp.MustCompile(`^.+(\(.+\))$`) // e.g. uint32(xyz) )
var ExtractCommentString = func(c *ast.Comment) string {
return c.Text
}
ExtractCommentString is a Noop func, but allows to be intercepted during tests to clean comment texts from test artifacts while keeping production code unaffected.
Functions ¶
func AssignEnumConstBlockToType ¶
func AssignEnumConstBlockToType(node ast.Node, typesInfo *types.Info, genFile *ast.File, enumTypes []*EnumType) (token.Pos, error)
AssignEnumConstBlockToType evaluates the current node for a possible const block spec/enum values. If the given node does not fulfill the requirements for a possible const block spec, it returns zero values. If the given node violates the requirements for possible const block spec, it returns an error and the token position. It otherwise determines all const block values and assigns them to relevant enumtype from the given slice of enum types.
func DetectGeneratedFile ¶
DetectGeneratedFile determines the generated enumer file. If no such file exists, it will return `nil`.
func TypeToString ¶
Types ¶
type AdditionalData ¶
type AdditionalData struct { Headers []*AdditionalDataHeader Rows [][]*AdditionalDataCell }
type AdditionalDataCell ¶
type AdditionalDataHeader ¶
type EnumConstBlock ¶
type EnumConstBlock struct { Node *ast.GenDecl Specs []*EnumValueSpec // hint: all value specs of a block }
type EnumType ¶
type EnumType struct { Node *ast.GenDecl Config *EnumTypeConfig Spec *EnumTypeSpec // hint: the specification derived either from const block notation or from a file ConstBlock *EnumConstBlock }
func DetermineEnumType ¶
func DetermineEnumType(node ast.Node, typesInfo *types.Info, genFile *ast.File) (*EnumType, token.Pos, error)
DetermineEnumType evaluates given node for enum types. If the given node is not fulfilling the requirements for a possible enum type declaration it returns zero values. If the given node violates the requirements for a eum declaration it will return an error and the token position.
func (*EnumType) CrossValidateConstBlockWithSpec ¶
func (*EnumType) DetectMagicComment ¶
DetectMagicComment retrieves the magic comment from the list of comments. It assumes that a magic comment exists.
func (*EnumType) HasFileSpec ¶
HasFileSpec indicates whether or not the EnumType is configured with a source file. Its usage is legal for AFTER the config has been loaded.
func (*EnumType) HasSimpleBlockSpec ¶
func (*EnumType) LoadSimpleBlockSpec ¶
func (*EnumType) ParseMagicComment ¶
func (*EnumType) ValidateConstBlock ¶
func (*EnumType) ValidateEnumTypeConfig ¶
type EnumTypeConfig ¶
func DefaultConfig ¶
func DefaultConfig(cfg *config.Options) *EnumTypeConfig
type EnumTypeSpec ¶
type EnumTypeSpec struct { Type SpecType Values []*EnumTypeSpecValue AdditionalData *AdditionalData }
type EnumTypeSpecValue ¶
type EnumTypeSpecValue struct { ID uint64 EnumValue string IsAlternative bool // hint: an alternative value ConstSpec *EnumValueSpec // hint: if derived from const value }
type EnumValueSpec ¶
func (*EnumValueSpec) GetObjectVia ¶
func (e *EnumValueSpec) GetObjectVia(ti *types.Info) types.Object
func (*EnumValueSpec) GetTypeVia ¶
func (e *EnumValueSpec) GetTypeVia(ti *types.Info) types.Type