Documentation ¶
Index ¶
- func CamelCase(s string) string
- func CloneCommentGroup(firstLF bool, c *ast.CommentGroup) *ast.CommentGroup
- func CloneExpr(e ast.Expr) ast.Expr
- func CloneIdent(src []*ast.Ident) []*ast.Ident
- func FromComment(c *ast.CommentGroup) []string
- func IdentEmptyString() *ast.Ident
- func IdentErr() *ast.Ident
- func IdentError() *ast.Ident
- func IdentName(vs []*ast.Ident) string
- func IdentNil() *ast.Ident
- func ImportName(s *ast.ImportSpec) string
- func ImportPath(s *ast.ImportSpec) string
- func JoinCase(s string, delimiter byte) string
- func Kebab(str string) string
- func LowTitle(s string) string
- func NewBinaryExpr(tok token.Token, x, y ast.Expr) *ast.BinaryExpr
- func NewBlockStmt(stmts ...ast.Stmt) *ast.BlockStmt
- func NewCallExpr(fun ast.Expr, args ...ast.Expr) *ast.CallExpr
- func NewComment(firstLF bool, comments ...string) []*ast.Comment
- func NewCommentGroup(firstLF bool, comments ...string) *ast.CommentGroup
- func NewDeclStmt(decl ast.Decl) *ast.DeclStmt
- func NewEllipsis(elt ast.Expr) *ast.Ellipsis
- func NewExprStmt(x ast.Expr) *ast.ExprStmt
- func NewFieldFuncField(name string, typ ast.Expr) *ast.Field
- func NewFieldUnameFuncField(typ ast.Expr) *ast.Field
- func NewFuncDecl(name string, typ *ast.FuncType, body *ast.BlockStmt, opts ...Option) *ast.FuncDecl
- func NewFuncLit(ft *ast.FuncType, body *ast.BlockStmt) *ast.FuncLit
- func NewGenDeclReferenceVariable(x, sel string, opt ...Option) *ast.GenDecl
- func NewIdent(name string) *ast.Ident
- func NewImportSpec(name, path string, opts ...Option) *ast.ImportSpec
- func NewIndexExpr(x, index ast.Expr) *ast.IndexExpr
- func NewIndexListExpr(x ast.Expr, indices ...ast.Expr) *ast.IndexListExpr
- func NewInterfaceType(fields ...*ast.Field) *ast.InterfaceType
- func NewKeyValueExpr(key, value ast.Expr) *ast.KeyValueExpr
- func NewLitChar(v string) *ast.BasicLit
- func NewLitFloat(v string) *ast.BasicLit
- func NewLitImag(v string) *ast.BasicLit
- func NewLitInt(v string) *ast.BasicLit
- func NewLitString(v string) *ast.BasicLit
- func NewMethodDecl(name string, recv *ast.Field, typ *ast.FuncType, body *ast.BlockStmt, ...) *ast.FuncDecl
- func NewParenExpr(x ast.Expr) *ast.ParenExpr
- func NewReturnStmt(expr ...ast.Expr) *ast.ReturnStmt
- func NewSelectorExpr(x ast.Expr, sel string) *ast.SelectorExpr
- func NewStarExpr(x ast.Expr) *ast.StarExpr
- func NewStructType(fields ...*ast.Field) *ast.StructType
- func NewTypeAssertExpr(x ast.Expr, tpy ast.Expr) *ast.TypeAssertExpr
- func NewTypeSpec(name string, typ ast.Expr, opts ...Option) *ast.TypeSpec
- func NewUnameFuncDecl(typ *ast.FuncType, body *ast.BlockStmt, opts ...Option) *ast.FuncDecl
- func NewUnaryExpr(op token.Token, x ast.Expr) *ast.UnaryExpr
- func NewValueSpecReferenceVariable(x, sel string, opts ...Option) *ast.ValueSpec
- func PkgName(path string) string
- func ReplaceInitialism(s string) string
- func SmallCamelCase(fieldName string) string
- func SnakeCase(str string) string
- func SplitCase(str string, delimiter byte) string
- func UnStar(e ast.Expr) ast.Expr
- type Applier
- type AssignStmtBuilder
- type BlockStmtBuilder
- type ChainExprBUilder
- func (b *ChainExprBUilder) Binary(tok token.Token, y ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) Build() ast.Expr
- func (b *ChainExprBUilder) Call(args ...ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) Ellipsis() *ChainExprBUilder
- func (b *ChainExprBUilder) Index(index ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) IndexList(indices ...ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) KeyValue(value ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) Paren() *ChainExprBUilder
- func (b *ChainExprBUilder) Selector(sel string) *ChainExprBUilder
- func (b *ChainExprBUilder) Star() *ChainExprBUilder
- func (b *ChainExprBUilder) TypeAssert(typ ast.Expr) *ChainExprBUilder
- func (b *ChainExprBUilder) Unary(tok token.Token) *ChainExprBUilder
- type FieldBuilder
- func (b *FieldBuilder) Comment(comment *ast.CommentGroup) *FieldBuilder
- func (b *FieldBuilder) Doc(comment *ast.CommentGroup) *FieldBuilder
- func (b *FieldBuilder) FuncField() *ast.Field
- func (b *FieldBuilder) Name(name string) *FieldBuilder
- func (b *FieldBuilder) StructField() *ast.Field
- func (b *FieldBuilder) Tag(v string) *FieldBuilder
- type File
- type FuncTypeBuilder
- type GenDeclBuilder
- type IfStmtBuilder
- type ImportMgr
- func (g *ImportMgr) AddImport(path string, opts ...Option) (added bool)
- func (g *ImportMgr) AddNamedImport(name, path string, opts ...Option) (added bool)
- func (g *ImportMgr) GetNamedImport(name string) (path string, existed bool)
- func (g *ImportMgr) Imports() []*ast.ImportSpec
- func (g *ImportMgr) Iter(f func(name, path string) bool)
- func (g *ImportMgr) IterNamedImport(f func(name, path string) bool)
- func (g *ImportMgr) Len() int
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCase ¶
CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.
func CloneCommentGroup ¶
func CloneCommentGroup(firstLF bool, c *ast.CommentGroup) *ast.CommentGroup
func FromComment ¶
func FromComment(c *ast.CommentGroup) []string
func ImportName ¶
func ImportName(s *ast.ImportSpec) string
ImportName returns the name of s, or "" if the import is not named.
func ImportPath ¶
func ImportPath(s *ast.ImportSpec) string
ImportPath returns the unquoted import path of s, or "" if the path is not properly quoted.
func Kebab ¶
Kebab 转换驼峰字符串为用'-'分隔的字符串 example2: delimiter = '-' initialisms = DefaultInitialisms IdCom -> id-com Idcom -> idcom nameIdCom -> name-id-com nameIdcom -> name-idcom
func NewBinaryExpr ¶
func NewComment ¶
NewComment creates a new comment list
func NewCommentGroup ¶
func NewCommentGroup(firstLF bool, comments ...string) *ast.CommentGroup
NewCommentGroup creates a new comment group
func NewDeclStmt ¶
NewDeclStmt *GenDecl with CONST, TYPE, or VAR token
func NewFieldFuncField ¶
shortcuts NewField(typ).Name(name).FuncField()
func NewFieldUnameFuncField ¶
shortcuts NewField(typ).FuncField()
func NewFuncDecl ¶
func NewGenDeclReferenceVariable ¶
var _ = context.TODO
func NewImportSpec ¶
func NewImportSpec(name, path string, opts ...Option) *ast.ImportSpec
NewImportSpec new the import with the given name and path to the file f, if absent. If name is empty, use PkgName(path).
import fmt "fmt"
func NewIndexListExpr ¶
func NewInterfaceType ¶
func NewInterfaceType(fields ...*ast.Field) *ast.InterfaceType
func NewKeyValueExpr ¶
func NewKeyValueExpr(key, value ast.Expr) *ast.KeyValueExpr
func NewLitChar ¶
func NewLitFloat ¶
func NewLitImag ¶
func NewLitString ¶
func NewMethodDecl ¶
func NewReturnStmt ¶
func NewReturnStmt(expr ...ast.Expr) *ast.ReturnStmt
func NewSelectorExpr ¶
func NewSelectorExpr(x ast.Expr, sel string) *ast.SelectorExpr
func NewStructType ¶
func NewStructType(fields ...*ast.Field) *ast.StructType
func NewTypeAssertExpr ¶
tpy: asserted type; nil means type switch X.(type)
func NewUnameFuncDecl ¶
func NewValueSpecReferenceVariable ¶
NewValueSpecReferenceVariable format: `_ = context.TODO`, `_ = errors.New`
func PkgName ¶
PkgName returns the package name from a Go path with a package qualifier. github.com/{{owner}}/{{package}} -> {{package}}
func ReplaceInitialism ¶
ReplaceInitialism replaces the initialism. see `defaultInitialisms` ID -> Id API -> Api APIRequest-> ApiRequest
func SmallCamelCase ¶
SmallCamelCase to small camel case string id_com -> idCom idcom -> idcom name_id_com -> nameIdCom name_idcom -> nameIdcom
func SnakeCase ¶
SnakeCase 转换驼峰字符串为用'_'分隔的字符串 example2: delimiter = '_' initialisms = DefaultInitialisms IdCom -> id_com Idcom -> idcom nameIdCom -> name_id_com nameIdcom -> name_idcom
Types ¶
type AssignStmtBuilder ¶
type AssignStmtBuilder struct {
// contains filtered or unexported fields
}
func NewAssignStmt ¶
func NewAssignStmt() *AssignStmtBuilder
func NewShortVarDeclStmt ¶
func NewShortVarDeclStmt() *AssignStmtBuilder
func (*AssignStmtBuilder) Build ¶
func (b *AssignStmtBuilder) Build() *ast.AssignStmt
func (*AssignStmtBuilder) Lhs ¶
func (b *AssignStmtBuilder) Lhs(lhs ...ast.Expr) *AssignStmtBuilder
func (*AssignStmtBuilder) Rhs ¶
func (b *AssignStmtBuilder) Rhs(rhs ...ast.Expr) *AssignStmtBuilder
type BlockStmtBuilder ¶
type BlockStmtBuilder struct {
// contains filtered or unexported fields
}
func NewBlockStmtBuilder ¶
func NewBlockStmtBuilder(stmts ...ast.Stmt) *BlockStmtBuilder
func (*BlockStmtBuilder) Build ¶
func (b *BlockStmtBuilder) Build() *ast.BlockStmt
func (*BlockStmtBuilder) Stmt ¶
func (b *BlockStmtBuilder) Stmt(stmts ...ast.Stmt) *BlockStmtBuilder
type ChainExprBUilder ¶
type ChainExprBUilder struct {
// contains filtered or unexported fields
}
func NewChainExpr ¶
func NewChainExpr(inner ast.Expr) *ChainExprBUilder
func NewChainExprIdent ¶
func NewChainExprIdent(name string) *ChainExprBUilder
shortcut NewChainExpr(ast.NewIdent(name))
func (*ChainExprBUilder) Binary ¶
func (b *ChainExprBUilder) Binary(tok token.Token, y ast.Expr) *ChainExprBUilder
func (*ChainExprBUilder) Build ¶
func (b *ChainExprBUilder) Build() ast.Expr
func (*ChainExprBUilder) Call ¶
func (b *ChainExprBUilder) Call(args ...ast.Expr) *ChainExprBUilder
func (*ChainExprBUilder) Ellipsis ¶
func (b *ChainExprBUilder) Ellipsis() *ChainExprBUilder
func (*ChainExprBUilder) Index ¶
func (b *ChainExprBUilder) Index(index ast.Expr) *ChainExprBUilder
func (*ChainExprBUilder) IndexList ¶
func (b *ChainExprBUilder) IndexList(indices ...ast.Expr) *ChainExprBUilder
func (*ChainExprBUilder) KeyValue ¶
func (b *ChainExprBUilder) KeyValue(value ast.Expr) *ChainExprBUilder
func (*ChainExprBUilder) Paren ¶
func (b *ChainExprBUilder) Paren() *ChainExprBUilder
func (*ChainExprBUilder) Selector ¶
func (b *ChainExprBUilder) Selector(sel string) *ChainExprBUilder
func (*ChainExprBUilder) Star ¶
func (b *ChainExprBUilder) Star() *ChainExprBUilder
func (*ChainExprBUilder) TypeAssert ¶
func (b *ChainExprBUilder) TypeAssert(typ ast.Expr) *ChainExprBUilder
tpy: asserted type; nil means type switch X.(type)
func (*ChainExprBUilder) Unary ¶
func (b *ChainExprBUilder) Unary(tok token.Token) *ChainExprBUilder
type FieldBuilder ¶
type FieldBuilder struct {
// contains filtered or unexported fields
}
func NewField ¶
func NewField(typ ast.Expr) *FieldBuilder
NewField function/method filed syntax: `a time.Time`, `a,b time.Time`, `time.Time` struct field syntax: `a time.Time`, `a,b time.Time`, `time.Time`
func (*FieldBuilder) Comment ¶
func (b *FieldBuilder) Comment(comment *ast.CommentGroup) *FieldBuilder
func (*FieldBuilder) Doc ¶
func (b *FieldBuilder) Doc(comment *ast.CommentGroup) *FieldBuilder
func (*FieldBuilder) FuncField ¶
func (b *FieldBuilder) FuncField() *ast.Field
func (*FieldBuilder) Name ¶
func (b *FieldBuilder) Name(name string) *FieldBuilder
func (*FieldBuilder) StructField ¶
func (b *FieldBuilder) StructField() *ast.Field
func (*FieldBuilder) Tag ¶
func (b *FieldBuilder) Tag(v string) *FieldBuilder
type File ¶
type File struct { Filename string // filename of the file Doc *ast.CommentGroup // package comment Name string // package name Imports *ImportMgr // package import manager GenDecl []ast.Decl // top-level generic declarations(token.CONST, token.TYPE, token.VAR); or nil Decls []ast.Decl // top-level declarations }
type FuncTypeBuilder ¶
type FuncTypeBuilder struct {
// contains filtered or unexported fields
}
func NewFuncType ¶
func NewFuncType() *FuncTypeBuilder
func (*FuncTypeBuilder) Build ¶
func (b *FuncTypeBuilder) Build() *ast.FuncType
func (*FuncTypeBuilder) Param ¶
func (b *FuncTypeBuilder) Param(f ...*ast.Field) *FuncTypeBuilder
func (*FuncTypeBuilder) Result ¶
func (b *FuncTypeBuilder) Result(f ...*ast.Field) *FuncTypeBuilder
type GenDeclBuilder ¶
type GenDeclBuilder struct {
// contains filtered or unexported fields
}
func NewGenDecl ¶
func NewGenDecl(tok token.Token, spec ...ast.Spec) *GenDeclBuilder
NewGenDecl * tok: IMPORT, CONST, TYPE, or VAR
func NewGenDeclConst ¶
func NewGenDeclConst(spec ...ast.Spec) *GenDeclBuilder
func NewGenDeclImport ¶
func NewGenDeclImport(spec ...ast.Spec) *GenDeclBuilder
func NewGenDeclType ¶
func NewGenDeclType(spec ...ast.Spec) *GenDeclBuilder
func NewGenDeclVar ¶
func NewGenDeclVar(spec ...ast.Spec) *GenDeclBuilder
func (*GenDeclBuilder) Build ¶
func (b *GenDeclBuilder) Build() *ast.GenDecl
func (*GenDeclBuilder) Doc ¶
func (b *GenDeclBuilder) Doc(c *ast.CommentGroup) *GenDeclBuilder
func (*GenDeclBuilder) Spec ¶
func (b *GenDeclBuilder) Spec(spec ...ast.Spec) *GenDeclBuilder
type IfStmtBuilder ¶
type IfStmtBuilder struct {
// contains filtered or unexported fields
}
func NewIfStmt ¶
func NewIfStmt() *IfStmtBuilder
func (*IfStmtBuilder) Body ¶
func (b *IfStmtBuilder) Body(v *ast.BlockStmt) *IfStmtBuilder
func (*IfStmtBuilder) Build ¶
func (b *IfStmtBuilder) Build() *ast.IfStmt
func (*IfStmtBuilder) Cond ¶
func (b *IfStmtBuilder) Cond(v ast.Expr) *IfStmtBuilder
func (*IfStmtBuilder) Else ¶
func (b *IfStmtBuilder) Else(v ast.Stmt) *IfStmtBuilder
func (*IfStmtBuilder) Init ¶
func (b *IfStmtBuilder) Init(v ast.Stmt) *IfStmtBuilder
type ImportMgr ¶
type ImportMgr struct {
// contains filtered or unexported fields
}
func NewImportMgr ¶
func NewImportMgr() *ImportMgr
func (*ImportMgr) AddNamedImport ¶
func (*ImportMgr) GetNamedImport ¶
func (*ImportMgr) Imports ¶
func (g *ImportMgr) Imports() []*ast.ImportSpec
func (*ImportMgr) IterNamedImport ¶
type Option ¶
type Option func(Applier)
func WithComment ¶
func WithComment(c *ast.CommentGroup) Option
func WithDocComment ¶
func WithDocComment(c *ast.CommentGroup) Option