MCPcopy Create free account
hub / github.com/despiteallobjections/amigo / IntuitiveMethodSet

Function IntuitiveMethodSet

types/ui.go:24–50  ·  view source on GitHub ↗

This file defines utilities for user interfaces that display types. IntuitiveMethodSet returns the intuitive method set of a type T, which is the set of methods you can call on an addressable value of that type. The result always contains MethodSet(T), and is exactly MethodSet(T) for interface type

(T Type, msets *MethodSetCache)

Source from the content-addressed store, hash-verified

22// The order of the result is as for types.MethodSet(T).
23//
24func IntuitiveMethodSet(T Type, msets *MethodSetCache) []*Selection {
25 isPointerToConcrete := func(T Type) bool {
26 ptr, ok := T.(*Pointer)
27 return ok && !IsInterface(ptr.Elem())
28 }
29
30 var result []*Selection
31 mset := msets.MethodSet(T)
32 if IsInterface(T) || isPointerToConcrete(T) {
33 for i, n := 0, mset.Len(); i < n; i++ {
34 result = append(result, mset.At(i))
35 }
36 } else {
37 // T is some other concrete type.
38 // Report methods of T and *T, preferring those of T.
39 pmset := msets.MethodSet(NewPointer(T))
40 for i, n := 0, pmset.Len(); i < n; i++ {
41 meth := pmset.At(i)
42 if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
43 meth = m
44 }
45 result = append(result, meth)
46 }
47
48 }
49 return result
50}

Callers 1

TestIntuitiveMethodSetFunction · 0.85

Calls 11

IsInterfaceFunction · 0.85
NewPointerFunction · 0.85
MethodSetMethod · 0.80
ElemMethod · 0.65
PkgMethod · 0.65
NameMethod · 0.65
appendFunction · 0.50
LenMethod · 0.45
AtMethod · 0.45
LookupMethod · 0.45
ObjMethod · 0.45

Tested by 1

TestIntuitiveMethodSetFunction · 0.68