gen

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyPackages = errors.New("too many package")
)

Functions

This section is empty.

Types

type File

type File struct {
	*Package            // Package to which this file belongs.
	*ast.File           // Parsed AST.
	TypeName    string  // Name of the constant type.
	Values      []Value // Accumulator for constant values of that type.
	TrimPrefix  string
	LineComment bool
}

func (*File) GenDecl

func (f *File) GenDecl(node ast.Node) bool

type Generator

type Generator struct {
	TrimPrefix  string
	LineComment bool
	// contains filtered or unexported fields
}

func New

func New(trimPrefix string, lineComment bool) *Generator

func (*Generator) Format

func (g *Generator) Format() []byte

func (*Generator) Generate

func (g *Generator) Generate(typeName string) (err error)

generate produces the String method for the named type.

func (*Generator) GenerateHeader

func (g *Generator) GenerateHeader() error

func (*Generator) ParsePackage

func (g *Generator) ParsePackage(patterns []string, tags []string) (err error)

ParsePackage analyzes the single package constructed from the patterns and tags.

type Package

type Package struct {
	Name  string
	Defs  map[*ast.Ident]types.Object
	Files []*File
}

type Value

type Value struct {
	OriginalName string // The name of the constant.
	Name         string // The name with trimmed prefix.
	// The value is stored as a bit pattern alone. The boolean tells us
	// whether to interpret it as an int64 or a uint64; the only place
	// this matters is when sorting.
	// Much of the time the str field is all we need; it is printed
	// by Value.String.
	Value  uint64 // Will be converted to int64 when needed.
	Signed bool   // Whether the constant is a signed type.
	Str    string // The string representation given by the "go/constant" package.
}

Value represents a declared constant.

func (*Value) String

func (v *Value) String() string

Jump to

Keyboard shortcuts

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