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

Method convertArgs

java/org/apache/el/parser/AstValue.java:256–405  ·  view source on GitHub ↗
(EvaluationContext ctx, Object[] src, Method m)

Source from the content-addressed store, hash-verified

254 }
255
256 private Object[] convertArgs(EvaluationContext ctx, Object[] src, Method m) {
257 Class<?>[] types = m.getParameterTypes();
258 if (types.length == 0) {
259 // Treated as if parameters have been provided so src is ignored
260 return EMPTY_ARRAY;
261 }
262
263 int paramCount = types.length;
264
265 if (m.isVarArgs() && paramCount > 1 && (src == null || paramCount > src.length) ||
266 !m.isVarArgs() && (src == null || src.length != paramCount)) {
267 String srcCount = null;
268 if (src != null) {
269 srcCount = Integer.toString(src.length);
270 }
271 String msg;
272 if (m.isVarArgs()) {
273 msg = MessageFactory.get("error.invoke.tooFewParams", m.getName(), srcCount,
274 Integer.toString(paramCount));
275 } else {
276 msg = MessageFactory.get("error.invoke.wrongParams", m.getName(), srcCount,
277 Integer.toString(paramCount));
278 }
279 throw new IllegalArgumentException(msg);
280 }
281
282 if (src == null) {
283 // Must be a varargs method with a single parameter.
284 // Use a new array every time since the called code could modify the
285 // contents of the array
286 return new Object[1];
287 }
288
289 Object[] dest = new Object[paramCount];
290
291 for (int i = 0; i < paramCount - 1; i++) {
292 dest[i] = ELSupport.coerceToType(ctx, src[i], types[i]);
293 }
294
295 if (m.isVarArgs()) {
296 Class<?> varArgType = m.getParameterTypes()[paramCount - 1].getComponentType();
297 if (varArgType.equals(Integer.class)) {
298 Integer[] varArgs = new Integer[src.length - (paramCount - 1)];
299 for (int i = 0; i < src.length - (paramCount - 1); i++) {
300 varArgs[i] = ELSupport.coerceToType(ctx, src[paramCount - 1 + i], Integer.class);
301 }
302 dest[paramCount - 1] = varArgs;
303 } else if (varArgType.equals(Byte.class)) {
304 Byte[] varArgs = new Byte[src.length - (paramCount - 1)];
305 for (int i = 0; i < src.length - (paramCount - 1); i++) {
306 varArgs[i] = ELSupport.coerceToType(ctx, src[paramCount - 1 + i], Byte.class);
307 }
308 dest[paramCount - 1] = varArgs;
309 } else if (varArgType.equals(Boolean.class)) {
310 Boolean[] varArgs = new Boolean[src.length - (paramCount - 1)];
311 for (int i = 0; i < src.length - (paramCount - 1); i++) {
312 varArgs[i] = ELSupport.coerceToType(ctx, src[paramCount - 1 + i], Boolean.class);
313 }

Callers 2

invokeMethod · 0.95
getMethodReferenceMethod · 0.95

Calls 9

getMethod · 0.95
coerceToTypeMethod · 0.95
toStringMethod · 0.65
getNameMethod · 0.65
equalsMethod · 0.65
newInstanceMethod · 0.65
getParameterTypesMethod · 0.45
isVarArgsMethod · 0.45
booleanValueMethod · 0.45

Tested by

no test coverage detected