builder

package
v0.0.0-...-dc97279 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicLit

func BasicLit(value string) *ast.BasicLit

func Ident

func Ident(value string) *ast.Ident

func IdentList

func IdentList(value ...string) []*ast.Ident

func IdentListExpr

func IdentListExpr(value ...string) []ast.Expr

func IntLit

func IntLit(value int) *ast.BasicLit

func LastExpr

func LastExpr(data *References, expr ast.Expr) ast.Expr

Busca a ultima expressão e adiciona nas referencias

func NewFilename

func NewFilename(file string, suffix string) string

Remove a extensão do arquivo e adiciona um suffixo

func StringLit

func StringLit(value string) *ast.BasicLit

Types

type ExprBlockBuilder

type ExprBlockBuilder struct {
	Expr []ast.Expr
}

func ExprBlock

func ExprBlock() *ExprBlockBuilder

Bloco de expressão

func (*ExprBlockBuilder) Append

func (b *ExprBlockBuilder) Append(expr *ExprBuilder) *ExprBlockBuilder

Adiciona a expressão na lista

func (*ExprBlockBuilder) AppendBlock

func (b *ExprBlockBuilder) AppendBlock(expr *ExprBlockBuilder) *ExprBlockBuilder

Adiciona um bloco de expressão

func (*ExprBlockBuilder) AppendExpr

func (b *ExprBlockBuilder) AppendExpr(expr ast.Expr) *ExprBlockBuilder

Adiciona a expressão na lista

func (*ExprBlockBuilder) AppendExprs

func (b *ExprBlockBuilder) AppendExprs(expr []ast.Expr) *ExprBlockBuilder

Adiciona um bloco de expressão

type ExprBuilder

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

func Expr

func Expr(name string) *ExprBuilder

Cria uma expressão. Inicialmente tem o valor de &ast.Ident

func (*ExprBuilder) BinaryExpr

func (b *ExprBuilder) BinaryExpr(exp ast.Expr, op token.Token) *ExprBuilder

Operação (ExprBuilder).expr (op) expr

func (*ExprBuilder) Call

func (b *ExprBuilder) Call(exp *ExprBuilder) *ast.CallExpr

*ExprBuilder -> *ast.CallExpr

func (*ExprBuilder) CallExpr

func (b *ExprBuilder) CallExpr(args ...ast.Expr) *ast.CallExpr

...ast.Expr -> *ast.CallExpr

func (*ExprBuilder) CallExprBlock

func (b *ExprBuilder) CallExprBlock(expr *ExprBlockBuilder) *ast.CallExpr

*ExprBlockBuilder -> *ast.CallExpr

func (*ExprBuilder) CallStr

func (b *ExprBuilder) CallStr(args ...string) *ast.CallExpr

...string -> *ast.CallExpr

func (*ExprBuilder) CompositeLit

func (b *ExprBuilder) CompositeLit(elts *ExprBlockBuilder) *ExprBuilder

CompositeLit: ExprBuilder { ExprBlockBuilder }

func (*ExprBuilder) E

func (b *ExprBuilder) E() ast.Expr

Return ast.Expr

func (*ExprBuilder) ExprList

func (b *ExprBuilder) ExprList() []ast.Expr

Converte em []ast.Expr { ExprBuilder }

func (*ExprBuilder) Field

func (b *ExprBuilder) Field(names []*ast.Ident) *ast.Field

Convert em campo

func (*ExprBuilder) KeyValue

func (b *ExprBuilder) KeyValue(value *ExprBuilder) *ExprBuilder

KeyValueExpr => key:value

func (*ExprBuilder) NotEquals

func (b *ExprBuilder) NotEquals(expr *ExprBuilder) *ExprBuilder

Não igual (ExprBuilder) != expr

func (*ExprBuilder) NotEqualsExpr

func (b *ExprBuilder) NotEqualsExpr(expr ast.Expr) *ExprBuilder

Não igual (ExprBuilder) != expr

func (*ExprBuilder) NotNil

func (b *ExprBuilder) NotNil() *ExprBuilder

Não nulo (ExprBuilder) != nil

func (*ExprBuilder) Property

func (b *ExprBuilder) Property(property string) *ExprBuilder

Acesso a propriedade (SelectorExpr)

func (*ExprBuilder) Star

func (b *ExprBuilder) Star() *ExprBuilder

StarExpr => *ExprBuilder

func (*ExprBuilder) TypeAssert

func (e *ExprBuilder) TypeAssert(typeAssert *ExprBuilder) *ExprBuilder

ExprBuilder.(TypeAssert)

