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)
| 22 | // The order of the result is as for types.MethodSet(T). |
| 23 | // |
| 24 | func 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 | } |