public static void addSuppressedIfPossible(Throwable e, Throwable suppressed) { if (addSuppressedExceptionMethod != null) { try { addSuppressedExceptionMethod.invoke(e, suppressed); } catch (InvocationTargetException | IllegalAccessException ignored) { } } }
public static boolean isBeanPropertyReadMethod(Method method) { return method != null && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && method.getReturnType() != void.class && method.getDeclaringClass() != Object.class && method.getParameterTypes().length == 0 && ((method.getName().startsWith("get") && method.getName().length() > 3) || (method.getName().startsWith("is") && method.getName().length() > 2)); }
private Throwable tryInternalFastPathGetFailure(Future<?> future) throws Exception { Method tryInternalFastPathGetFailureMethod = abstractFutureClass.getDeclaredMethod("tryInternalFastPathGetFailure"); tryInternalFastPathGetFailureMethod.setAccessible(true); return (Throwable) tryInternalFastPathGetFailureMethod.invoke(future); } }
public MethodInvokeTypeProvider(TypeProvider provider, Method method, int index) { this.provider = provider; this.methodName = method.getName(); this.declaringClass = method.getDeclaringClass(); this.index = index; this.method = method; }
@Override public boolean matches(Method method, Class<?> targetClass) { return (method.getName().startsWith("set") && method.getParameterCount() == 1 && method.getReturnType() == Void.TYPE); }
public static boolean isSetBeanFactory(Method candidateMethod) { return (candidateMethod.getName().equals("setBeanFactory") && candidateMethod.getParameterCount() == 1 && BeanFactory.class == candidateMethod.getParameterTypes()[0] && BeanFactoryAware.class.isAssignableFrom(candidateMethod.getDeclaringClass())); } }
private static void doTestMocking(RateLimiter mock) throws Exception { for (Method method : RateLimiter.class.getMethods()) { if (!isStatic(method.getModifiers()) && !NOT_WORKING_ON_MOCKS.contains(method.getName()) && !method.getDeclaringClass().equals(Object.class)) { method.invoke(mock, arbitraryParameters(method)); } } }
/** * Determine whether the given method is an "equals" method. * @see java.lang.Object#equals(Object) */ public static boolean isEqualsMethod(@Nullable Method method) { if (method == null || !method.getName().equals("equals")) { return false; } Class<?>[] paramTypes = method.getParameterTypes(); return (paramTypes.length == 1 && paramTypes[0] == Object.class); }
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; }
@Override public boolean matches(Method m, @Nullable Class<?> targetClass) { return m.getName().equals("overload") && m.getParameterCount() == 1 && m.getParameterTypes()[0].equals(int.class); } });
@Override public Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable { // If the method is a method from Object then defer to normal invocation. if (method.getDeclaringClass() == Object.class) { return method.invoke(this, args); } if (platform.isDefaultMethod(method)) { return platform.invokeDefaultMethod(method, service, proxy, args); } return loadServiceMethod(method).invoke(args != null ? args : emptyArgs); } });
MethodSignature(Method method) { name = method.getName(); parameterTypes = Arrays.asList(method.getParameterTypes()); typeSignature = new TypeSignature(method.getTypeParameters()); }
@Test public void testFindBridgedMethodInHierarchy() throws Exception { Method bridgeMethod = DateAdder.class.getMethod("add", Object.class); assertTrue(bridgeMethod.isBridge()); Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(bridgeMethod); assertFalse(bridgedMethod.isBridge()); assertEquals("add", bridgedMethod.getName()); assertEquals(1, bridgedMethod.getParameterCount()); assertEquals(Date.class, bridgedMethod.getParameterTypes()[0]); }
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()); } } } }
@Override public Class<?> getPropertyType() { if (this.member instanceof Method) { return ((Method) this.member).getReturnType(); } else { return ((Field) this.member).getType(); } }
/** * Checks whether {@code method} is thread-safe, as indicated by the presence of the {@link * AllowConcurrentEvents} annotation. */ private static boolean isDeclaredThreadSafe(Method method) { return method.getAnnotation(AllowConcurrentEvents.class) != null; }
/** 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; }
@Nullable private SendTo getSendTo(Method specificMethod) { SendTo ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod, SendTo.class); if (ann == null) { ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), SendTo.class); } return ann; }
/** * Verifies that {@code method} produces a {@link NullPointerException} or {@link * UnsupportedOperationException} when the parameter in position {@code paramIndex} is null. If * this parameter is marked nullable, this method does nothing. * * @param instance the instance to invoke {@code method} on, or null if {@code method} is static */ public void testMethodParameter( @Nullable final Object instance, final Method method, int paramIndex) { method.setAccessible(true); testParameter(instance, invokable(instance, method), paramIndex, method.getDeclaringClass()); }