registry

package
v3.0.0-alpha.11 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: BSD-3-Clause Imports: 7 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 NewMethodScope

func NewMethodScope(r *Registry) *MethodScope

func (*MethodScope) AddName

func (m *MethodScope) AddName(name string)

AddName records name as visible in the current scope. This may be useful in cases where a template statically adds its own name that needs to be registered with the scope to prevent future naming collisions.

func (*MethodScope) AddVar

func (m *MethodScope) AddVar(vr *types.Var, prefix 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.

func (*MethodScope) AllocateName

func (m *MethodScope) AllocateName(prefix string) string

AllocateName creates a new variable name in the lexical scope of the method. It ensures the returned name does not conflict with any other name visible to the scope. It registers the returned name in the lexical scope such that its exact value can never be allocated again.

func (*MethodScope) NameExists

func (m *MethodScope) NameExists(name string) bool

NameExists returns whether or not the name is currently visible in the scope.

func (*MethodScope) ResolveVariableNameCollisions

func (m *MethodScope) ResolveVariableNameCollisions(ctx context.Context)

type Package

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

Package represents an imported package.

func NewPackage

func NewPackage(pkg TypesPackage) *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(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error)

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

func (*Registry) AddImport

func (r *Registry) AddImport(ctx context.Context, 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, *types.TypeParamList, 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() *packages.Package

func (Registry) SrcPkgName

func (r Registry) SrcPkgName() string

SrcPkgName returns the name of the source package.

type TypesPackage

type TypesPackage interface {
	Name() string
	Path() string
}

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) Nillable

func (v Var) Nillable() bool

func (Var) Type

func (v Var) Type() types.Type

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