Documentation ¶
Overview ¶
reflectplus generates and embedds the missing pieces in the go reflection system.
Index ¶
- func AddPackage(pkg Package)
- func AddProxyFactory(importPath string, name string, fac ProxyFactory)
- func AddType(importPath string, name string, p reflect.Type)
- func FindByType(t reflect.Type) interface{}
- func FindType(importPath string, name string) reflect.Type
- func Generate(dir string) error
- func Must(err error)
- func NewProxy(importPath string, name string, handler InvocationHandler) (interface{}, error)
- func PositionalError(p Positional, causedBy error) error
- type Annotation
- type Annotations
- type Field
- type Interface
- type InvocationHandler
- type Method
- type Package
- type Param
- type Pos
- type Positional
- type ProxyFactory
- type Struct
- type TypeDecl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPackage ¶
func AddPackage(pkg Package)
func AddProxyFactory ¶
func AddProxyFactory(importPath string, name string, fac ProxyFactory)
func FindByType ¶
FindByType tries to find the Struct or interface from the reflect type, otherwise returns nil.
func NewProxy ¶
func NewProxy(importPath string, name string, handler InvocationHandler) (interface{}, error)
func PositionalError ¶
func PositionalError(p Positional, causedBy error) error
Types ¶
type Annotation ¶
type Annotation struct { Doc string `json:"doc,omitempty"` Text string `json:"text,omitempty"` Name string `json:"name,omitempty"` Values map[string]interface{} `json:"values,omitempty"` Pos Pos `json:"pos,omitempty"` }
An Annotation is actually an @-prefixed-named json object one-liner
func (Annotation) AsString ¶
func (a Annotation) AsString(key string) string
func (Annotation) MustAsBool ¶
func (a Annotation) MustAsBool(key string) bool
func (Annotation) MustAsFloat ¶
func (a Annotation) MustAsFloat(key string) float64
func (Annotation) MustAsString ¶
func (a Annotation) MustAsString(key string) string
func (Annotation) Position ¶
func (a Annotation) Position() Pos
func (Annotation) Value ¶
func (a Annotation) Value() string
Value returns the value for the "value"-key or the empty string
type Annotations ¶
type Annotations []Annotation
func (Annotations) Has ¶
func (s Annotations) Has(name string) bool
type Field ¶
type Interface ¶
type Interface struct { Doc string `json:"doc,omitempty"` Annotations []Annotation `json:"annotations,omitempty"` ImportPath string `json:"importPath,omitempty"` Name string `json:"name,omitempty"` Methods []Method `json:"methods,omitempty"` Pos Pos `json:"pos,omitempty"` }
func FindInterface ¶
func Interfaces ¶
func Interfaces() []Interface
type InvocationHandler ¶
type InvocationHandler func(method string, args ...interface{}) []interface{}
type Method ¶
type Method struct { Doc string `json:"doc,omitempty"` Annotations []Annotation `json:"annotations,omitempty"` Receiver *Param `json:"receiver,omitempty"` // optional receiver, if this is actually a struct method not a function Name string `json:"name,omitempty"` Params []Param `json:"params,omitempty"` Returns []Param `json:"returns,omitempty"` Pos Pos `json:"pos,omitempty"` }
func (Method) FindAnnotations ¶
func (m Method) FindAnnotations(name string) []Annotation
func (Method) MustAnnotationByName ¶
func (m Method) MustAnnotationByName(n string) Annotation
AnnotationByName asserts the existence of the named annotation and panics otherwise
func (Method) ParamByName ¶
type Package ¶
type Package struct { Doc string `json:"doc,omitempty"` ImportPath string `json:"importPath,omitempty"` Name string `json:"name,omitempty"` Packages []*Package `json:"packages,omitempty"` Interfaces []*Interface `json:"interfaces,omitempty"` Structs []*Struct `json:"structs,omitempty"` Funcs []Method `json:"funcs,omitempty"` }
func FindPackage ¶
func ImportMetaData ¶
func (*Package) AllInterfaces ¶
func (*Package) AllStructs ¶
func (*Package) VisitPackages ¶
type Positional ¶
type Positional interface {
Position() Pos
}
type ProxyFactory ¶
type ProxyFactory func(px InvocationHandler) interface{}
type Struct ¶
type Struct struct { Doc string `json:"doc,omitempty"` Annotations []Annotation `json:"annotations,omitempty"` ImportPath string `json:"importPath,omitempty"` Name string `json:"name,omitempty"` Fields []Field `json:"fields,omitempty"` Methods []Method `json:"methods,omitempty"` // Methods with a receiver Factories []Method `json:"factories,omitempty"` // factory methods, returning the struct Pos Pos `json:"pos,omitempty"` }
func FindStruct ¶
func (Struct) FindAnnotations ¶
func (s Struct) FindAnnotations(name string) []Annotation
type TypeDecl ¶
type TypeDecl struct { ImportPath string `json:"importPath,omitempty"` Identifier string `json:"identifier,omitempty"` // slices and arrays are [], maps are map, look at the type Params for details. func is a hard one and is describes in Func Stars int `json:"stars,omitempty"` Var bool `json:"var,omitempty"` Params []TypeDecl `json:"params,omitempty"` // generics: currently only slices [], arrays [x] and maps map[a]b are supported Length int `json:"length,omitempty"` // parsed array length or -1 for a slice, 0 if not applicable Func *Method `json:"func,omitempty"` // only non-nil if identifier is "func" }
A TypeDecl (TypeDeclaration) refers to a type definition somewhere else. A declaration may contain other type parameter for generics (currently only slices, maps and channels), which itself may be generic. Also in a parameter definition variable (ellipsis) is allowed. What makes it even more complex are length attributes for arrays and an variable amount of pointer indirection (stars).
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
parser contains the glue code for different parsers (e.g.
|
parser contains the glue code for different parsers (e.g. |