@Override public final boolean isVarArgs() { return method.isVarArgs(); } }
/** Return true if the method takes a variable number of arguments. */ public boolean isVarArgs () { return method.isVarArgs(); }
/** Return true if the method takes a variable number of arguments. */ public boolean isVarArgs () { return method.isVarArgs(); }
@Override public final boolean isVarArgs() { return method.isVarArgs(); } }
public boolean isVarArgs() { return method.isVarArgs(); }
@Override public final boolean isVarArgs() { return method.isVarArgs(); } }
private Executable(final Method method) { parameterTypes = method.getParameterTypes(); isVarArgs = method.isVarArgs(); }
private boolean wantedArgIndexIsVarargAndSameTypeAsReturnType(Method method, int argumentPosition) { Class<?>[] parameterTypes = method.getParameterTypes(); return method.isVarArgs() && argumentPosition == /* vararg index */ parameterTypes.length - 1 && method.getReturnType().isAssignableFrom(parameterTypes[argumentPosition]); }
private Object[] extractArgs(Method method, Object[] args) { if (!method.isVarArgs()) { return args; } Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]); Object[] combinedArgs = new Object[args.length - 1 + varArgs.length]; System.arraycopy(args, 0, combinedArgs, 0, args.length - 1); System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length); return combinedArgs; }
/** * Create a new executor for the given method. * @param method the method to invoke */ public ReflectiveMethodExecutor(Method method) { this.originalMethod = method; this.methodToInvoke = ClassUtils.getInterfaceMethodIfPossible(method); if (method.isVarArgs()) { Class<?>[] paramTypes = method.getParameterTypes(); this.varargsPosition = paramTypes.length - 1; } else { this.varargsPosition = null; } }
public SerializableMethod(Method method) { declaringClass = method.getDeclaringClass(); methodName = method.getName(); parameterTypes = method.getParameterTypes(); returnType = method.getReturnType(); exceptionTypes = method.getExceptionTypes(); isVarArgs = method.isVarArgs(); }
private boolean wantedArgumentPositionIsValidForInvocation(InvocationOnMock invocation, int argumentPosition) { if (argumentPosition < 0) { return false; } if (!invocation.getMethod().isVarArgs()) { return invocation.getArguments().length > argumentPosition; } // for all varargs accepts positive ranges return true; }
public SerializableMethod(Method method) { this.method = method; declaringClass = method.getDeclaringClass(); methodName = method.getName(); parameterTypes = SuspendMethod.trimSuspendParameterTypes(method.getParameterTypes()); returnType = method.getReturnType(); exceptionTypes = method.getExceptionTypes(); isVarArgs = method.isVarArgs(); isAbstract = (method.getModifiers() & Modifier.ABSTRACT) != 0; }
/** * Convert a supplied set of arguments into the requested types. If the parameterTypes are related to * a varargs method then the final entry in the parameterTypes array is going to be an array itself whose * component type should be used as the conversion target for extraneous arguments. (For example, if the * parameterTypes are {Integer, String[]} and the input arguments are {Integer, boolean, float} then both * the boolean and float must be converted to strings). This method does *not* repackage the arguments * into a form suitable for the varargs invocation - a subsequent call to setupArgumentsForVarargsInvocation handles that. * @param converter the converter to use for type conversions * @param arguments the arguments to convert to the requested parameter types * @param method the target Method * @return true if some kind of conversion occurred on the argument * @throws SpelEvaluationException if there is a problem with conversion */ public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method) throws SpelEvaluationException { Integer varargsPosition = (method.isVarArgs() ? method.getParameterCount() - 1 : null); return convertArguments(converter, arguments, method, varargsPosition); }
private static Object[] toVarArgs(final Method method, Object[] args) { if (method.isVarArgs()) { final Class<?>[] methodParameterTypes = method.getParameterTypes(); args = getVarArgs(args, methodParameterTypes); } return args; }
private Object[] extractArgs(Method method, Object[] args) { if (!method.isVarArgs()) { return args; } Object[] varArgs = ObjectUtils.toObjectArray(args[args.length - 1]); Object[] combinedArgs = new Object[args.length - 1 + varArgs.length]; System.arraycopy(args, 0, combinedArgs, 0, args.length - 1); System.arraycopy(varArgs, 0, combinedArgs, args.length - 1, varArgs.length); return combinedArgs; }
private static StringBuilder possibleArgumentTypesOf(InvocationOnMock invocation) { Class<?>[] parameterTypes = invocation.getMethod().getParameterTypes(); if (parameterTypes.length == 0) { return new StringBuilder("the method has no arguments.\n"); } StringBuilder stringBuilder = new StringBuilder("the possible argument indexes for this method are :\n"); for (int i = 0, parameterTypesLength = parameterTypes.length; i < parameterTypesLength; i++) { stringBuilder.append(" [").append(i); if (invocation.getMethod().isVarArgs() && i == parameterTypesLength - 1) { stringBuilder.append("+] ").append(parameterTypes[i].getComponentType().getSimpleName()).append(" <- Vararg").append("\n"); } else { stringBuilder.append("] ").append(parameterTypes[i].getSimpleName()).append("\n"); } } return stringBuilder; }
@SuppressWarnings("unchecked") private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) { List<Object> parameters = new ArrayList<>(); for (CacheInvocationParameter param : context.getKeyParameters()) { Object value = param.getValue(); if (param.getParameterPosition() == context.getAllParameters().length - 1 && context.getMethod().isVarArgs()) { parameters.addAll((List<Object>) CollectionUtils.arrayToList(value)); } else { parameters.add(value); } } return keyGenerator.generate(context.getTarget(), context.getMethod(), parameters.toArray()); }
@Override public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException { try { this.argumentConversionOccurred = ReflectionHelper.convertArguments( context.getTypeConverter(), arguments, this.originalMethod, this.varargsPosition); if (this.originalMethod.isVarArgs()) { arguments = ReflectionHelper.setupArgumentsForVarargsInvocation( this.originalMethod.getParameterTypes(), arguments); } ReflectionUtils.makeAccessible(this.methodToInvoke); Object value = this.methodToInvoke.invoke(target, arguments); return new TypedValue(value, new TypeDescriptor(new MethodParameter(this.originalMethod, -1)).narrow(value)); } catch (Exception ex) { throw new AccessException("Problem invoking method: " + this.methodToInvoke, ex); } }
@Override public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException { try { Method m = HasRoleExecutor.class.getMethod("hasRole", String[].class); Object[] args = arguments; if (args != null) { ReflectionHelper.convertAllArguments(tc, args, m); } if (m.isVarArgs()) { args = ReflectionHelper.setupArgumentsForVarargsInvocation(m.getParameterTypes(), args); } return new TypedValue(m.invoke(null, args), new TypeDescriptor(new MethodParameter(m,-1))); } catch (Exception ex) { throw new AccessException("Problem invoking hasRole", ex); } }