Documentation ¶
Index ¶
- func Implements(t Type, interfaceType *Interface) bool
- func IsEmptyInterface(tp Type) bool
- type Alias
- func (a *Alias) Elem() Type
- func (a *Alias) Equal(another Type) bool
- func (a *Alias) FullName() string
- func (a *Alias) Implements(interfaceType *Interface, isPointer bool) bool
- func (a *Alias) Kind() Kind
- func (a *Alias) Name(identified bool, packageContext string) string
- func (a *Alias) Package() *Package
- func (a Alias) String() string
- func (a *Alias) Zero(identified bool, packageContext string) string
- type Array
- type BuiltInType
- type Chan
- type ChanDir
- type Declaration
- type FuncParam
- type Function
- func (f *Function) Elem() Type
- func (f *Function) Equal(another Type) bool
- func (f *Function) FullName() string
- func (f *Function) Kind() Kind
- func (f Function) Name(identified bool, packageContext string) string
- func (f *Function) Package() *Package
- func (f Function) String() string
- func (f *Function) Zero(_ bool, _ string) string
- type Interface
- func (i *Interface) Elem() Type
- func (i *Interface) Equal(another Type) bool
- func (i Interface) FullName() string
- func (i *Interface) Implements(another *Interface) bool
- func (i *Interface) IsEmpty() bool
- func (i *Interface) Kind() Kind
- func (i Interface) Name(identified bool, packageContext string) string
- func (i *Interface) Package() *Package
- func (i Interface) String() string
- func (i Interface) Zero(_ bool, _ string) string
- type Kind
- type Map
- type Package
- func (p *Package) GetAlias(name string) (*Alias, bool)
- func (p *Package) GetFunction(name string) (*Function, bool)
- func (p *Package) GetInterfaceType(name string) (*Interface, bool)
- func (p *Package) GetPkgPath() PkgPath
- func (p *Package) GetStruct(name string) (*Struct, bool)
- func (p *Package) GetType(name string) (Type, bool)
- func (p *Package) IsStandard() bool
- func (p *Package) MustFunction(name string) *Function
- func (p *Package) MustGetType(name string) Type
- func (p *Package) MustStruct(name string) *Struct
- func (p *Package) NewConstant(name string, tp Type, value constant.Value) error
- func (p *Package) NewNamedType(name string, namedType Type) error
- func (p *Package) NewVariable(name string, tp Type) error
- func (p *Package) SetIdentifier(s string)
- func (p *Package) SetNamedType(name string, tp Type)
- func (p *Package) TypeOf(name string) (Type, bool)
- type PackageMap
- func (p PackageMap) MustGetByPath(path string) *Package
- func (p PackageMap) NewPackage(name, identifier string) (*Package, error)
- func (p PackageMap) PackageByIdentifier(identifier string) (*Package, bool)
- func (p PackageMap) PackageByPath(path string) (*Package, bool)
- func (p *PackageMap) TypeOf(typeOf string, packageContext *Package) (Type, bool)
- type Packager
- type PkgPath
- type Pointer
- type Receiver
- type Struct
- func (s *Struct) Elem() Type
- func (s *Struct) Equal(another Type) bool
- func (s *Struct) FullName() string
- func (s *Struct) Implements(interfaceType *Interface, pointer bool) bool
- func (s *Struct) Kind() Kind
- func (s *Struct) Name(identifier bool, packageContext string) string
- func (s *Struct) Package() *Package
- func (s *Struct) String() string
- func (s *Struct) Zero(identified bool, packageContext string) string
- type StructField
- type StructTag
- type StructTagTuple
- type StructTagTuples
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Implements ¶
Implements checks if the type t implements interface 'interfaceType'.
func IsEmptyInterface ¶
IsEmptyInterface checks if the input type is an empty interface.
Types ¶
type Alias ¶
Alias is the type that represents wrapped and named another type. I.e.: 'type Custom int' would be an Alias over BuiltIn(int) type.
func (*Alias) Implements ¶ added in v0.1.0
Implements checks if the alias types implements provided interface. The argument isPointer states if given the pointer to alias or an alias by itself implements given interface.
type Array ¶
type Array struct { ArrayKind Kind // Could be either KindSlice or KindArray Type Type ArraySize int }
Array is the array or slice representing type.
type BuiltInType ¶
type BuiltInType struct {
BuiltInKind Kind
}
BuiltInType is the built in type definition.
func (*BuiltInType) Equal ¶
func (b *BuiltInType) Equal(another Type) bool
Equal checks if given built in type is equal to another Type.
func (*BuiltInType) FullName ¶
func (b *BuiltInType) FullName() string
FullName implements Type interface.
func (*BuiltInType) Name ¶
func (b *BuiltInType) Name(_ bool, _ string) string
Name implements Type interface.
func (BuiltInType) String ¶
func (b BuiltInType) String() string
KindString implements Type interface.
type Chan ¶
Chan is the type representing channel.
type ChanDir ¶
type ChanDir int
A ChanDir value indicates a channel direction.
The direction of a channel is indicated by one of these constants.
type Declaration ¶
type Declaration struct { Comment string Name string Type Type Constant bool Val constant.Value Package *Package }
Declaration is the variable or constant declaration.
func (Declaration) ConstValue ¶ added in v0.1.0
func (d Declaration) ConstValue() interface{}
ConstValue gets the basic value of given constant declaration type. The method panics if the Declaration is not a constant but variable. For selected field kind it returns following Value Types:
- KindString - string
- KindBool - bool
- KindInt, KindInt8, KindInt16, KindInt32, KindInt64: - int
- KindUint, KindUint8, KindUint16, KindUint32, KindUint64: - uint
- KindFloat64, KindFloat32: - float64
- KindComplex64, KindComplex128: - complex128
func (Declaration) String ¶ added in v0.1.0
func (d Declaration) String() string
String provides a string visual form of the declaration.
type Function ¶
type Function struct { Comment string Pkg *Package Receiver *Receiver FuncName string In []FuncParam Out []FuncParam Variadic bool }
Function is the function type used for getting.
type Interface ¶
Interface is the interface type model definition.
func (*Interface) Implements ¶
Implements checks if given interface implements another interface.
type Kind ¶
type Kind uint
A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
const ( Invalid Kind = iota KindBool KindInt KindInt8 KindInt16 KindInt32 KindInt64 KindUint KindUint8 KindUint16 KindUint32 KindUint64 KindUintptr KindFloat32 KindFloat64 KindComplex64 KindComplex128 KindString KindArray KindChan KindFunc KindInterface KindMap KindPtr KindSlice KindStruct KindUnsafePointer )
Enumerated kind representations.
func (Kind) BuiltInName ¶
BuiltInName gets the name of the builtin kind.
type Map ¶
Map is the type wrapper for the standar key value map type.
type Package ¶
type Package struct { Path string Identifier string Interfaces []*Interface Structs []*Struct Functions []*Function Aliases []*Alias Types map[string]Type Declarations map[string]Declaration sync.Mutex }
Package is the golang package reflection container. It contains all interfaces, structs, functions and type wrappers that are located inside of it.
func NewPackage ¶
NewPackage creates new package definition.
func (*Package) GetFunction ¶
GetFunction gets the function type by it's name.
func (*Package) GetInterfaceType ¶
GetInterfaceType gets the interface by it's name.
func (*Package) GetPkgPath ¶
GetPkgPath gets the PkgPath for given package.
func (*Package) IsStandard ¶
IsStandard checks if given package is a standard package.
func (*Package) MustFunction ¶
MustFunction gets the function declaration with the 'name'. If the function is not found it panics.
func (*Package) MustGetType ¶
MustGetType get the type with given 'name' from given package. If the type is not found the function panics.
func (*Package) MustStruct ¶
MustStruct gets the struct declaration with the 'name'. If the struct is not found it panics.
func (*Package) NewConstant ¶
NewConstant adds new package constant Declaration.
func (*Package) NewNamedType ¶
NewNamedType adds new named type to the package definition.
func (*Package) NewVariable ¶
NewVariable adds new package variable Declaration.
func (*Package) SetIdentifier ¶
SetIdentifier sets the package identifier.
func (*Package) SetNamedType ¶
SetNamedType sets the type with given name to be stored withing given package.
type PackageMap ¶
PackageMap is a slice wrapper over Package type.
func (PackageMap) MustGetByPath ¶
func (p PackageMap) MustGetByPath(path string) *Package
func (PackageMap) NewPackage ¶
func (p PackageMap) NewPackage(name, identifier string) (*Package, error)
NewPackage creates new package definition in given package map.
func (PackageMap) PackageByIdentifier ¶
func (p PackageMap) PackageByIdentifier(identifier string) (*Package, bool)
PackageByIdentifier gets the package by provided identifier. If there is more than one package with given identifier The function would return the first matching package.
func (PackageMap) PackageByPath ¶
func (p PackageMap) PackageByPath(path string) (*Package, bool)
PackageByPath gets the package by provided path.
type Packager ¶
type Packager interface { // Package gets the Package for given type. Package() *Package }
Packager is the interface that allows to get Type packages. Only the Types that contains the name stores the Package i.e.: Struct, Interface, Alias, Function.
type PkgPath ¶
type PkgPath string
PkgPath is the string package that contains full package name.
func (PkgPath) Identifier ¶
Identifier gets package identifier.
func (PkgPath) IsStandard ¶
IsStandard checks if the package is standard.
type Pointer ¶
type Pointer struct {
PointedType Type
}
Pointer is the type implementation that defines pointer type.
type Receiver ¶
Receiver is the function (method) receiver with the name and a pointer flag.
type Struct ¶
type Struct struct { Pkg *Package Comment string TypeName string Fields []StructField Methods []Function }
Struct is the struct type reflection.
func (*Struct) Implements ¶
Implements checks if given structure implements provided interface.
type StructField ¶
type StructField struct { Name string Comment string Type Type Tag StructTag Index []int Embedded bool Anonymous bool }
StructField is a structure field model.
func (StructField) String ¶
func (s StructField) String() string
KindString implements fmt.Stringer interface.
type StructTag ¶
type StructTag string
A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.
func (StructTag) Get ¶
Get returns the value associated with key in the tag string. If there is no such key in the tag, Get returns the empty string. If the tag does not have the conventional format, the value returned by Get is unspecified. To determine whether a tag is explicitly set to the empty string, use Lookup.
func (StructTag) Lookup ¶
Lookup returns the value associated with key in the tag string. If the key is present in the tag the value (which may be empty) is returned. Otherwise the returned value will be the empty string. The ok return value reports whether the value was explicitly set in the tag string. If the tag does not have the conventional format, the value returned by Lookup is unspecified.
func (StructTag) Split ¶
func (tag StructTag) Split() (tuples StructTagTuples)
Split splits up the struct tag into key, value tuples.
type StructTagTuple ¶
type StructTagTuple struct {
Key, Value string
}
StructTagTuple is a tuple key,value for the struct tag.
type StructTagTuples ¶
type StructTagTuples []StructTagTuple
StructTagTuples is the slice alias over the the structTag key, value tuples. It is used to recreate the StructTag.
func (StructTagTuples) Join ¶
func (s StructTagTuples) Join() StructTag
Join joins the structTag tuples and creates a single StructTag.
type Type ¶
type Type interface { // Name gets the type name with or without package identifier. // An optional packageContext parameter defines the name of the package (full package name) that is expected to be // within given context of search. This could be used to get the chain of names with respect to some package. // Example: // Developer wants to generate some additional method for the type 'X' within package 'my.com/testing/pkg'. // In order to generate valid names for the imported types the identity needs to be set to 'true'. // But current package context ('my.com/testing/pkg') should not be used be prefixed with the identifier. // Thus, an optional 'packageContext' parameter needs to be set to 'my.com/testing/pkg'. Name(identified bool, packageContext string) string // FullName gets the full name of given type with the full package name and a type. FullName() string // Kind gets the Kind of given type. Kind() Kind // Elem gets the wrapped, pointed, base of Elem() Type // String gets the full name string representation of given type. String() string // Zero gets zero value string of given type. Zero(identified bool, packageContext string) string // Equal checks if the types matches exact. Equal(another Type) bool }
Type is the interface used by all golang type reflections in package.
var ( Error Type Byte Type Rune Type Bool Type Int Type Int8 Type Int16 Type Int32 Type Int64 Type Uint Type Uint8 Type Uint16 Type Uint32 Type Uint64 Type Uintptr Type Float32 Type Float64 Type Complex64 Type Complex128 Type String Type UnsafePointer Type )
Builtin types definitions.
func Dereference ¶
Dereference is getting Type dereferenced basic value. If the value is basic returns nil.
func GetBuiltInType ¶
GetBuiltInType gets the built in type with given name.
func MustGetBuiltInType ¶
MustGetBuiltInType gets the built in type with given name. If the type is not found the function panics.