typgen

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultParent = "internal/generated"
)
View Source
const (
	InitFilePath = "internal/generated/init.go"
)

Variables

View Source
var (
	DefaultInitImports = map[string]string{
		"github.com/kmrtftech/tg-framework/pkg/typapp": "",
	}
	InfoSignature = CodeLine("// DO NOT EDIT. Code-generated file\n")
)

Functions

func CreateTargetDir

func CreateTargetDir(path string, suffix string) string

func ExecuteAnnotator

func ExecuteAnnotator(ctx *Context, ator Annotator, filtered []*Annotation) error

func IsFunc

func IsFunc(d *Annotation) bool

func IsInterface

func IsInterface(d *Annotation) bool

func IsPublic

func IsPublic(d *Annotation) bool

func IsStruct

func IsStruct(d *Annotation) bool

func MappedAnnotsByFile

func MappedAnnotsByFile(annots []*Annotation) map[*File][]*Annotation

func PackageName

func PackageName(path string) string

func ParseRawAnnot

func ParseRawAnnot(raw string) (name, params string)

ParseRawAnnot parse raw string to annotation

func StructTag

func StructTag(tag *ast.BasicLit) reflect.StructTag

StructTag create struct tag

func WriteCoder

func WriteCoder(c *typgo.Context, coder Coder, target string) error

Types

type AliasGenerator

type AliasGenerator struct {
	Map map[string]string // key is import package , value is import alias
	// contains filtered or unexported fields
}

func NewAliasGenerator

func NewAliasGenerator(m map[string]string) *AliasGenerator

func (*AliasGenerator) Generate

func (i *AliasGenerator) Generate(val string) string

func (*AliasGenerator) Imports

func (i *AliasGenerator) Imports() []*Import

func (*AliasGenerator) Keys

func (i *AliasGenerator) Keys() []string

type AnnotProcessor

type AnnotProcessor interface {
	ProcessAnnot(*Context, *Annotation) error
}

type AnnotatedFileProcessor

type AnnotatedFileProcessor interface {
	ProcessAnnotatedFile(*Context, *File, []*Annotation) error
}

type Annotation

type Annotation struct {
	Name   string            `json:"name"`
	Params reflect.StructTag `json:"params"`
	Decl   *Decl             `json:"decl"`
}

Annotation that contain extra additional information

func Compile

func Compile(paths ...string) ([]*Annotation, error)

func Filter

func Filter(annotations []*Annotation, annotator Annotator) []*Annotation

func (*Annotation) Dir

func (d *Annotation) Dir() string

func (*Annotation) Package

func (d *Annotation) Package() string

Package of annotation

func (*Annotation) PackagePath

func (d *Annotation) PackagePath() string

func (*Annotation) Path

func (d *Annotation) Path() string

type Annotator

type Annotator interface {
	AnnotationName() string
	IsAllowed(*Annotation) bool
}

type CodeGenerator

type CodeGenerator struct {
	Walker     Walker
	Annotators []Annotator
}

func (*CodeGenerator) Execute

func (g *CodeGenerator) Execute(c *typgo.Context) error

Execute annotation

func (*CodeGenerator) Task

func (g *CodeGenerator) Task() *typgo.Task

Task to annotate

type CodeLine

type CodeLine string

func (CodeLine) Code

func (c CodeLine) Code() string

type CodeLines

type CodeLines []string

func (CodeLines) Code

func (c CodeLines) Code() string

type Coder

type Coder interface {
	Code() string
}

type Coders

type Coders []Coder

func (Coders) Code

func (s Coders) Code() string

type Context

type Context struct {
	*typgo.Context
	InitAliasGen *AliasGenerator
	InitFuncBody CodeLines
	MappedCoders map[*File][]Coder
	Annotations  []*Annotation
}

func NewContext

func NewContext(c *typgo.Context, annots []*Annotation) *Context

func (*Context) AppendFileCoder

func (i *Context) AppendFileCoder(file *File, coder Coder)

func (*Context) AppendInit

func (c *Context) AppendInit(s string)

func (*Context) AppendInitf

func (i *Context) AppendInitf(format string, args ...interface{})

func (*Context) ProvideConstructor

func (i *Context) ProvideConstructor(name, importPath, constructor string)

func (*Context) WriteFile

func (i *Context) WriteFile(f *File, target string) error

func (*Context) WriteInitFile

func (i *Context) WriteInitFile(target string) error

type Decl

type Decl struct {
	File *File
	Type
}

Decl stand of declaration

type Field

type Field struct {
	Names []string
	Type  string
	reflect.StructTag
}

Field information

type FieldList

type FieldList struct {
	List []*Field
}

FieldList function parameter

type File

type File struct {
	Path    string
	Name    string
	Imports []*Import
}

File information

func (*File) Code

func (f *File) Code() string

type FilePaths

type FilePaths []string

func (FilePaths) Walk

func (f FilePaths) Walk() []string

type Function

type Function struct {
	Name    string
	Docs    []string
	Recv    []*Field
	Params  []*Field
	Returns []*Field
	Body    Coder
}

Function declaration

func CreateFuncDecl

func CreateFuncDecl(funcDecl *ast.FuncDecl, file *File) *Function

func (*Function) Code

func (f *Function) Code() string

func (*Function) GetDocs

func (f *Function) GetDocs() []string

GetDocs comment documentation

func (*Function) GetName

func (f *Function) GetName() string

GetName of declaration

func (*Function) IsMethod

func (f *Function) IsMethod() bool

IsMethod return true if function is method (has receiver argument)

type GenDecl

type GenDecl struct {
	Docs []string
}

GenDecl generic declaration

type Import

type Import struct {
	Name string
	Path string
}

func CreateImports

func CreateImports(f *ast.File) []*Import

type Interface

type Interface struct {
	TypeDecl
}

Interface interface declaration

func CreateInterfaceDecl

func CreateInterfaceDecl(typeDecl TypeDecl) *Interface

type Layouts

type Layouts []string

func (Layouts) Walk

func (l Layouts) Walk() []string

type PostAnnotator

type PostAnnotator interface {
	AfterAnnotate(*Context, []*Annotation) error
}

type PreAnnotator

type PreAnnotator interface {
	BeforeAnnotate(*Context, []*Annotation) error
}

type Struct

type Struct struct {
	TypeDecl
	Fields []*Field
}

Struct declaration

func CreateStructDecl

func CreateStructDecl(typeDecl TypeDecl, structType *ast.StructType) *Struct

type Type

type Type interface {
	GetName() string
	GetDocs() []string
}

Type declaration type

type TypeDecl

type TypeDecl struct {
	GenDecl
	Name string
	Docs []string
}

TypeDecl type declaration

func (*TypeDecl) GetDocs

func (t *TypeDecl) GetDocs() []string

GetDocs get doc

func (*TypeDecl) GetName

func (t *TypeDecl) GetName() string

GetName get name

type Walker

type Walker interface {
	Walk() []string
}

Jump to

Keyboard shortcuts

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