/** * Retrieve all candidate methods for the given class, considering * the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag. * Called as the starting point for factory method determination. */ private Method[] getCandidateMethods(Class<?> factoryClass, RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { return AccessController.doPrivileged((PrivilegedAction<Method[]>) () -> (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods())); } else { return (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods()); } }
/** * Retrieve all candidate methods for the given class, considering * the {@link RootBeanDefinition#isNonPublicAccessAllowed()} flag. * Called as the starting point for factory method determination. */ private Method[] getCandidateMethods(Class<?> factoryClass, RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { return AccessController.doPrivileged((PrivilegedAction<Method[]>) () -> (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods())); } else { return (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getAllDeclaredMethods(factoryClass) : factoryClass.getMethods()); } }
Method[] methods = ReflectionUtils.getAllDeclaredMethods(bridgeMethod.getDeclaringClass()); for (Method candidateMethod : methods) { if (isBridgedCandidateFor(candidateMethod, bridgeMethod)) {
/** * Returns a {@link java.util.Set} of {@link java.lang.reflect.Method} instances that * are annotated with the annotation provided. * * @param clazz The class to search for a method with the given annotation type * @param annotationType The type of annotation to look for * @return a set of {@link java.lang.reflect.Method} instances if any are found, an empty set if not. */ @SuppressWarnings("rawtypes") public static final Set<Method> findMethod(Class clazz, Class<? extends Annotation> annotationType) { Method [] declaredMethods = org.springframework.util.ReflectionUtils.getAllDeclaredMethods(clazz); Set<Method> results = new HashSet<>(); for (Method curMethod : declaredMethods) { Annotation annotation = AnnotationUtils.findAnnotation(curMethod, annotationType); if(annotation != null) { results.add(curMethod); } } return results; } }
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass); int minTypeDiffWeight = Integer.MAX_VALUE; Method matchingMethod = null;
@Override public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { if (!Proxy.isProxyClass(bean.getClass())) { return bean; } InvocationHandler handler = Proxy.getInvocationHandler(bean); final Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass()); for (Method method : methods) { Hmily hmily = AnnotationUtils.findAnnotation(method, Hmily.class); if (Objects.nonNull(hmily)) { HmilyFeignHandler hmilyFeignHandler = new HmilyFeignHandler(); hmilyFeignHandler.setDelegate(handler); Class<?> clazz = bean.getClass(); Class<?>[] interfaces = clazz.getInterfaces(); ClassLoader loader = clazz.getClassLoader(); return Proxy.newProxyInstance(loader, interfaces, hmilyFeignHandler); } } return bean; }
@Override public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { if (!Proxy.isProxyClass(bean.getClass())) { return bean; } InvocationHandler handler = Proxy.getInvocationHandler(bean); final Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass()); for (Method method : methods) { Myth myth = AnnotationUtils.findAnnotation(method, Myth.class); if (Objects.nonNull(myth)) { MythFeignHandler mythFeignHandler = new MythFeignHandler(); mythFeignHandler.setDelegate(handler); Class<?> clazz = bean.getClass(); Class<?>[] interfaces = clazz.getInterfaces(); ClassLoader loader = clazz.getClassLoader(); return Proxy.newProxyInstance(loader, interfaces, mythFeignHandler); } } return bean; }
Method[] methods = ReflectionUtils.getAllDeclaredMethods(bridgeMethod.getDeclaringClass()); for (Method candidateMethod : methods) { if (isBridgedCandidateFor(candidateMethod, bridgeMethod)) {
@Test public void getAllDeclaredMethods() throws Exception { class Foo { @Override public String toString() { return super.toString(); } } int toStringMethodCount = 0; for (Method method : ReflectionUtils.getAllDeclaredMethods(Foo.class)) { if (method.getName().equals("toString")) { toStringMethodCount++; } } assertThat(toStringMethodCount, is(2)); }
Method[] methods = ReflectionUtils.getAllDeclaredMethods(clazz); for (Method method : methods) { if (introductionAwareMethodMatcher != null ?
Class<?> targetClass = getTargetClass(); Assert.state(targetClass != null, "No target class set"); Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass); int minTypeDiffWeight = Integer.MAX_VALUE; Object[] argumentsToUse = null;
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass); int minTypeDiffWeight = Integer.MAX_VALUE; Method matchingMethod = null;
Class<?> targetClass = getTargetClass(); Assert.state(targetClass != null, "No target class set"); Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass); int minTypeDiffWeight = Integer.MAX_VALUE; Object[] argumentsToUse = null;
int argCount = arguments.length; Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass()); int minTypeDiffWeight = Integer.MAX_VALUE; Method matchingMethod = null;
public Method[] run() { return (mbd.isNonPublicAccessAllowed() ? ReflectionUtils.getAllDeclaredMethods(factoryClazz) : factoryClazz.getMethods()); } });
public UniqueMethodFilter(Class<?> targetClass) { Method[] allMethods = ReflectionUtils.getAllDeclaredMethods(targetClass); for (Method method : allMethods) { this.uniqueMethods.add(org.springframework.util.ClassUtils.getMostSpecificMethod(method, targetClass)); } }
private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class<?> targetType, TypeConverter typeConverter) { if (this.expectedType == null) { return true; } List<Method> methods = filter.filter(Arrays.asList(ReflectionUtils.getAllDeclaredMethods(targetType))); for (Method candidate : methods) { if (typeConverter.canConvert(TypeDescriptor.valueOf(candidate.getReturnType()), this.expectedType)) { return true; } } return false; }
/** * Find a matching method with the specified name for the specified arguments. * @return a matching method, or <code>null</code> if none * @see #getTargetClass() * @see #getTargetMethod() * @see #getArguments() */ protected Method findMatchingMethod() { String targetMethod = getTargetMethod(); Object[] arguments = getArguments(); int argCount = arguments.length; Method[] candidates = ReflectionUtils.getAllDeclaredMethods(getTargetClass()); int minTypeDiffWeight = Integer.MAX_VALUE; Method matchingMethod = null; for (Method candidate : candidates) { if (candidate.getName().equals(targetMethod)) { Class[] paramTypes = candidate.getParameterTypes(); if (paramTypes.length == argCount) { int typeDiffWeight = getTypeDifferenceWeight(paramTypes, arguments); if (typeDiffWeight < minTypeDiffWeight) { minTypeDiffWeight = typeDiffWeight; matchingMethod = candidate; } } } } return matchingMethod; }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bScanListenerAnnotation) { Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass()); if (methods != null) { for (Method method : methods) {
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(factoryClass); Method uniqueCandidate = null; for (Method candidate : candidates) {