Documentation
¶
Index ¶
- func LoadPackage(packagePattern string) (*packages.Package, error)
- func LoadPackages(packagePatterns ...string) (map[string]*packages.Package, error)
- type Field
- func (f Field) AsStruct() *Struct
- func (f Field) Comments() string
- func (f Field) DerefResolvedType() string
- func (f Field) Error(fset *token.FileSet) string
- func (f Field) HasTag(key string) bool
- func (f Field) IsLocalType() bool
- func (f Field) LookupTag(key string) (string, bool)
- func (f Field) OriginType() string
- func (f Field) ResolvedType() string
- func (f Field) String() string
- func (f Field) TypeArgs() string
- type Interface
- type NamedType
- type Package
- type Struct
- func (s Struct) Comments() string
- func (s Struct) Fields() []Field
- func (s Struct) HasMethod(methodName string) bool
- func (s Struct) Implements(iface string) bool
- func (s Struct) NumFields() int
- func (s Struct) PrintWithFieldError(fieldIndex int, errMsg string) string
- func (s *Struct) SetInterface(iface string)
- func (s Struct) String() string
- type TypeInfo
- func (t TypeInfo) DerefType() string
- func (t TypeInfo) DerefUnqualifiedType() string
- func (t TypeInfo) IsIterable() bool
- func (t TypeInfo) IsPointer() bool
- func (t TypeInfo) Name() string
- func (t TypeInfo) Type() string
- func (t TypeInfo) TypeName() string
- func (t TypeInfo) UnqualifiedType() string
- func (t TypeInfo) UnqualifiedTypeName() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadPackage ¶ added in v0.1.14
Loads a single package
func LoadPackages ¶
Loads and type checks a package. Returns any errors encountered during loading or typechecking, otherwise returns the package's data. Useful for static type analysis with the types package instead of manually parsing the AST. A good explainer lives here: https://github.com/golang/example/tree/master/gotypes
Types ¶
type Field ¶
type Field struct {
TypeInfo
// contains filtered or unexported fields
}
func (Field) DerefResolvedType ¶ added in v0.2.1
Returns the field's unqualified type if it's local, and the qualified type otherwise.
func (Field) IsLocalType ¶
Returns true if the field's type originates from the same package its parent struct is defined in.
func (Field) OriginType ¶ added in v0.1.14
If the type is a generic instantiation, returns the origin of the generic type. e.g. ccc.Foo[bool] returns ccc.Foo
func (Field) ResolvedType ¶ added in v0.1.11
Returns the field's unqualified type if it's local, and the qualified type otherwise.
type Interface ¶ added in v0.1.14
type Interface struct {
Name string
// contains filtered or unexported fields
}
type Package ¶ added in v0.2.3
func ParsePackage ¶ added in v0.2.3
We can iterate over the declarations at the package level a single time to extract all the data necessary for generation. Any new data that needs to be added to the struct definitions can be extracted here.
type Struct ¶
type Struct struct {
TypeInfo
// contains filtered or unexported fields
}
func FilterStructsByInterface ¶ added in v0.1.14
func (Struct) Implements ¶ added in v0.0.18
func (Struct) PrintWithFieldError ¶
func (*Struct) SetInterface ¶ added in v0.0.18
type TypeInfo ¶ added in v0.0.18
type TypeInfo struct {
// contains filtered or unexported fields
}
func (TypeInfo) DerefUnqualifiedType ¶ added in v0.2.1
Type without pointer and package prefix removed e.g. *ccc.UUID -> UUID
func (TypeInfo) IsIterable ¶ added in v0.0.18
Returns true if type is slice or array
func (TypeInfo) TypeName ¶ added in v0.0.18
Qualified type without array/slice/pointer prefix. e.g. *ccc.UUID -> ccc.UUID, []ccc.UUID -> ccc.UUID
func (TypeInfo) UnqualifiedType ¶ added in v0.0.18
Type without package prefix. e.g. ccc.UUID -> UUID, []ccc.UUID -> []UUID
func (TypeInfo) UnqualifiedTypeName ¶ added in v0.0.18
Type without array/slice/pointer or package prefix. e.g. *ccc.UUID -> UUID, []ccc.UUID -> UUID