Documentation
¶
Index ¶
- type MethodScope
- type Package
- type Registry
- func (r *Registry) AddImport(ctx context.Context, pkg *types.Package) *Package
- func (r Registry) Imports() []*Package
- func (r Registry) LookupInterface(name string) (*types.Interface, *types.TypeParamList, error)
- func (r *Registry) MethodScope() *MethodScope
- func (r Registry) SrcPkg() *packages.Package
- func (r Registry) SrcPkgName() string
- type TypesPackage
- type Var
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.
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 (*Registry) AddImport ¶
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 ¶
Imports returns the list of imported packages. The list is sorted by path.
func (Registry) LookupInterface ¶
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) SrcPkgName ¶
SrcPkgName returns the name of the source package.
type TypesPackage ¶
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) TypeString ¶
TypeString returns the variable type with the package qualifier in the format 'pkg.Type'.