astutil

package module
v0.0.0-...-db497c1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 11 Imported by: 5

README

astutil

Go Report Card GoDoc MIT License

Package astutil provides useful methods to work with ast when you intend to make a generator.

TOC

Install

go get github.com/mh-cbon/astutil

API

Please check the godoc: GoDoc

Recipes

Release the project
gump patch -d # check
gump patch # bump

History

CHANGELOG

Documentation

Overview

Package astutil provides useful methods to work with ast when you intend to make a generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindCtors

func FindCtors(p *loader.PackageInfo, aboutTypes []string) map[string]*ast.FuncDecl

FindCtors searches given package for every ctors of given struct list.

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

func GetAnnotations(comment string, start string) map[string]string

GetAnnotations extracts annotations of a comment. start is the symbol starting an annotation. If start is @, @annotationName annotationValue

func GetComment

func GetComment(prog *loader.Program, t token.Pos) string

GetComment takes an ast.Node to find its comment.

func GetFastProgramLoader

func GetFastProgramLoader(s string) loader.Config

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 GetPkgID

func GetPkgID(p string) string

GetPkgID extract the pkg id in pkg.identifier

func GetPointedType

func GetPointedType(t string) string

GetPointedType always return the type prefixed with a *. A pointer types is returned untouched.

func GetProgram

func GetProgram(s string) *loader.Program

GetProgram load program of s a pkg path

func GetProgramFast

func GetProgramFast(s string) *loader.Program

GetProgramFast load program of s a pkg path

func GetProgramLoader

func GetProgramLoader(s string) loader.Config

GetProgramLoader returns a program loader.

func GetSignatureImportIdentifiers

func GetSignatureImportIdentifiers(m *ast.FuncDecl) []string

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

func GetTypeToStructInit(t string) string

GetTypeToStructInit takes a type like *pkg.Struct into a &pkg.Struct{}.

func GetUnpointedType

func GetUnpointedType(t string) string

GetUnpointedType always return the dereferenced type. A non pointer types is returned untouched.

func GetUnslicedType

func GetUnslicedType(t string) string

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 HasStruct

func HasStruct(p *loader.PackageInfo, n string) bool

HasStruct with name n

func IsAPointedType

func IsAPointedType(t string) bool

IsAPointedType returns true for starType.

func IsASlicedType

func IsASlicedType(t string) bool

IsASlicedType returns true for sliceType.

func IsArrayType

func IsArrayType(s string) bool

IsArrayType returns true when the given string is an []Array.

func IsBasic

func IsBasic(t string) bool

IsBasic return true when the given type is a basic string... The type is always dereferenced.

func IsExported

func IsExported(m string) bool

IsExported name.

func IsStarType

func IsStarType(s string) bool

IsStarType returns true when the given string is a *Star.

func MethodHasEllipse

func MethodHasEllipse(m *ast.FuncDecl) bool

MethodHasEllipse returns true if last param has ellipse.

func MethodName

func MethodName(m *ast.FuncDecl) string

MethodName returns the name of given func

func MethodParamNames

func MethodParamNames(m *ast.FuncDecl) string

MethodParamNames reutrns the list of variable in the in signature.

func MethodParamNamesInvokation

func MethodParamNamesInvokation(m *ast.FuncDecl, withEllipse bool) string

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

func MethodParamTypes(m *ast.FuncDecl) string

MethodParamTypes reutrns the list of variable type in the in signature.

func MethodParams

func MethodParams(m *ast.FuncDecl) string

MethodParams returns the in signature.

func MethodParamsToProps

func MethodParamsToProps(m *ast.FuncDecl) string

MethodParamsToProps returns the in signature as property list.

func MethodReturnError

func MethodReturnError(m *ast.FuncDecl) bool

MethodReturnError returns true if the last out param is of type error.

func MethodReturnNames

func MethodReturnNames(m *ast.FuncDecl) []string

MethodReturnNames returns all names of the out signature.

func MethodReturnNamesNormalized

func MethodReturnNamesNormalized(m *ast.FuncDecl) []string

MethodReturnNamesNormalized returns all names of the out signature.

func MethodReturnPointer

func MethodReturnPointer(m *ast.FuncDecl) bool

MethodReturnPointer returns true if the func returns a pointer.

func MethodReturnTypes

func MethodReturnTypes(m *ast.FuncDecl) []string

MethodReturnTypes returns all types of the out signature.

func MethodReturnVars

func MethodReturnVars(m *ast.FuncDecl) []string

MethodReturnVars create a list of of unqiue variables for each param of out signature.

func Print

func Print(x interface{}) string

Print any node x to string

func PrintPkg

func PrintPkg(p *loader.PackageInfo) string

PrintPkg all files of a package to string.

func ReceiverName

func ReceiverName(m *ast.FuncDecl) string

ReceiverName returns the receiver variable name.

func ReceiverType

func ReceiverType(x *ast.FuncDecl) string

ReceiverType returns the type of the receiver in a method.

func SetReceiverName

func SetReceiverName(m *ast.FuncDecl, name string)

SetReceiverName sets the receiver variable name of a method.

func SetReceiverPointer

func SetReceiverPointer(m *ast.FuncDecl, pointer bool)

SetReceiverPointer makes sure the receiver type is a pointer.

func SetReceiverTypeName

func SetReceiverTypeName(x *ast.FuncDecl, name string)

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.

func ToString

func ToString(n interface{}) string

ToString takes an ast.Node and print it to string. It does not accept nil values, please check it ahead.

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) Len

func (t *StringSlice) Len() int

Len of the slice.

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) Reverse

func (t *StringSlice) Reverse() *StringSlice

Reverse the slice.

func (*StringSlice) Set

func (t *StringSlice) Set(x []string) *StringSlice

Set the slice.

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

Jump to

Keyboard shortcuts

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