parser

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPackage added in v0.1.14

func LoadPackage(packagePattern string) (*packages.Package, error)

Loads a single package

func LoadPackages

func LoadPackages(packagePatterns ...string) (map[string]*packages.Package, error)

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) Comments added in v0.1.14

func (f *Field) Comments() string

func (*Field) DerefResolvedType added in v0.2.1

func (f *Field) DerefResolvedType() string

Returns the field's unqualified type if it's local, and the qualified type otherwise.

func (*Field) Error added in v0.1.14

func (f *Field) Error() string

func (Field) HasTag added in v0.1.13

func (f Field) HasTag(key string) bool

func (*Field) IsLocalType

func (f *Field) IsLocalType() bool

Returns true if the field's type originates from the same package its parent struct is defined in.

func (*Field) LookupTag

func (f *Field) LookupTag(key string) (string, bool)

func (*Field) OriginType added in v0.1.14

func (f *Field) OriginType() string

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

func (f *Field) ResolvedType() string

Returns the field's unqualified type if it's local, and the qualified type otherwise.

func (*Field) String

func (f *Field) String() string

func (*Field) TypeArgs added in v0.1.14

func (f *Field) TypeArgs() string

type Interface added in v0.1.14

type Interface struct {
	Name string
	// contains filtered or unexported fields
}

type Struct

type Struct struct {
	*TypeInfo
	// contains filtered or unexported fields
}

func FilterStructsByInterface added in v0.1.14

func FilterStructsByInterface(pStructs []*Struct, interfaceNames []string) []*Struct

func ParseStructs

func ParseStructs(pkg *packages.Package) []*Struct

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.

func (*Struct) Comments added in v0.1.14

func (s *Struct) Comments() string

func (*Struct) Error added in v0.1.14

func (s *Struct) Error() string

func (*Struct) Fields

func (s *Struct) Fields() []*Field

func (Struct) HasMethod added in v0.1.14

func (s Struct) HasMethod(methodName string) bool

func (*Struct) Implements added in v0.0.18

func (s *Struct) Implements(iface string) bool

func (*Struct) LocalTypes

func (s *Struct) LocalTypes() []*TypeInfo

func (*Struct) Name

func (s *Struct) Name() string

func (*Struct) NumFields added in v0.1.14

func (s *Struct) NumFields() int

func (*Struct) PrintWithFieldError

func (s *Struct) PrintWithFieldError(fieldIndex int, errMsg string) string

func (*Struct) SetInterface added in v0.0.18

func (s *Struct) SetInterface(iface string)

func (*Struct) String

func (s *Struct) String() string

Pretty prints the struct name and its fields. Useful for debugging.

type TypeInfo added in v0.0.18

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

func (*TypeInfo) AsStruct added in v0.1.14

func (t *TypeInfo) AsStruct() *Struct

func (*TypeInfo) DerefType added in v0.2.1

func (t *TypeInfo) DerefType() string

e.g. *ccc.UUID -> ccc.UUID

func (*TypeInfo) DerefUnqualifiedType added in v0.2.1

func (t *TypeInfo) DerefUnqualifiedType() string

Type without pointer and package prefix removed e.g. *ccc.UUID -> UUID

func (*TypeInfo) IsExported added in v0.1.14

func (t *TypeInfo) IsExported() bool

func (*TypeInfo) IsIterable added in v0.0.18

func (t *TypeInfo) IsIterable() bool

Returns true if type is slice or array

func (*TypeInfo) IsPointer added in v0.0.18

func (t *TypeInfo) IsPointer() bool

func (*TypeInfo) Name added in v0.0.18

func (t *TypeInfo) Name() string

func (*TypeInfo) Type added in v0.0.18

func (t *TypeInfo) Type() string

e.g. ccc.UUID, []ccc.UUID

func (*TypeInfo) TypeName added in v0.0.18

func (t *TypeInfo) TypeName() string

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

func (t *TypeInfo) UnqualifiedType() string

Type without package prefix. e.g. ccc.UUID -> UUID, []ccc.UUID -> []UUID

func (*TypeInfo) UnqualifiedTypeName added in v0.0.18

func (t *TypeInfo) UnqualifiedTypeName() string

Type without array/slice/pointer or package prefix. e.g. *ccc.UUID -> UUID, []ccc.UUID -> UUID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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