MCPcopy Create free account
hub / github.com/boxbeam/RedLib / getMethod

Method getMethod

src/redempt/redlib/nms/NMSHelper.java:108–124  ·  view source on GitHub ↗

Gets a method by its name and parameter types, accounts for cases where the given class might not be the exact same type as the parameter the method requires, but is a subclass. @param clazz The class to get the method in @param name The name of the method @param argTypes The class types for

(Class<?> clazz, String name, Class<?>[] argTypes)

Source from the content-addressed store, hash-verified

106 * @return The method in the class, or null if none was found
107 */
108 public static Method getMethod(Class<?> clazz, String name, Class<?>[] argTypes) {
109 Method[] methods = clazz.getMethods();
110 methods:
111 for (Method method : methods) {
112 if (!method.getName().equals(name) || method.getParameterCount() != argTypes.length) {
113 continue;
114 }
115 Parameter[] params = method.getParameters();
116 for (int i = 0; i < params.length; i++) {
117 if (!params[i].getType().isAssignableFrom(argTypes[i])) {
118 continue methods;
119 }
120 }
121 return method;
122 }
123 return null;
124 }
125
126 /**
127 * Gets a constructor by its parameter types, accounts for cases where the given class might not be the

Callers 2

callStaticMethodMethod · 0.95
callMethodMethod · 0.95

Calls 3

equalsMethod · 0.45
getNameMethod · 0.45
getTypeMethod · 0.45

Tested by

no test coverage detected