Debian Codegraph @

internal/runtime/method.go

raw
1 package runtime
2
3 import "reflect"
4
5 // MethodLookup looks the method of one name up in a type, by reflect.Type.MethodByName with the name as a constant.
6 //
7 // The compiler tells the linker which names the calls of Method and MethodByName of reflect look up when it sees
8 // them as constants, and the linker keeps the methods of those names only. A call with any other argument makes
9 // the linker keep every exported method of every type of the program ( cmd/compile/internal/walk.usemethod ), so
10 // the methods are looked up by these functions, each with its name in its code, and never by a name in a
11 // variable.
12 type MethodLookup func(reflect.Type) (reflect.Method, bool)
13
14 // MarshalJSONMethod looks MarshalJSON up.
15 func MarshalJSONMethod(typ reflect.Type) (reflect.Method, bool) {
16 return typ.MethodByName("MarshalJSON")
17 }
18
19 // MarshalTextMethod looks MarshalText up.
20 func MarshalTextMethod(typ reflect.Type) (reflect.Method, bool) {
21 return typ.MethodByName("MarshalText")
22 }
23
24 // AppendTextMethod looks AppendText up.
25 func AppendTextMethod(typ reflect.Type) (reflect.Method, bool) {
26 return typ.MethodByName("AppendText")
27 }
28
29 // UnmarshalJSONMethod looks UnmarshalJSON up.
30 func UnmarshalJSONMethod(typ reflect.Type) (reflect.Method, bool) {
31 return typ.MethodByName("UnmarshalJSON")
32 }