loader

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: Apache-2.0, BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EachType

func EachType(pkg *Package, cb TypeCallback)

EachType calls the given callback for each (gendecl, typespec) combo in the given package. Generally, using markers.EachType is better when working with marker data, and has a more convinient representation.

func ErrFromNode

func ErrFromNode(err error, node Node) error

ErrFromNode returns the given error, with additional information attaching it to the given AST node. It will automatically map over error lists.

func MaybeErrList

func MaybeErrList(errs []error) error

MaybeErrList constructs an ErrList if the given list of errors has any errors, otherwise returning nil.

func NonVendorPath

func NonVendorPath(rawPath string) string

NonVendorPath returns a package path that does not include anything before the last vendor directory. This is useful for when using vendor directories, and using go/types.Package.Path(), which returns the full path including vendor.

If you're using this, make sure you really need it -- it's better to index by the actual Package object when you can.

func ParseAstTag

func ParseAstTag(tag *ast.BasicLit) reflect.StructTag

ParseAstTag parses the given raw tag literal into a reflect.StructTag.

Types

type ErrList

type ErrList []error

ErrList is a list of errors aggregated together into a single error.

func (ErrList) Error

func (l ErrList) Error() string

type Loader

type Loader interface {
	LoadRoots(roots ...string) ([]*Package, error)
}

func NewLoader

func NewLoader() Loader

func NewWithConfig

func NewWithConfig(cfg *packages.Config) Loader

loader loads packages and their imports. Loaded packages will have type size, imports, and exports file information populated.

type Node

type Node interface {
	Pos() token.Pos // position of first character belonging to the node
}

Node is the intersection of go/ast.Node and go/types.Var.

type NodeFilter

type NodeFilter func(ast.Node) bool

NodeFilter filters nodes, accepting them for reference collection when true is returned and rejecting them when false is returned.

type Package

type Package struct {
	*packages.Package

	sync.Mutex
	// contains filtered or unexported fields
}

Package is a single, unique Go package that can be lazily parsed and type-checked. Packages should not be constructed directly -- instead, use LoadRoots.

func (*Package) AddError

func (p *Package) AddError(err error)

AddError adds an error to the errors associated with the given package.

func (*Package) EachType

func (p *Package) EachType(cb TypeCallback)

EachType calls the given callback for each (gendecl, typespec) combo in the given package. Generally, using markers.EachType is better when working with marker data, and has a more convinient representation.

func (*Package) Imports

func (p *Package) Imports() map[string]*Package

Imports returns the imports for the given package, indexed by package path (*not* name in any particular file).

func (*Package) NeedSyntax

func (p *Package) NeedSyntax()

NeedSyntax indicates that a parsed AST is needed for this package. Actual ASTs can be accessed via the Syntax field.

func (*Package) NeedTypesInfo

func (p *Package) NeedTypesInfo()

NeedTypesInfo indicates that type-checking information is needed for this package. Actual type-checking information can be accessed via the Types and TypesInfo fields.

type PositionedError

type PositionedError struct {
	Pos token.Pos
	// contains filtered or unexported fields
}

PositionedError represents some error with an associated position. The position is tied to some external token.FileSet.

type TypeCallback

type TypeCallback func(file *ast.File, decl *ast.GenDecl, spec *ast.TypeSpec)

TypeCallback is a callback called for each raw AST (gendecl, typespec) combo.

type TypeChecker

type TypeChecker interface {
	Check(rootPkg *Package)
}

func NewTypeChecker

func NewTypeChecker() TypeChecker

Jump to

Keyboard shortcuts

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