MethodValue returns the Function implementing method sel, building wrapper methods on demand. It returns nil if sel denotes an abstract (interface) method. Precondition: sel.Kind() == MethodVal. Thread-safe. EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu)
(sel *Selection)
| 21 | // EXCLUSIVE_LOCKS_ACQUIRED(prog.methodsMu) |
| 22 | // |
| 23 | func (prog *Program) MethodValue(sel *Selection) *Function { |
| 24 | if sel.Kind() != MethodVal { |
| 25 | panic(fmt.Sprintf("MethodValue(%s) kind != MethodVal", sel)) |
| 26 | } |
| 27 | T := sel.Recv() |
| 28 | if isInterface(T) { |
| 29 | return nil // abstract method |
| 30 | } |
| 31 | if prog.mode&LogSource != 0 { |
| 32 | defer logStack("MethodValue %s %v", T, sel)() |
| 33 | } |
| 34 | |
| 35 | prog.methodsMu.Lock() |
| 36 | defer prog.methodsMu.Unlock() |
| 37 | |
| 38 | return prog.addMethod(prog.createMethodSet(T), sel) |
| 39 | } |
| 40 | |
| 41 | // LookupMethod returns the implementation of the method of type T |
| 42 | // identified by (pkg, name). It returns nil if the method exists but |
no test coverage detected