generator

package
v0.0.0-...-ab3e630 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCannotExecuteTemplate             = "cannot execute template"
	ErrorCannotFormatGeneratedCode         = "cannot format generated code"
	ErrorCannotGenerateProxies             = "cannot generate proxies"
	ErrorFailedToOpenTemplateFile          = "failed to open template file"
	ErrorFailedToWriteGeneratedCode        = "failed to write generated code"
	ErrorTemplateFileNotFound              = "template file not found"
	ErrorFailedToObtainGeneratorSourceFile = "failed to obtain generator source file"
)

Variables

View Source
var (
	ErrCannotExecuteTemplate             = errors.New(ErrorCannotExecuteTemplate)
	ErrCannotFormatGeneratedCode         = errors.New(ErrorCannotFormatGeneratedCode)
	ErrCannotGenerateProxies             = errors.New(ErrorCannotGenerateProxies)
	ErrFailedToOpenTemplateFile          = errors.New(ErrorFailedToOpenTemplateFile)
	ErrFailedToWriteGeneratedCode        = errors.New(ErrorFailedToWriteGeneratedCode)
	ErrTemplateFileNotFound              = errors.New(ErrorTemplateFileNotFound)
	ErrFailedToObtainGeneratorSourceFile = errors.New(ErrorFailedToObtainGeneratorSourceFile)
)
View Source
var (
	ErrCannotReadModFile             = errors.New(errorCannotReadModFile)
	ErrCannotParseModFile            = errors.New(errorCannotParseModFile)
	ErrFailedToAddRequiredDependency = errors.New(errorFailedToAddRequiredDependency)
	ErrCannotFormatModFile           = errors.New(errorCannotFormatModFile)
	ErrCannotWriteModFile            = errors.New(errorCannotWriteModFile)
)

Functions

func FormatType

func FormatType(parameter reflection.Parameter) string

FormatType formats the given reflection.Parameter's type information into a string representation.

func FormattedCallParameters

func FormattedCallParameters(m reflection.Method) string

FormattedCallParameters formats the call parameters of the given reflection.Method into a comma-separated string.

func FormattedParameters

func FormattedParameters(m reflection.Method) string

FormattedParameters formats the parameters of the given reflection.Method into a comma-separated string with type info.

func FormattedResultParameters

func FormattedResultParameters(m reflection.Method) string

FormattedResultParameters formats the result parameters of the given reflection.Method into a comma-separated string.

func FormattedResultTypes

func FormattedResultTypes(m reflection.Method) string

FormattedResultTypes formats the result types of the given reflection.Method into a string representation.

func GetGoFilePath

func GetGoFilePath() (string, error)

func GoFileAccessor

func GoFileAccessor() reflection.AstFileAccessor

GoFileAccessor Creates a new reflection.AstFileAccessor object that reads a source file from the GOFILE variable.

func HasResults

func HasResults(m reflection.Method) bool

HasResults checks if the given reflection.Method has any result parameters.

func MakePrivate

func MakePrivate(s string) string

func MakePublic

func MakePublic(s string) string

func RegisterNamingFunctions

func RegisterNamingFunctions(generator GenericCodeGenerator) error

func RegisterTemplateFunctions

func RegisterTemplateFunctions(g GenericCodeGenerator, functions ...func(generator GenericCodeGenerator) error) error

func RegisterTypeModelFunctions

func RegisterTypeModelFunctions(generator GenericCodeGenerator) error

RegisterTypeModelFunctions registers a series of functions for type model processing in the given code generator.

func Signature

func Signature(m reflection.Method) string

Signature generates the signature string of a given method.

Types

type BootstrapGenerator

type BootstrapGenerator interface {
	ScaffoldProjectFiles()
}

BootstrapGenerator provides functionalities to scaffold project files.

func NewBootstrapGenerator

func NewBootstrapGenerator(writerFunc ScaffoldingFileWriterFunc) BootstrapGenerator

NewBootstrapGenerator initializes and returns a BootstrapGenerator with the specified project folder path.

type CodeFileGenerator

type CodeFileGenerator interface {
	GenerateCode() error
}

func NewCodeFileGenerator

func NewCodeFileGenerator(kind string, fileAccessor reflection.AstFileAccessor, config ...CodeFileGeneratorOptionsFunc) (CodeFileGenerator, error)

type CodeFileGeneratorOptions

type CodeFileGeneratorOptions struct {
	TemplateLoader         TemplateLoader
	ConfigureModelCallback reflection.ModelConfigurationFunc
	OutputWriterFactory    OutputWriterFactory
	// contains filtered or unexported fields
}

type CodeFileGeneratorOptionsFunc

type CodeFileGeneratorOptionsFunc func(config *CodeFileGeneratorOptions)

type GenericCodeGenerator

type GenericCodeGenerator interface {
	AddTemplateFunc(functions ...TemplateFunction) error
	Generate(templateName string, model any, writer io.Writer) error
}

func NewGenericCodeGenerator

func NewGenericCodeGenerator(templateLoader TemplateLoader) GenericCodeGenerator

type GoProject

type GoProject interface {
	AddDependency(packageName string, version string) error
}

func OpenProject

func OpenProject(projectFolderPath string) (GoProject, error)

OpenProject opens an existing Go project from the specified folder path and returns a GoProject instance.

type OutputWriterFactory

type OutputWriterFactory func(kind string, source *reflection.AstFileSource) (io.WriteCloser, error)

func FileOutputWriter

func FileOutputWriter() OutputWriterFactory

FileOutputWriter Creates an OutputWriterFactory object that can be used create file writers.

type ProjectError

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

func (ProjectError) Error

func (e ProjectError) Error() string

func (ProjectError) Is

func (e ProjectError) Is(err error) bool

func (ProjectError) Unwrap

func (e ProjectError) Unwrap() error

type ProjectItem

type ProjectItem struct {
	TemplateName   string
	TargetFilename string
}

ProjectItem represents a template file and its corresponding target filename in a project scaffold.

type ScaffoldingFileWriterFunc

type ScaffoldingFileWriterFunc func(targetFilename string) (io.WriteCloser, error)

type TemplateFunction

type TemplateFunction struct {
	Name     string
	Function any
}

func NamedFunc

func NamedFunc(name string, f any) TemplateFunction

type TemplateLoader

type TemplateLoader func(name string) (string, error)

type TemplateModelBuilder

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

func NewTemplateModelBuilder

func NewTemplateModelBuilder(file *ast.File) *TemplateModelBuilder

func (*TemplateModelBuilder) Build

func (b *TemplateModelBuilder) Build() (*reflection.Model, error)

Jump to

Keyboard shortcuts

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