Documentation ¶
Index ¶
- func Implements(t Type, interfaceType *InterfaceType) bool
- func PackageNameOfDir(srcDir string) (string, error)
- type ArrayType
- func (a ArrayType) Elem() Type
- func (a ArrayType) Equal(another Type) bool
- func (a ArrayType) FullName() string
- func (a ArrayType) Kind() Kind
- func (a ArrayType) Name(identifier bool, packageContext string) string
- func (a ArrayType) String() string
- func (a ArrayType) Zero(identified bool, packageContext string) string
- type BuiltInType
- type ChanDir
- type ChanType
- type FuncParam
- type FunctionType
- func (f FunctionType) Elem() Type
- func (f FunctionType) Equal(another Type) bool
- func (f FunctionType) FullName() string
- func (f FunctionType) Kind() Kind
- func (f FunctionType) Name(identified bool, packageContext string) string
- func (f FunctionType) Package() *Package
- func (f FunctionType) String() string
- func (f FunctionType) Zero(_ bool, _ string) string
- type InterfaceType
- func (i InterfaceType) Elem() Type
- func (i InterfaceType) Equal(another Type) bool
- func (i InterfaceType) FullName() string
- func (i InterfaceType) Implements(another *InterfaceType) bool
- func (i InterfaceType) Kind() Kind
- func (i InterfaceType) Name(identified bool, packageContext string) string
- func (i InterfaceType) Package() *Package
- func (i InterfaceType) String() string
- func (i InterfaceType) Zero(_ bool, _ string) string
- type Kind
- type LoadConfig
- type MapType
- type Package
- func (p *Package) GetFunction(name string) (*FunctionType, bool)
- func (p *Package) GetInterfaceType(name string) (*InterfaceType, bool)
- func (p *Package) GetPkgPath() PkgPath
- func (p *Package) GetStructType(name string) (*StructType, bool)
- func (p *Package) GetType(name string) (Type, bool)
- func (p *Package) GetWrappedType(name string) (*WrappedType, bool)
- func (p *Package) IsStandard() bool
- func (p *Package) MustGetType(name string) Type
- type PackageMap
- func (p PackageMap) LoadPackages(cfg LoadConfig) error
- func (p PackageMap) MustGetByPath(path string) *Package
- 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 PointerType
- func (p PointerType) Elem() Type
- func (p PointerType) Equal(another Type) bool
- func (p PointerType) FullName() string
- func (p PointerType) Kind() Kind
- func (p PointerType) Name(identified bool, pkgContext string) string
- func (p PointerType) String() string
- func (p PointerType) Zero(_ bool, _ string) string
- type Receiver
- type StructField
- type StructTag
- type StructType
- func (s *StructType) Elem() Type
- func (s *StructType) Equal(another Type) bool
- func (s *StructType) FullName() string
- func (s *StructType) Implements(interfaceType *InterfaceType, pointer bool) bool
- func (s *StructType) Kind() Kind
- func (s *StructType) Name(identifier bool, packageContext string) string
- func (s *StructType) Package() *Package
- func (s *StructType) String() string
- func (s *StructType) Zero(identified bool, packageContext string) string
- type Type
- type WrappedType
- func (w WrappedType) Elem() Type
- func (w WrappedType) Equal(another Type) bool
- func (w WrappedType) FullName() string
- func (w WrappedType) Kind() Kind
- func (w WrappedType) Name(identified bool, packageContext string) string
- func (w WrappedType) Package() *Package
- func (w WrappedType) String() string
- func (w WrappedType) Zero(identified bool, packageContext string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Implements ¶
func Implements(t Type, interfaceType *InterfaceType) bool
Implements checks if the type t implements interface 'interfaceType'.
func PackageNameOfDir ¶
PackageNameOfDir get package import path via dir
Types ¶
type ArrayType ¶
ArrayType is the array or slice representing type.
type BuiltInType ¶
BuiltInType is the built in type definition.
func (BuiltInType) Equal ¶
func (b BuiltInType) Equal(another Type) bool
func (BuiltInType) FullName ¶
func (b BuiltInType) FullName() string
FullName implements Type interface.
type ChanType ¶
ChanType is the type representing channel.
type FunctionType ¶
type FunctionType struct { Comment string Pkg *Package Receiver *Receiver FuncName string In []FuncParam Out []FuncParam Variadic bool }
FunctionType is the function type used for getting.
func (FunctionType) Equal ¶
func (f FunctionType) Equal(another Type) bool
Equal implements Type interface.
func (FunctionType) FullName ¶
func (f FunctionType) FullName() string
FullName implements Type interface.
func (FunctionType) Name ¶
func (f FunctionType) Name(identified bool, packageContext string) string
Name implements Type interface.
func (FunctionType) Package ¶
func (f FunctionType) Package() *Package
Package implements Type interface.
func (FunctionType) String ¶
func (f FunctionType) String() string
String implements Type interface.
type InterfaceType ¶
type InterfaceType struct { Pkg *Package Comment string InterfaceName string Methods []FunctionType }
InterfaceType is the interface type model definition.
func (InterfaceType) Equal ¶
func (i InterfaceType) Equal(another Type) bool
Equal implements Type interface.
func (InterfaceType) FullName ¶
func (i InterfaceType) FullName() string
FullName implements Type interface.
func (InterfaceType) Implements ¶
func (i InterfaceType) Implements(another *InterfaceType) bool
Implements checks if given interface implements another interface.
func (InterfaceType) Name ¶
func (i InterfaceType) Name(identified bool, packageContext string) string
Name implements Type interface.
func (InterfaceType) Package ¶
func (i InterfaceType) Package() *Package
Package implements Type interface
func (InterfaceType) String ¶
func (i InterfaceType) String() string
String implements Type 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 Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Uintptr Float32 Float64 Complex64 Complex128 String Array Chan Func Interface Map Ptr Slice Struct UnsafePointer Wrapper )
Enumerated kind representations.
type LoadConfig ¶
type LoadConfig struct { // Paths could be absolute or relative path to given directory. Paths []string // PkgNames should be full pkg name i.e.: 'golang.org/x/mod/modfile' PkgNames []string // BuildFlags are the flags used by the ast. BuildFlags []string // Verbose sets the loader in verbose mode. Verbose bool }
LoadConfig contains configuration used while loading packages.
type MapType ¶
MapType is the type wrapper for the standar key value map type.
func (MapType) Elem ¶
Elem as the map has both the key and value it needs to be dereferenced manually.
type Package ¶
type Package struct { Path string Identifier string Interfaces []*InterfaceType Structs []*StructType Functions []*FunctionType WrappedTypes []*WrappedType Types map[string]Type sync.Mutex // contains filtered or unexported fields }
Package is the golang package reflection container. It contains all interfaces, structs, functions and type wrappers that are located inside of it.
func (*Package) GetFunction ¶
func (p *Package) GetFunction(name string) (*FunctionType, bool)
GetFunction gets the function type by it's name.
func (*Package) GetInterfaceType ¶
func (p *Package) GetInterfaceType(name string) (*InterfaceType, bool)
GetInterfaceType gets the interface by it's name.
func (*Package) GetPkgPath ¶
GetPkgPath gets the PkgPath for given package.
func (*Package) GetStructType ¶
func (p *Package) GetStructType(name string) (*StructType, bool)
GetStructType gets the struct type by it's name.
func (*Package) GetWrappedType ¶
func (p *Package) GetWrappedType(name string) (*WrappedType, bool)
GetWrappedType gets the wrapped type by it's name.
func (*Package) IsStandard ¶
IsStandard checks if given package is a standard package.
func (*Package) MustGetType ¶
MustGetType get the type with given 'name' from given package. If the type is not found the function panics.
type PackageMap ¶
PackageMap is a slice wrapper over Package type.
func LoadPackages ¶
func LoadPackages(cfg LoadConfig) (PackageMap, error)
LoadPackages parses Golang packages using AST.
func (PackageMap) LoadPackages ¶
func (p PackageMap) LoadPackages(cfg LoadConfig) error
LoadPackages updates the packages in the given PackageMap. The function would get and parse only packages that doesn't currently exists in given map.
func (PackageMap) MustGetByPath ¶
func (p PackageMap) MustGetByPath(path string) *Package
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.: StructType, InterfaceType, WrappedType, FunctionType.
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 PointerType ¶
type PointerType struct {
PointedType Type
}
PointerType is the type implementation that defines pointer type.
func PointerTo ¶
func PointerTo(pointsTo Type) *PointerType
PointerTo creates a pointer of given type.
func (PointerType) Equal ¶
func (p PointerType) Equal(another Type) bool
Equal implements Type interface.
func (PointerType) FullName ¶
func (p PointerType) FullName() string
FullName implements Type interface.
type Receiver ¶
Receiver is the function (method) receiver with the name and a pointer flag.
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
String 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.
type StructType ¶
type StructType struct { Pkg *Package Comment string TypeName string Fields []StructField Methods []FunctionType }
StructType is the struct type reflection.
func (*StructType) Equal ¶
func (s *StructType) Equal(another Type) bool
Equal implements Type interface.
func (*StructType) FullName ¶
func (s *StructType) FullName() string
FullName implements Type interface.
func (*StructType) Implements ¶
func (s *StructType) Implements(interfaceType *InterfaceType, pointer bool) bool
Implements checks if given structure implements provided interface.
func (*StructType) Name ¶
func (s *StructType) Name(identifier bool, packageContext string) string
Name implements Type interface.
func (*StructType) Package ¶
func (s *StructType) Package() *Package
PkgPath implements Type interface.
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.
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.
type WrappedType ¶
WrappedType is the type that represents wrapped and named another type. I.e.: 'type Custom int' would be a WrappedType over BuiltIn(int) type.
func (WrappedType) Equal ¶
func (w WrappedType) Equal(another Type) bool
Equal implements Type interface.
func (WrappedType) FullName ¶
func (w WrappedType) FullName() string
FullName implements Type interface.
func (WrappedType) Name ¶
func (w WrappedType) Name(identified bool, packageContext string) string
Name implements Type interface.
func (WrappedType) Package ¶
func (w WrappedType) Package() *Package
PkgPath implements Type interface.