MCPcopy
hub / github.com/vektra/mockery / LookupInterface

Method LookupInterface

template/registry.go:58–75  ·  view source on GitHub ↗

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

(name string)

Source from the content-addressed store, hash-verified

56// LookupInterface returns the underlying interface definition of the
57// given interface name.
58func (r Registry) LookupInterface(name string) (*types.Interface, *types.TypeParamList, error) {
59 obj := r.SrcPkg().Types.Scope().Lookup(name)
60 if obj == nil {
61 return nil, nil, stackerr.NewStackErr(fmt.Errorf("interface not found: %s", name))
62 }
63
64 if !types.IsInterface(obj.Type()) {
65 return nil, nil, fmt.Errorf("%s (%s) is not an interface", name, obj.Type())
66 }
67
68 var tparams *types.TypeParamList
69 named, ok := obj.Type().(*types.Named)
70 if ok {
71 tparams = named.TypeParams()
72 }
73
74 return obj.Type().Underlying().(*types.Interface).Complete(), tparams, nil
75}
76
77// MethodScope returns a new MethodScope.
78func (r *Registry) MethodScope() *MethodScope {

Callers 1

GenerateMethod · 0.80

Calls 3

SrcPkgMethod · 0.95
NewStackErrFunction · 0.92
TypeMethod · 0.80

Tested by

no test coverage detected