func (*ExprBuilder) TypeAssertExpr

func (e *ExprBuilder) TypeAssertExpr(typeAssert ast.Expr) *ExprBuilder

ExprBuilder.(TypeAssert)

func (*ExprBuilder) UnaryAndExpr

func (b *ExprBuilder) UnaryAndExpr() *ExprBuilder

UnaryExpr(Token.AND): & ExprBuilder

func (*ExprBuilder) UnaryArrowExpr

func (b *ExprBuilder) UnaryArrowExpr() *ExprBuilder

UnaryExpr(Token.AND): <- ExprBuilder

type FieldBuilder

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

func Fields

func Fields(builder func(b *FieldBuilder)) *FieldBuilder

Campos

func (*FieldBuilder) Field

func (b *FieldBuilder) Field(field []*ast.Field) *FieldBuilder

Adiciona o campo

func (*FieldBuilder) FieldExpr

func (b *FieldBuilder) FieldExpr(field *ExprBuilder) *FieldBuilder

Adiciona o campo

func (*FieldBuilder) Fields

func (b *FieldBuilder) Fields(field ...*ast.Field) *FieldBuilder

Adiciona o campo

type FileBuilder

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

func NewFileBuilder

func NewFileBuilder() *FileBuilder

Construtor de arquivos

func (*FileBuilder) AppendDecl

func (b *FileBuilder) AppendDecl(decl ast.Decl) *FileBuilder

Adiciona a declaração no corpo do arquivo

func (*FileBuilder) AppendDeclList

func (b *FileBuilder) AppendDeclList(decl []ast.Decl) *FileBuilder

Adiciona a declaração no corpo do arquivo

func (*FileBuilder) AppendFunc

func (b *FileBuilder) AppendFunc(decl *FuncBuilder) *FileBuilder

Adiciona a func no arquivo

func (*FileBuilder) AppendStruct

func (b *FileBuilder) AppendStruct(decl *StructBuilder) *FileBuilder

Adiciona a struct no arquivo

func (*FileBuilder) Import

func (b *FileBuilder) Import(path string) *FileBuilder

Adiciona a importação

func (*FileBuilder) ImportName

func (b *FileBuilder) ImportName(name string, path string) *FileBuilder

Adiciona a importação

func (*FileBuilder) Info

func (b *FileBuilder) Info(projectName, projectUrl string) *FileBuilder

Informações da geração

func (*FileBuilder) Package

func (b *FileBuilder) Package(name string) *FileBuilder

Declaração do pacote do arquivo

func (*FileBuilder) Write

func (b *FileBuilder) Write(fileSet *token.FileSet, path string) error

Escreve o arquivo

type FuncBuilder

type FuncBuilder struct {
	Name *ast.Ident
	Body *ast.BlockStmt
	Type *ast.FuncType
	// contains filtered or unexported fields
}

func Func

func Func(name string, builder func(b *FuncBuilder)) *FuncBuilder

Cria uma nova função (FuncDecl)

func (*FuncBuilder) AppendBody

func (fn *FuncBuilder) AppendBody(stmt *StmtBuilder) *FuncBuilder

Corpo da função

func (*FuncBuilder) D

func (b *FuncBuilder) D() *ast.FuncDecl

func(<recv>) <name>(<param>) <returns> { <body> }

func (*FuncBuilder) L

func (b *FuncBuilder) L() *ast.FuncLit

func (<param>) <returns> { <body> }

func (*FuncBuilder) Params

func (b *FuncBuilder) Params(builder func(*FieldBuilder)) *FuncBuilder

Parâmetros da função

func (*FuncBuilder) ParamsList

func (b *FuncBuilder) ParamsList(fields []*ast.Field) *FuncBuilder

Parâmetros da função

func (*FuncBuilder) Recv

func (b *FuncBuilder) Recv(builder func(*FieldBuilder)) *FuncBuilder

Recebimento da função

func (*FuncBuilder) RecvList

func (b *FuncBuilder) RecvList(fields []*ast.Field) *FuncBuilder

Recebimento da função

func (*FuncBuilder) Result

func (b *FuncBuilder) Result(builder func(*FieldBuilder)) *FuncBuilder

Retorno da função

func (*FuncBuilder) ResultsList

func (b *FuncBuilder) ResultsList(fields []*ast.Field) *FuncBuilder

Retorno da função

func (*FuncBuilder) SetBody

func (b *FuncBuilder) SetBody(body func(*StmtBuilder)) *FuncBuilder

Corpo da função

func (*FuncBuilder) SetBodyStmt

