/** * Determine if the supplied {@code method} is an annotation attribute method. * @param method the method to check * @return {@code true} if the method is an attribute method * @since 4.2 */ static boolean isAttributeMethod(@Nullable Method method) { return (method != null && method.getParameterCount() == 0 && method.getReturnType() != void.class); }
@Nullable private Object wrapCacheValue(Method method, @Nullable Object cacheValue) { if (method.getReturnType() == Optional.class && (cacheValue == null || cacheValue.getClass() != Optional.class)) { return Optional.ofNullable(cacheValue); } return cacheValue; }
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]))); }
/** * Determine the conventional variable name for the return type of the given * method, taking the generic collection type, if any, into account, falling * back on the given actual return value if the method declaration is not * specific enough, e.g. {@code Object} return type or untyped collection. * @param method the method to generate a variable name for * @param value the return value (may be {@code null} if not available) * @return the generated variable name */ public static String getVariableNameForReturnType(Method method, @Nullable Object value) { return getVariableNameForReturnType(method, method.getReturnType(), value); }
/** * Determine the conventional variable name for the return type of the * given method, taking the generic collection type, if any, into account. * @param method the method to generate a variable name for * @return the generated variable name */ public static String getVariableNameForReturnType(Method method) { return getVariableNameForReturnType(method, method.getReturnType(), null); }
@Nullable private static Method determineToMethod(Class<?> targetClass, Class<?> sourceClass) { if (String.class == targetClass || String.class == sourceClass) { // Do not accept a toString() method or any to methods on String itself return null; } Method method = ClassUtils.getMethodIfAvailable(sourceClass, "to" + targetClass.getSimpleName()); return (method != null && !Modifier.isStatic(method.getModifiers()) && ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null); }
@Override public boolean matches(Method method, Class<?> targetClass) { return method.getReturnType().equals(String.class); } },
@Override public boolean matches(Method m, @Nullable Class<?> targetClass) { return m.getReturnType() == int.class; } };
@Override public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) { return m.getReturnType() == Void.TYPE; } });
InteractionTester(Class<T> interfaceType, Method method) { this.interfaceType = interfaceType; this.method = method; this.passedArgs = getParameterValues(method); this.returnValue = new FreshValueGenerator().generateFresh(method.getReturnType()); }
/** * Return the type of object that this FactoryBean creates, * or {@code null} if not known in advance. */ @Override public Class<?> getObjectType() { if (!isPrepared()) { // Not fully initialized yet -> return null to indicate "not known yet". return null; } return getPreparedMethod().getReturnType(); }
private static Method findMethodWithReturnType(String name, Class<?> returnType, Class<SettingsDaoImpl> targetType) { Method[] methods = targetType.getMethods(); for (Method m : methods) { if (m.getName().equals(name) && m.getReturnType().equals(returnType)) { return m; } } return null; }
private static Method getMethodForReturnType(Class<?> returnType) { return Arrays.stream(TestBean.class.getMethods()) .filter(method -> method.getReturnType().equals(returnType)) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Unique return type not found: " + returnType)); }
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()); } } } }
@GwtIncompatible // reflection public void testAsMapBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("asMap") && m.getReturnType().equals(SortedMap.class)) { return; } } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (Future.class.equals(invocation.getMethod().getReturnType())) { return new AsyncResult<>(invocation.getArguments()[0].toString()); } return null; } });
@Override public Object invoke(MethodInvocation invocation) throws Throwable { assertTrue(!Thread.currentThread().getName().equals(originalThreadName)); if (Future.class.equals(invocation.getMethod().getReturnType())) { return new AsyncResult<>(invocation.getArguments()[0].toString()); } return null; } });
@GwtIncompatible // reflection public void testKeySetBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("keySet") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); }
@GwtIncompatible // reflection public void testGetBridgeMethods() { for (Method m : TreeMultimap.class.getMethods()) { if (m.getName().equals("get") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); } }
@GwtIncompatible // reflection @AndroidIncompatible // Reflection bug, or actual binary compatibility problem? public void testElementSetBridgeMethods() { for (Method m : TreeMultiset.class.getMethods()) { if (m.getName().equals("elementSet") && m.getReturnType().equals(SortedSet.class)) { return; } } fail("No bridge method found"); } }