myasthurts

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 12 Imported by: 3

README

go-my-ast-hurts

A helper for dealing with Go AST

THIS IS A WORK IN PROGRESS

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NullRefType = &BaseRefType{
		name: "nil",
	}
	InterfaceRefType = &BaseRefType{
		name: "interface",
	}
)
View Source
var (
	ErrTypeNotFound             = errors.New("type not found")
	ErrBuiltInNotFound          = errors.New("builtin package not found")
	ErrPackageAliasNotFound     = errors.New("package alias not found")
	ErrUnexpectedSelector       = errors.New("unexpected selector identifier")
	ErrUnexpectedExpressionType = errors.New("unexpected expression type")
)

Functions

func NewBaseType

func NewBaseType(pkg *Package, name string) *baseType

NewBaseType creates a new initialized baseType.

func NewEnvironment

func NewEnvironment() (*environment, error)

func NewPackageContext

func NewPackageContext(pkg *Package, buildPackage *build.Package) *parsePackageContext

Types

type ArrayRefType

type ArrayRefType struct {
	RefType
}

func NewArrayRefType

func NewArrayRefType(refType RefType) *ArrayRefType

func (*ArrayRefType) AppendType

func (refType *ArrayRefType) AppendType(tp Type)

func (*ArrayRefType) Name

func (refType *ArrayRefType) Name() string

func (*ArrayRefType) Pkg

func (refType *ArrayRefType) Pkg() *Package

func (*ArrayRefType) Type

func (refType *ArrayRefType) Type() Type

type BaseRefType

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

func (*BaseRefType) AppendType

func (rt *BaseRefType) AppendType(tp Type)

AppendType add Type in RefType

func (*BaseRefType) Name

func (refType *BaseRefType) Name() string

func (*BaseRefType) Pkg

func (refType *BaseRefType) Pkg() *Package

func (*BaseRefType) Type

func (refType *BaseRefType) Type() Type

type ChanRefType

type ChanRefType struct {
	RefType
}

func NewChanRefType

func NewChanRefType(refType RefType) *ChanRefType

func (*ChanRefType) AppendType

func (refType *ChanRefType) AppendType(tp Type)

func (*ChanRefType) Name

func (refType *ChanRefType) Name() string

func (*ChanRefType) Pkg

func (refType *ChanRefType) Pkg() *Package

func (*ChanRefType) Type

func (refType *ChanRefType) Type() Type

type Constant

type Constant struct {
	Name string
	Type Type
}

type Doc

type Doc struct {
	Comments []string
}

func (*Doc) FormatComment

func (doc *Doc) FormatComment() string

FormatComment is simple method to remove // or /* */ of comment

type Ellipsis

type Ellipsis struct {
	Elt RefType
	// contains filtered or unexported fields
}

func NewEllipsis

func NewEllipsis(pkg *Package, elt RefType) *Ellipsis

func (*Ellipsis) AddMethod

func (el *Ellipsis) AddMethod(method *TypeMethod)

func (*Ellipsis) Methods

func (el *Ellipsis) Methods() []*TypeMethod

func (*Ellipsis) Name

func (el *Ellipsis) Name() string

func (*Ellipsis) Package

func (el *Ellipsis) Package() *Package

type EllipsisRefType

type EllipsisRefType struct {
	RefType
}

func NewEllipsisRefType

func NewEllipsisRefType(refType RefType) *EllipsisRefType

func (*EllipsisRefType) AppendType

func (refType *EllipsisRefType) AppendType(tp Type)

func (*EllipsisRefType) Name

func (refType *EllipsisRefType) Name() string

func (*EllipsisRefType) Pkg

func (refType *EllipsisRefType) Pkg() *Package

func (*EllipsisRefType) Type

func (refType *EllipsisRefType) Type() Type

type EnvConfig

type EnvConfig struct {
	DevMode    bool
	ASTI       bool
	CurrentDir string
}

EnvConfig is a Struct to set config in Environment

func (EnvConfig) CWD

func (ec EnvConfig) CWD() string

type Field

type Field struct {
	Name    string
	RefType RefType
	Tag     Tag
	Doc     Doc
}

Field is utilized in Struct type in the present moment.

type File

type File struct {
	Package    *Package
	FileName   string
	Doc        Doc
	Variables  []*Variable
	Constants  []*Constant
	Structs    []*Struct
	Interfaces []*Interface
	Files      []*File
}

File is utilized to represent each file read in Package.

type Interface

type Interface struct {
	Doc Doc
	// contains filtered or unexported fields
}

func NewInterface

func NewInterface(pkg *Package, name string) *Interface

NewInterface Create new Interface.

func (*Interface) AddMethod

func (t *Interface) AddMethod(method *TypeMethod)

func (*Interface) Methods

func (t *Interface) Methods() []*TypeMethod

func (*Interface) Name

func (t *Interface) Name() string

func (*Interface) Package

func (t *Interface) Package() *Package

type MapType

type MapType struct {
	Key   RefType
	Value RefType
	// contains filtered or unexported fields
}

func NewMap

func NewMap(pkg *Package, key RefType, value RefType) *MapType

func (*MapType) AddMethod

func (mt *MapType) AddMethod(method *TypeMethod)

func (*MapType) Methods

func (mt *MapType) Methods() []*TypeMethod

func (*MapType) Name

func (mt *MapType) Name() string

func (*MapType) Package

func (mt *MapType) Package() *Package

type MethodArgument

type MethodArgument struct {
	Name string
	Type RefType
	Doc  Doc
}

MethodArgument represent type of fields and arguments.

type MethodDescriptor

