generator

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const Autoname = "."
View Source
const BaseConstType = "string"

Variables

This section is empty.

Functions

func FiledPathAndAccessCheckCondition

func FiledPathAndAccessCheckCondition(receiverVar string, isReceiverReference, redeclareReceiver bool, fieldParts []FieldInfo) (string, string, []string)

func FuncDeclName

func FuncDeclName(funcDecl *ast.FuncDecl) string

func GenerateGetter added in v0.0.2

func GenerateGetter(model *struc.Model, pkgName, receiverVar, methodName, fieldName, fieldType, outPkgPath string, nolint bool, isReceiverReference bool, fieldParts []FieldInfo) string

func GenerateSetter added in v0.0.2

func GenerateSetter(model *struc.Model, pkgName, receiverVar, methodName, fieldName, fieldType, outPkgPath string, nolint bool, isReceiverReference bool, fieldParts []FieldInfo) string

func GetFieldConstName

func GetFieldConstName(typeName string, fieldName struc.FieldName, export, snake bool) string

func GetFieldRef

func GetFieldRef(fields ...struc.FieldName) struc.FieldName

func GetFieldType

func GetFieldType(typeName string, export, snake bool) string

func GetTypeName

func GetTypeName(typeName string, pkg string) string

func IdentName

func IdentName(name string, export bool) string

func IsExported added in v0.0.2

func IsExported(name string) bool

func LegalIdentName

func LegalIdentName(name string) string

func MethodName

func MethodName(typ, fun string) string

func NoLint

func NoLint(nolint bool) string

func OutPackageName

func OutPackageName(outPackageName string, outPackage *packages.Package) string

func PathToShortVarName

func PathToShortVarName(fieldPath string) string

func PathToVarName

func PathToVarName(fieldPath string) string

func Quoted

func Quoted(value string) string

func TypeParamsDeclarationString

func TypeParamsDeclarationString(list *types.TypeParamList, basePkgPath string) string

func TypeParamsString

func TypeParamsString(tparams *types.TypeParamList, basePkgPath string) string

func TypeReceiverVar added in v0.0.2

func TypeReceiverVar(typeName string) string

Types

type CodeRewriter

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

func NewCodeRewriter

func NewCodeRewriter(fieldValueRewriters []string) (*CodeRewriter, error)

func (*CodeRewriter) Transform

func (rewrite *CodeRewriter) Transform(fieldName string, fieldType struc.FieldType, fieldRef string) (string, bool)

type FieldConst added in v0.0.2

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

func (FieldConst) Name added in v0.0.2

func (constant FieldConst) Name() string

type FieldInfo

type FieldInfo struct {
	Name string
	Type struc.FieldType
}

type Generator

type Generator struct {
	OutPkgPath  string
	OutPkgTypes *types.Package
	// contains filtered or unexported fields
}

func New

func New(name, outBuildTags string, outFile *ast.File, outFileInfo *token.File, pkgPath string, pkgTypes *types.Package) *Generator

func (*Generator) AddFuncDecl

func (g *Generator) AddFuncDecl(node *ast.FuncDecl) error

func (*Generator) AddFuncOrMethod

func (g *Generator) AddFuncOrMethod(name, body string) error

func (*Generator) AddImport

func (g *Generator) AddImport(pack, name, alias string) (string, error)

func (*Generator) AddMethod

func (g *Generator) AddMethod(typ, name, body string) error

func (*Generator) AddStruct

func (g *Generator) AddStruct(s Structure) error

func (*Generator) AddType

func (g *Generator) AddType(typeName string, typeValue string) error

func (*Generator) FormatSrc

func (g *Generator) FormatSrc() ([]byte, error)

func (*Generator) GenerateAsMapFunc

func (g *Generator) GenerateAsMapFunc(
	model *struc.Model, name, keyType string,
	constants []FieldConst,
	rewriter *CodeRewriter,
	export, snake, returnRefs, noReceiver, nolint, hardcodeValues bool,
) (string, string, string, error)

func (*Generator) GenerateFieldConstant

func (g *Generator) GenerateFieldConstant(
	model *struc.Model, valueTmpl, nameTmpl, typ, funcList, typeMethod, refAccessor, valAccessor string,
	export, snake, nolint, compact, usePrivate, notDeclateConsType, uniqueValues bool,
	flats, excludedFields c.Checkable[string], include string,
) error

func (*Generator) GenerateFieldConstants

func (g *Generator) GenerateFieldConstants(model *struc.Model, typ string, export, snake, allFields bool, flats c.Checkable[string]) ([]FieldConst, error)

func (*Generator) GetFullFieldTypeName added in v0.0.2

func (g *Generator) GetFullFieldTypeName(fieldType struc.FieldType, baseType bool) (string, error)

func (*Generator) GetPackageName

func (g *Generator) GetPackageName(pkgName, pkgPath string) (string, error)

func (*Generator) ImportPack

func (g *Generator) ImportPack(pkg *types.Package, basePackagePath string) (*types.Package, error)

func (*Generator) Repack

func (g *Generator) Repack(typ types.Type, basePackagePath string) (types.Type, error)

func (*Generator) RepackObj

func (g *Generator) RepackObj(typName *types.TypeName, basePackagePath string) (*types.TypeName, error)

func (*Generator) RepackTuple

func (g *Generator) RepackTuple(vr *types.Tuple, basePackagePath string) (*types.Tuple, error)

func (*Generator) RepackVar

func (g *Generator) RepackVar(vr *types.Var, basePackagePath string) (*types.Var, error)

func (*Generator) Src

func (g *Generator) Src() ([]byte, error)

func (*Generator) WriteBody

func (g *Generator) WriteBody(outPackageName string) error

type RewriteEngine

type RewriteEngine string
const (
	RewriteEngineFmt RewriteEngine = "fmt"
)

type RewriteTrigger

type RewriteTrigger string
const (
	RewriteTriggerEmpty RewriteTrigger = ""
	RewriteTriggerField RewriteTrigger = "field"
	RewriteTriggerType  RewriteTrigger = "type"
)

type Structure

type Structure struct {
	Name, Body string
	// contains filtered or unexported fields
}

func (*Structure) AddMethod

func (s *Structure) AddMethod(name, val string) error

Jump to

Keyboard shortcuts

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