Documentation ¶
Overview ¶
Package astutil provides useful methods to work with ast when you intend to make a generator.
Index ¶
- func FindCtors(p *loader.PackageInfo, aboutTypes []string) map[string]*ast.FuncDecl
- func FindFilesContainingDef(p *loader.PackageInfo, s string) []*ast.File
- func FindMethods(p *loader.PackageInfo) map[string][]*ast.FuncDecl
- func FindStruct(p *loader.PackageInfo, search string) *ast.TypeSpec
- func FindTypes(p *loader.PackageInfo) []string
- func GetAnnotations(comment string, start string) map[string]string
- func GetComment(prog *loader.Program, t token.Pos) string
- func GetFastProgramLoader(s string) loader.Config
- func GetImportPath(p *loader.PackageInfo, name string) string
- func GetImportPaths(p *loader.PackageInfo, names []string) []string
- func GetPkgID(p string) string
- func GetPointedType(t string) string
- func GetProgram(s string) *loader.Program
- func GetProgramFast(s string) *loader.Program
- func GetProgramLoader(s string) loader.Config
- func GetSignatureImportIdentifiers(m *ast.FuncDecl) []string
- func GetStruct(p *loader.PackageInfo, s string) *ast.StructType
- func GetTypeToStructInit(t string) string
- func GetUnpointedType(t string) string
- func GetUnslicedType(t string) string
- func HasMethod(p *loader.PackageInfo, t, n string) bool
- func HasStruct(p *loader.PackageInfo, n string) bool
- func IsAPointedType(t string) bool
- func IsASlicedType(t string) bool
- func IsArrayType(s string) bool
- func IsBasic(t string) bool
- func IsExported(m string) bool
- func IsStarType(s string) bool
- func MethodHasEllipse(m *ast.FuncDecl) bool
- func MethodName(m *ast.FuncDecl) string
- func MethodParamNames(m *ast.FuncDecl) string
- func MethodParamNamesInvokation(m *ast.FuncDecl, withEllipse bool) string
- func MethodParamTypes(m *ast.FuncDecl) string
- func MethodParams(m *ast.FuncDecl) string
- func MethodParamsToProps(m *ast.FuncDecl) string
- func MethodReturnError(m *ast.FuncDecl) bool
- func MethodReturnNames(m *ast.FuncDecl) []string
- func MethodReturnNamesNormalized(m *ast.FuncDecl) []string
- func MethodReturnPointer(m *ast.FuncDecl) bool
- func MethodReturnTypes(m *ast.FuncDecl) []string
- func MethodReturnVars(m *ast.FuncDecl) []string
- func Print(x interface{}) string
- func PrintPkg(p *loader.PackageInfo) string
- func ReceiverName(m *ast.FuncDecl) string
- func ReceiverType(x *ast.FuncDecl) string
- func SetReceiverName(m *ast.FuncDecl, name string)
- func SetReceiverPointer(m *ast.FuncDecl, pointer bool)
- func SetReceiverTypeName(x *ast.FuncDecl, name string)
- func StructProps(s *ast.StructType) []map[string]string
- func ToString(n interface{}) string
- type StringSlice
- func (t *StringSlice) Index(s string) int
- func (t *StringSlice) InsertAt(i int, s string) *StringSlice
- func (t *StringSlice) Len() int
- func (t *StringSlice) Pop() string
- func (t *StringSlice) Push(x ...string) *StringSlice
- func (t *StringSlice) Remove(s string) bool
- func (t *StringSlice) RemoveAt(i int) bool
- func (t *StringSlice) Reverse() *StringSlice
- func (t *StringSlice) Set(x []string) *StringSlice
- func (t *StringSlice) Shift() string
- func (t *StringSlice) Slice(start int, length int) []string
- func (t *StringSlice) Splice(start int, length int, s ...string) []string
- func (t *StringSlice) Unshift(x ...string) *StringSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindFilesContainingDef ¶
func FindFilesContainingDef(p *loader.PackageInfo, s string) []*ast.File
FindFilesContainingDef given package for the files defining s.
func FindMethods ¶
func FindMethods(p *loader.PackageInfo) map[string][]*ast.FuncDecl
FindMethods searches given package for every struct methods definition
func FindStruct ¶
func FindStruct(p *loader.PackageInfo, search string) *ast.TypeSpec
FindStruct searches given package for struct matching given name
func FindTypes ¶
func FindTypes(p *loader.PackageInfo) []string
FindTypes searches given package for every struct types definition
func GetAnnotations ¶
GetAnnotations extracts annotations of a comment. start is the symbol starting an annotation. If start is @, @annotationName annotationValue
func GetComment ¶
GetComment takes an ast.Node to find its comment.
func GetFastProgramLoader ¶
GetFastProgramLoader returns a fast program loader
func GetImportPath ¶
func GetImportPath(p *loader.PackageInfo, name string) string
GetImportPath return the import path of an identifier.
func GetImportPaths ¶
func GetImportPaths(p *loader.PackageInfo, names []string) []string
GetImportPaths ...
func GetPointedType ¶
GetPointedType always return the type prefixed with a *. A pointer types is returned untouched.
func GetProgramFast ¶
GetProgramFast load program of s a pkg path
func GetProgramLoader ¶
GetProgramLoader returns a program loader.
func GetSignatureImportIdentifiers ¶
GetSignatureImportIdentifiers extract import identifers from the method signature.
func GetStruct ¶
func GetStruct(p *loader.PackageInfo, s string) *ast.StructType
GetStruct searches given package for a struct named s
func GetTypeToStructInit ¶
GetTypeToStructInit takes a type like *pkg.Struct into a &pkg.Struct{}.
func GetUnpointedType ¶
GetUnpointedType always return the dereferenced type. A non pointer types is returned untouched.
func GetUnslicedType ¶
GetUnslicedType always return the unsliced type. A non pointer types is returned untouched.
func HasMethod ¶
func HasMethod(p *loader.PackageInfo, t, n string) bool
HasMethod with name n on type t
func IsArrayType ¶
IsArrayType returns true when the given string is an []Array.
func IsBasic ¶
IsBasic return true when the given type is a basic string... The type is always dereferenced.
func IsStarType ¶
IsStarType returns true when the given string is a *Star.
func MethodHasEllipse ¶
MethodHasEllipse returns true if last param has ellipse.
func MethodParamNames ¶
MethodParamNames reutrns the list of variable in the in signature.
func MethodParamNamesInvokation ¶
MethodParamNamesInvokation reutrns the list of variable in the in signature as an invokation. If withEllipse is true, the last argument gets uses with the ellipse token.
func MethodParamTypes ¶
MethodParamTypes reutrns the list of variable type in the in signature.
func MethodParams ¶
MethodParams returns the in signature.
func MethodParamsToProps ¶
MethodParamsToProps returns the in signature as property list.
func MethodReturnError ¶
MethodReturnError returns true if the last out param is of type error.
func MethodReturnNames ¶
MethodReturnNames returns all names of the out signature.
func MethodReturnNamesNormalized ¶
MethodReturnNamesNormalized returns all names of the out signature.
func MethodReturnPointer ¶
MethodReturnPointer returns true if the func returns a pointer.
func MethodReturnTypes ¶
MethodReturnTypes returns all types of the out signature.
func MethodReturnVars ¶
MethodReturnVars create a list of of unqiue variables for each param of out signature.
func PrintPkg ¶
func PrintPkg(p *loader.PackageInfo) string
PrintPkg all files of a package to string.
func ReceiverName ¶
ReceiverName returns the receiver variable name.
func ReceiverType ¶
ReceiverType returns the type of the receiver in a method.
func SetReceiverName ¶
SetReceiverName sets the receiver variable name of a method.
func SetReceiverPointer ¶
SetReceiverPointer makes sure the receiver type is a pointer.
func SetReceiverTypeName ¶
SetReceiverTypeName sets the type of the receiver.
func StructProps ¶
func StructProps(s *ast.StructType) []map[string]string
StructProps returns all props and their types of type s.
Types ¶
type StringSlice ¶
type StringSlice []string
StringSlice implements a typed slice of string
func NewStringSlice ¶
func NewStringSlice() *StringSlice
NewStringSlice creates a new typed slice of string
func (*StringSlice) Index ¶
func (t *StringSlice) Index(s string) int
Index of given string. It must implements Ider interface.
func (*StringSlice) InsertAt ¶
func (t *StringSlice) InsertAt(i int, s string) *StringSlice
InsertAt adds given string at index i
func (*StringSlice) Pop ¶
func (t *StringSlice) Pop() string
Pop removes then reutrns the last string.
func (*StringSlice) Push ¶
func (t *StringSlice) Push(x ...string) *StringSlice
Push appends every string
func (*StringSlice) Remove ¶
func (t *StringSlice) Remove(s string) bool
Remove removes given string
func (*StringSlice) RemoveAt ¶
func (t *StringSlice) RemoveAt(i int) bool
RemoveAt removes a string at index i.
func (*StringSlice) Shift ¶
func (t *StringSlice) Shift() string
Shift removes then reutrns the first string.
func (*StringSlice) Slice ¶
func (t *StringSlice) Slice(start int, length int) []string
Slice returns a copied slice of string, starting at start, ending at start+length.
func (*StringSlice) Splice ¶
func (t *StringSlice) Splice(start int, length int, s ...string) []string
Splice removes and returns a slice of string, starting at start, ending at start+length. If any s is provided, they are inserted in place of the removed slice.
func (*StringSlice) Unshift ¶
func (t *StringSlice) Unshift(x ...string) *StringSlice
Unshift prepends every string