type MethodDescriptor struct {
	Doc       Doc
	Recv      []MethodArgument
	Arguments []MethodArgument
	Result    []MethodResult
	Tag       Tag
	// contains filtered or unexported fields
}

func NewMethodDescriptor

func NewMethodDescriptor(pkg *Package, name string) *MethodDescriptor

NewMethodDescriptor return the pointer of new MethodDescriptor

func (*MethodDescriptor) AddMethod

func (t *MethodDescriptor) AddMethod(method *TypeMethod)

func (*MethodDescriptor) Compatible

func (method *MethodDescriptor) Compatible(m *MethodDescriptor) bool

Compatible checks if the signature of both method descriptor are compatible.

It checks if the all arguments refer to the same RefType. The same happens with the result.

Receivers are not taken into consideration, neither names.

func (*MethodDescriptor) Methods

func (t *MethodDescriptor) Methods() []*TypeMethod

func (*MethodDescriptor) Name

func (method *MethodDescriptor) Name() string

Name return name of Method

func (*MethodDescriptor) Package

func (method *MethodDescriptor) Package() *Package

Package return pointer of Package

type MethodResult

type MethodResult struct {
	Name string
	Type RefType
}

type Package

type Package struct {
	Name       string
	ImportPath string
	RealPath   string
	BuildInfo  *build.Package
	Doc        Doc

	Variables []*Variable
	Constants []*Constant
	Methods   []*MethodDescriptor

	Structs    []*Struct
	Interfaces []*Interface
	RefType    []RefType

	Types       []Type
	Files       []*File
	Parent      *Package
	Subpackages []*Package
	// contains filtered or unexported fields
}

func NewPackage

func NewPackage(buildPackage *build.Package) *Package

func (*Package) AddRefType

func (p *Package) AddRefType(ref RefType)

func (*Package) AppendInterface

func (p *Package) AppendInterface(s *Interface)

AppendInterface registers a new Interface to the package.

func (*Package) AppendMethod

func (p *Package) AppendMethod(method *MethodDescriptor)

func (*Package) AppendRefType

func (p *Package) AppendRefType(name string) (ref RefType)

AppendRefType add new RefType in Package.

func (*Package) AppendStruct

func (p *Package) AppendStruct(s *Struct)

AppendStruct add new Struct in Package

func (*Package) AppendVariable

func (p *Package) AppendVariable(variable *Variable) *Variable

func (*Package) EnsureRefType

func (p *Package) EnsureRefType(name string) (RefType, bool)

EnsureRefType will try to get the RefType from the list by the name param. If the RefType exists, it will return the reference with true (second return). If it is does not exists in the list, the function will create a new type and return it with false (second return).

func (*Package) InterfaceByName

func (p *Package) InterfaceByName(name string) (*Interface, bool)

StructByName find Struct by name.

func (*Package) MethodByName

func (p *Package) MethodByName(name string) (*MethodDescriptor, bool)

func (*Package) RefTypeByName

func (p *Package) RefTypeByName(name string) (RefType, bool)

RefTypeByName find RefType by name.

func (*Package) StructByName

func (p *Package) StructByName(name string) (*Struct, bool)

StructByName find Struct by name.

func (*Package) VariableByName

func (p *Package) VariableByName(name string) (vrle *Variable)

type RefType

type RefType interface {
	Name() string
	Pkg() *Package
	Type() Type
	AppendType(t Type)
}

func NewRefType

func NewRefType(name string, pkg *Package, t Type) RefType

type StarRefType

type StarRefType struct {
	RefType
}

func NewStarRefType

func NewStarRefType(refType RefType) *StarRefType

func (*StarRefType) AppendType

func (refType *StarRefType) AppendType(tp Type)

func (*StarRefType) Name

func (refType *StarRefType) Name() string

func (*StarRefType) Pkg

func (refType *StarRefType) Pkg() *Package

func (*StarRefType) Type

func (refType *StarRefType) Type() Type

type Struct

type Struct struct {
	Doc    Doc
	Fields []*Field
	// contains filtered or unexported fields
}

func NewStruct

func NewStruct(pkg *Package, name string) *Struct

NewStruct return new pointer Struct

func (*Struct) AddMethod

func (t *Struct) AddMethod(method *TypeMethod)

func (*Struct) Implements

func (s *Struct) Implements(i *Interface) bool

Implements checks if this struct implements a given interface.

This method uses the `MethodDescriptor.Compatible` to check if all interface methods have are implemented on the struct.

TODO(jota): Take into consideration Interface composing...

func (*Struct) Methods

func (t *Struct) Methods() []*TypeMethod

func (*Struct) Name

func (s *Struct) Name() string

Name return name of Struct

func (*Struct) Package

func (s *Struct) Package() *Package

Package return pointer package of Struct

type Tag

type Tag struct {
	Raw    string
	Params []TagParam
}

func (*Tag) AppendTagParam

func (t *Tag) AppendTagParam(tNew *TagParam) bool

AppendTagParam add new TagParam in Tag

func (*Tag) TagParamByName

func (t *Tag) TagParamByName(name string) *TagParam

TagParamByName find TagParam by name.

type TagParam

type TagParam struct {
	Name    string
	Value   string
	Options []string
}

type Type

type Type interface {
	Package() *Package
	Name() string
	Methods() []*TypeMethod
	AddMethod(*TypeMethod)
}

type TypeMethod

type TypeMethod struct {
	Name       string
	Descriptor *MethodDescriptor
}

type Variable

type Variable struct {
	Name    string
	RefType RefType
	Doc     Doc
}

Directories

Path Synopsis
data

Jump to

Keyboard shortcuts

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