chaingen

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	PkgPath          string
	Package          *packages.Package
	Type             *types.Named
	Annotations      []string
	Struct           *types.Struct
	Methods          []Method
	Children         []*BuilderRef
	MethodNames      map[string]*Method
	File             *ast.File
	FilePath         string
	Rendered         bool
	GeneratedMethods []Method
	Depth            int
}

Builder represents a struct type that is considered to be a builder. Builder has at least one method that returns altered Builder copy (chaining method). Every non-chaining method is considered as finalizer

func (*Builder) ReceiverName

func (b *Builder) ReceiverName() string

func (*Builder) ReceiverType added in v0.1.4

func (b *Builder) ReceiverType(ptr bool) string

func (*Builder) Ref

func (b *Builder) Ref(builder *Builder) *BuilderRef

func (*Builder) RenderChainMethod

func (b *Builder) RenderChainMethod(file *File, method Method)

func (*Builder) RenderFinalizer

func (b *Builder) RenderFinalizer(file *File, method Method)

type BuilderRef

type BuilderRef struct {
	Name            string
	IsMethod        bool
	FieldAnnotation string
	Builder         *Builder
}

type BuilderSpec added in v0.1.10

type BuilderSpec struct {
	Type       *types.Type
	Annotation string
}

type Chaingen

type Chaingen struct {
	// contains filtered or unexported fields
}

func New

func New(opts Options) Chaingen

func (Chaingen) Generate

func (c Chaingen) Generate() error

func (Chaingen) NewBuilder

func (c Chaingen) NewBuilder(builders map[*types.Named]*Builder, pkg *packages.Package, n *types.Named) error

func (Chaingen) Render

func (c Chaingen) Render(builders map[*types.Named]*Builder) (map[string]*File, error)

type File

type File struct {
	Builders []*Builder
	Package  *packages.Package
	File     *ast.File
	Path     string
	BuildTag string

	Imports       map[string]Import
	ImportAliases map[string]*Import
	Body          bytes.Buffer
}

func (*File) L

func (f *File) L(s ...string)

func (*File) P

func (f *File) P(s ...string)

func (*File) PackageIdentifier

func (f *File) PackageIdentifier(pkg *types.Package) string

func (*File) Render

func (f *File) Render(w io.Writer) error

func (*File) TypeIdentifier

func (f *File) TypeIdentifier(typ types.Type) string

type Glob

type Glob struct {
	TypeName string
	Const    string
	Prefix   string
	Suffix   string
	Middle   string
}

func NewGlob

func NewGlob(glob string) Glob

func (Glob) Match

func (g Glob) Match(typeName string, str string) bool

func (Glob) Replace

func (g Glob) Replace(methodName string, right *Glob) string

type Import

type Import struct {
	Alias   string
	Package *types.Package
}

type Method

type Method struct {
	Name     string
	Alias    string
	Scope    *types.Scope
	Pos      token.Pos
	Variadic bool
	Exported bool
	Builder  *Builder

	Recv        MethodParam
	Params      []MethodParam
	Results     []MethodParam
	Prefixes    []string
	Postfixes   []string
	WrapperName string
	Pointer     bool
}

func NewMethod

func NewMethod(builder *Builder, f *types.Func, sig *types.Signature) Method

func (Method) Doc

func (m Method) Doc() *ast.CommentGroup

func (Method) IsChaining

func (m Method) IsChaining() bool

func (Method) IsFinalizer

func (m Method) IsFinalizer() bool

func (Method) String

func (m Method) String() string

type MethodParam

type MethodParam struct {
	Name  string
	Type  types.Type
	Named *types.Named
}

type Options

type Options struct {
	Src           string
	TypeName      string
	Recursive     bool
	FileSuffix    string
	ErrOnConflict bool
	StructTag     string
	BuildTag      string
}

Jump to

Keyboard shortcuts

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