func (fn *FuncBuilder) SetBodyStmt(body []ast.Stmt) *FuncBuilder

Corpo da função

type References

type References struct {
	References map[string]bool
}

func NewRefer

func NewRefer() *References

func (*References) Import

func (r *References) Import(f *ast.File, builder *FileBuilder)

Importa as referências

func (*References) Name

func (r *References) Name(importSpec *ast.ImportSpec) string

Retorna o nome do pacote

type StmtBuilder

type StmtBuilder struct {
	Stmt []ast.Stmt
}

func Stmt

func Stmt(builder func(*StmtBuilder)) *StmtBuilder

Lista []ast.Stmt{}

func (*StmtBuilder) Append

func (b *StmtBuilder) Append(stmt ...ast.Stmt) *StmtBuilder

/ Adiciona um conjunto de ast.Stmt

func (*StmtBuilder) Assign

func (b *StmtBuilder) Assign(value *ExprBuilder, names ...string) *StmtBuilder

Define a variável e inicializa identifier := value

func (*StmtBuilder) AssignExpr

func (b *StmtBuilder) AssignExpr(value *ExprBuilder, identifier []ast.Expr) *StmtBuilder

Define a variável e inicializa identifier := value

func (*StmtBuilder) AssignToken

func (b *StmtBuilder) AssignToken(value ast.Expr, tok token.Token, identifier []ast.Expr) *StmtBuilder

ast.AssignStmt

func (*StmtBuilder) Define

func (b *StmtBuilder) Define(value *ExprBuilder, names ...string) *StmtBuilder

Define a variável identifier = value

func (*StmtBuilder) DefineExpr

func (b *StmtBuilder) DefineExpr(value *ExprBuilder, identifier []ast.Expr) *StmtBuilder

Define a variável identifier = value

func (*StmtBuilder) First

func (b *StmtBuilder) First() ast.Stmt

Retorna o primeiro valor

func (*StmtBuilder) Go

func (b *StmtBuilder) Go(Call *ast.CallExpr) *StmtBuilder

GoStmt: go Call (*ast.Expr)

func (*StmtBuilder) IfStmt

func (b *StmtBuilder) IfStmt(cond *ExprBuilder, body func(*StmtBuilder)) *StmtBuilder

IfStmt

func (*StmtBuilder) IfStmtExpr

func (b *StmtBuilder) IfStmtExpr(exp ast.Expr, init ast.Stmt, body *ast.BlockStmt) *StmtBuilder

IfStmt

func (*StmtBuilder) IfStmtInit

func (b *StmtBuilder) IfStmtInit(cond *ExprBuilder, init func(*StmtBuilder), body func(*StmtBuilder)) *StmtBuilder

IfStmt

func (*StmtBuilder) Include

func (b *StmtBuilder) Include(stmt *StmtBuilder) *StmtBuilder

Adiciona outro StmtBlockBuilder

func (*StmtBuilder) Return

func (b *StmtBuilder) Return(exp *ExprBuilder) *StmtBuilder

Retorno da função

func (*StmtBuilder) ReturnBlock

func (b *StmtBuilder) ReturnBlock(exp *ExprBlockBuilder) *StmtBuilder

Retorno da função

func (*StmtBuilder) Returns

func (b *StmtBuilder) Returns(exp ...ast.Expr) *StmtBuilder

Retorno da função

func (*StmtBuilder) ReturnsNames

func (b *StmtBuilder) ReturnsNames(names ...string) *StmtBuilder

Retorno da função

func (*StmtBuilder) Send

func (b *StmtBuilder) Send(Chan *ast.Expr, Value *ast.Expr) *StmtBuilder

SendStmt: Chan(*ast.Expr) <- Value (*ast.Expr)

func (*StmtBuilder) Var

func (b *StmtBuilder) Var(typeExpr ast.Expr, names ...string) *StmtBuilder

Cria uma variável var name1, name2... type

func (*StmtBuilder) VarExpr

func (b *StmtBuilder) VarExpr(typeExpr ast.Expr, names []*ast.Ident) *StmtBuilder

Cria uma variável var name1, name2... type

type StructBuilder

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

func Struct

func Struct(name string, builder func(s *StructBuilder)) *StructBuilder

Estrutura de dados

func (*StructBuilder) Field

func (b *StructBuilder) Field(builder func(*FieldBuilder)) *StructBuilder

Adiciona o campo

func (*StructBuilder) GenDecl

func (b *StructBuilder) GenDecl() *ast.GenDecl

Converte em ast.GenDecl

Jump to

Keyboard shortcuts

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