MCPcopy
hub / github.com/google/go-cmp / NameOf

Function NameOf

cmp/internal/function/func.go:78–106  ·  view source on GitHub ↗

NameOf returns the name of the function value.

(v reflect.Value)

Source from the content-addressed store, hash-verified

76
77// NameOf returns the name of the function value.
78func NameOf(v reflect.Value) string {
79 fnc := runtime.FuncForPC(v.Pointer())
80 if fnc == nil {
81 return "<unknown>"
82 }
83 fullName := fnc.Name() // e.g., "long/path/name/mypkg.(*MyType).(long/path/name/mypkg.myMethod)-fm"
84
85 // Method closures have a "-fm" suffix.
86 fullName = strings.TrimSuffix(fullName, "-fm")
87
88 var name string
89 for len(fullName) > 0 {
90 inParen := strings.HasSuffix(fullName, ")")
91 fullName = strings.TrimSuffix(fullName, ")")
92
93 s := lastIdentRx.FindString(fullName)
94 if s == "" {
95 break
96 }
97 name = s + "." + name
98 fullName = strings.TrimSuffix(fullName, s)
99
100 if i := strings.LastIndexByte(fullName, '('); inParen && i >= 0 {
101 fullName = fullName[:i]
102 }
103 fullName = strings.TrimSuffix(fullName, ".")
104 }
105 return strings.TrimSuffix(name, ".")
106}

Callers 8

callTRFuncMethod · 0.92
callTTBFuncMethod · 0.92
StringMethod · 0.92
StringMethod · 0.92
TransformerFunction · 0.92
StringMethod · 0.92
StringMethod · 0.92
TestNameOfFunction · 0.85

Calls 1

NameMethod · 0.45

Tested by 1

TestNameOfFunction · 0.68