MCPcopy Index your code
hub / github.com/apache/tomcat / getMethod

Method getMethod

java/org/apache/el/util/ReflectionUtil.java:153–348  ·  view source on GitHub ↗
(EvaluationContext ctx, Object base, Object property, Class<?>[] paramTypes,
            Object[] paramValues)

Source from the content-addressed store, hash-verified

151 * This class duplicates code in jakarta.el.Util. When making changes keep the code in sync.
152 */
153 @SuppressWarnings("null")
154 public static Method getMethod(EvaluationContext ctx, Object base, Object property, Class<?>[] paramTypes,
155 Object[] paramValues) throws MethodNotFoundException {
156
157 if (base == null || property == null) {
158 throw new MethodNotFoundException(
159 MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)));
160 }
161
162 String methodName = (property instanceof String) ? (String) property : property.toString();
163
164 int paramCount;
165 if (paramTypes == null) {
166 paramCount = 0;
167 } else {
168 paramCount = paramTypes.length;
169 }
170
171 Class<?> clazz = base.getClass();
172
173 // Fast path: when no arguments exist, there can only be one matching method and no need for coercion.
174 if (paramCount == 0) {
175 Method result = null;
176 Throwable t = null;
177 try {
178 Method method = clazz.getMethod(methodName, paramTypes);
179 result = getMethod(clazz, base, method);
180 } catch (NoSuchMethodException | SecurityException e) {
181 // Fall through
182 t = e;
183 }
184 if (result == null) {
185 throw new MethodNotFoundException(
186 MessageFactory.get("error.method.notfound", base, property, paramString(paramTypes)), t);
187 }
188 return result;
189 }
190
191 Method[] methods = clazz.getMethods();
192 Map<Method,MatchResult> candidates = new HashMap<>();
193
194 for (Method m : methods) {
195 if (!m.getName().equals(methodName)) {
196 // Method name doesn't match
197 continue;
198 }
199
200 Class<?>[] mParamTypes = m.getParameterTypes();
201 int mParamCount = mParamTypes.length;
202
203 // Check the number of parameters
204 // Multiple tests to improve readability
205 if (!m.isVarArgs() && paramCount != mParamCount) {
206 // Method has wrong number of parameters
207 continue;
208 }
209 if (m.isVarArgs() && paramCount < mParamCount - 1) {
210 // Method has wrong number of parameters

Callers 7

testBug54370aMethod · 0.95
testBug54370bMethod · 0.95
testBug54370cMethod · 0.95
testBug54370dMethod · 0.95
getMethodInfoMethod · 0.95
invokeMethod · 0.95
getMethodReferenceMethod · 0.95

Calls 15

getMethod · 0.95
paramStringMethod · 0.95
isAssignableFromMethod · 0.95
isCoercibleFromMethod · 0.95
isArrayMethod · 0.80
canAccessMethod · 0.80
getInterfacesMethod · 0.80
toStringMethod · 0.65
getMethodMethod · 0.65
equalsMethod · 0.65
getNameMethod · 0.65

Tested by 4

testBug54370aMethod · 0.76
testBug54370bMethod · 0.76
testBug54370cMethod · 0.76
testBug54370dMethod · 0.76