IsType reports whether the reflect.Type is of the specified function type.
(t reflect.Type, ft funcType)
| 39 | |
| 40 | // IsType reports whether the reflect.Type is of the specified function type. |
| 41 | func IsType(t reflect.Type, ft funcType) bool { |
| 42 | if t == nil || t.Kind() != reflect.Func || t.IsVariadic() { |
| 43 | return false |
| 44 | } |
| 45 | ni, no := t.NumIn(), t.NumOut() |
| 46 | switch ft { |
| 47 | case tbFunc: // func(T) bool |
| 48 | if ni == 1 && no == 1 && t.Out(0) == boolType { |
| 49 | return true |
| 50 | } |
| 51 | case ttbFunc: // func(T, T) bool |
| 52 | if ni == 2 && no == 1 && t.In(0) == t.In(1) && t.Out(0) == boolType { |
| 53 | return true |
| 54 | } |
| 55 | case ttiFunc: // func(T, T) int |
| 56 | if ni == 2 && no == 1 && t.In(0) == t.In(1) && t.Out(0) == intType { |
| 57 | return true |
| 58 | } |
| 59 | case trbFunc: // func(T, R) bool |
| 60 | if ni == 2 && no == 1 && t.Out(0) == boolType { |
| 61 | return true |
| 62 | } |
| 63 | case tibFunc: // func(T, I) bool |
| 64 | if ni == 2 && no == 1 && t.In(0).AssignableTo(t.In(1)) && t.Out(0) == boolType { |
| 65 | return true |
| 66 | } |
| 67 | case trFunc: // func(T) R |
| 68 | if ni == 1 && no == 1 { |
| 69 | return true |
| 70 | } |
| 71 | } |
| 72 | return false |
| 73 | } |
| 74 | |
| 75 | var lastIdentRx = regexp.MustCompile(`[_\p{L}][_\p{L}\p{N}]*$`) |
| 76 |
no outgoing calls
no test coverage detected
searching dependent graphs…