registry

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MethodScope

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

MethodScope is the sub-registry for allocating variables present in the method scope.

It should be created using a registry instance.

func (*MethodScope) AddVar

func (m *MethodScope) AddVar(vr *types.Var, suffix string) *Var

AddVar allocates a variable instance and adds it to the method scope.

Variables names are generated if required and are ensured to be without conflict with other variables and imported packages. It also adds the relevant imports to the registry for each added variable.

type Package

type Package struct {
	Alias string
	// contains filtered or unexported fields
}

Package represents an imported package.

func NewPackage

func NewPackage(pkg *types.Package) *Package

NewPackage creates a new instance of Package.

func (*Package) Path

func (p *Package) Path() string

Path is the full package import path (without vendor).

func (*Package) Qualifier

func (p *Package) Qualifier() string

Qualifier returns the qualifier which must be used to refer to types declared in the package.

type Registry

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

Registry encapsulates types information for the source and mock destination package. For the mock package, it tracks the list of imports and ensures there are no conflicts in the imported package qualifiers.

func New

func New(srcDir, moqPkg string) (*Registry, error)

New loads the source package info and returns a new instance of Registry.

func (*Registry) AddImport

func (r *Registry) AddImport(pkg *types.Package) *Package

AddImport adds the given package to the set of imports. It generates a suitable alias if there are any conflicts with previously imported packages.

func (Registry) Imports

func (r Registry) Imports() []*Package

Imports returns the list of imported packages. The list is sorted by path.

func (Registry) LookupInterface

func (r Registry) LookupInterface(name string) (*types.Interface, error)

LookupInterface returns the underlying interface definition of the given interface name.

func (*Registry) MethodScope

func (r *Registry) MethodScope() *MethodScope

MethodScope returns a new MethodScope.

func (Registry) SrcPkg

func (r Registry) SrcPkg() *types.Package

SrcPkg returns the types info for the source package.

func (Registry) SrcPkgName

func (r Registry) SrcPkgName() string

SrcPkgName returns the name of the source package.

type Var

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

Var represents a method variable/parameter.

It should be created using a method scope instance.

func (Var) IsSlice

func (v Var) IsSlice() bool

IsSlice returns whether the type (or the underlying type) is a slice.

func (Var) Type

func (v Var) Type() types.Type

Type returns the raw variable type. NOTE: Added by RussellLuo.

func (Var) TypeString

func (v Var) TypeString() string

TypeString returns the variable type with the package qualifier in the format 'pkg.Type'.

Jump to

Keyboard shortcuts

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