protected final Class<?> getResourceType() { if (this.isField) { return ((Field) this.member).getType(); } else if (this.pd != null) { return this.pd.getPropertyType(); } else { return ((Method) this.member).getParameterTypes()[0]; } }
/** * Create a new RemoteInvocation for the given AOP method invocation. * @param methodInvocation the AOP invocation to convert */ public RemoteInvocation(MethodInvocation methodInvocation) { this.methodName = methodInvocation.getMethod().getName(); this.parameterTypes = methodInvocation.getMethod().getParameterTypes(); this.arguments = methodInvocation.getArguments(); }
/** * Check whether the given method corresponds to the container's currently invoked * factory method. Compares method name and parameter types only in order to work * around a potential problem with covariant return types (currently only known * to happen on Groovy classes). */ private boolean isCurrentlyInvokedFactoryMethod(Method method) { Method currentlyInvoked = SimpleInstantiationStrategy.getCurrentlyInvokedFactoryMethod(); return (currentlyInvoked != null && method.getName().equals(currentlyInvoked.getName()) && Arrays.equals(method.getParameterTypes(), currentlyInvoked.getParameterTypes())); }
public static boolean isCandidateWriteMethod(Method method) { String methodName = method.getName(); Class<?>[] parameterTypes = method.getParameterTypes(); int nParams = parameterTypes.length; return (methodName.length() > 3 && methodName.startsWith("set") && Modifier.isPublic(method.getModifiers()) && (!void.class.isAssignableFrom(method.getReturnType()) || Modifier.isStatic(method.getModifiers())) && (nParams == 1 || (nParams == 2 && int.class == parameterTypes[0]))); }
/** Determines whether the given method takes a Guard as its first parameter. */ private static boolean isGuarded(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); return parameterTypes.length >= 1 && parameterTypes[0] == Monitor.Guard.class; }
/** Determines whether the given method takes a time and unit as its last two parameters. */ private static boolean isTimed(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); return parameterTypes.length >= 2 && parameterTypes[parameterTypes.length - 2] == long.class && parameterTypes[parameterTypes.length - 1] == TimeUnit.class; }
/** * Check whether the given method is declared on any of the given interfaces. */ private static boolean implementsInterface(Method method, Set<Class<?>> ifcs) { for (Class<?> ifc : ifcs) { if (ClassUtils.hasMethod(ifc, method.getName(), method.getParameterTypes())) { return true; } } return false; }
/** * Create an array of descriptors representing the parameter types for the supplied * method. Returns a zero sized array if there are no parameters. * @param method a Method * @return a String array of descriptors, one entry for each method parameter */ public static String[] toParamDescriptors(Method method) { return toDescriptors(method.getParameterTypes()); }
private static Object[] getParameterValues(Method method) { FreshValueGenerator paramValues = new FreshValueGenerator(); final List<Object> passedArgs = Lists.newArrayList(); for (Class<?> paramType : method.getParameterTypes()) { passedArgs.add(paramValues.generateFresh(paramType)); } return passedArgs.toArray(); }
/** * Verifies that {@code method} produces a {@link NullPointerException} or {@link * UnsupportedOperationException} whenever <i>any</i> of its non-nullable parameters are null. * * @param instance the instance to invoke {@code method} on, or null if {@code method} is static */ public void testMethod(@Nullable Object instance, Method method) { Class<?>[] types = method.getParameterTypes(); for (int nullIndex = 0; nullIndex < types.length; nullIndex++) { testMethodParameter(instance, method, nullIndex); } }
@Override public boolean matches(Method method, Class<?> targetClass) { return method.getParameterCount() == 1 && method.getParameterTypes()[0].equals(Integer.class); } },
@Override @Nullable public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } Method finder = getFinder(targetType.getType()); Assert.state(finder != null, "No finder method"); Object id = this.conversionService.convert( source, sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0])); return ReflectionUtils.invokeMethod(finder, source, id); }
@Override public int compare(Method m1, Method m2) { int nameComparison = m1.getName().compareTo(m2.getName()); if (nameComparison != 0) { return nameComparison; } else { return Ints.compare(m1.getParameterTypes().length, m2.getParameterTypes().length); } } });
static void verifyConsitentRawType() { for (Method method : RawTypeConsistencyTester.class.getDeclaredMethods()) { assertEquals( method.getReturnType(), TypeToken.of(method.getGenericReturnType()).getRawType()); for (int i = 0; i < method.getParameterTypes().length; i++) { assertEquals( method.getParameterTypes()[i], TypeToken.of(method.getGenericParameterTypes()[i]).getRawType()); } } } }
private static Object[] arbitraryParameters(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); Object[] params = new Object[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { params[i] = PARAMETER_VALUES.get(parameterTypes[i]); } return params; }
/** * Filter on methods with the given parameter types. */ public Builder<T> argTypes(Class<?>... argTypes) { addFilter("argTypes=" + Arrays.toString(argTypes), method -> ObjectUtils.isEmpty(argTypes) ? method.getParameterCount() == 0 : Arrays.equals(method.getParameterTypes(), argTypes)); return this; }
/** * Filter on methods with the given parameter types. */ public Builder<T> argTypes(Class<?>... argTypes) { addFilter("argTypes=" + Arrays.toString(argTypes), method -> ObjectUtils.isEmpty(argTypes) ? method.getParameterCount() == 0 : Arrays.equals(method.getParameterTypes(), argTypes)); return this; }
private static MethodParameter getMethodParameter(Class<?> parameterType) { Method method = ClassUtils.getMethod(TestBean.class, "handle", (Class<?>[]) null); for (int i=0; i < method.getParameterCount(); i++) { if (parameterType.equals(method.getParameterTypes()[i])) { return new MethodParameter(method, i); } } throw new IllegalArgumentException("Parameter type not found: " + parameterType); }
MethodSignature(Method method) { name = method.getName(); parameterTypes = Arrays.asList(method.getParameterTypes()); typeSignature = new TypeSignature(method.getTypeParameters()); }
@Override public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { Method finder = getFinder(targetType.getType()); return (finder != null && this.conversionService.canConvert(sourceType, TypeDescriptor.valueOf(finder.getParameterTypes()[0]))); }