use of org.springframework.util.ReflectionUtils.MethodFilter in project spring-framework by spring-projects.
the class ReflectionUtilsTests method doWithMethodsUsingUserDeclaredMethodsComposedFilter.
@Test
void doWithMethodsUsingUserDeclaredMethodsComposedFilter() {
ListSavingMethodCallback mc = new ListSavingMethodCallback();
// "q" because both absquatulate() and equals() contain "q"
MethodFilter isSetterMethodOrNameContainsQ = m -> m.getName().startsWith("set") || m.getName().contains("q");
MethodFilter methodFilter = ReflectionUtils.USER_DECLARED_METHODS.and(isSetterMethodOrNameContainsQ);
ReflectionUtils.doWithMethods(TestObject.class, mc, methodFilter);
assertThat(mc.getMethodNames()).containsExactlyInAnyOrder("setName", "setAge", "setSpouse", "absquatulate");
}
use of org.springframework.util.ReflectionUtils.MethodFilter in project alien4cloud by alien4cloud.
the class ChildContextAspectsManager method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(final Object bean, final String id) throws BeansException {
if (log.isTraceEnabled()) {
log.trace("post processing bean with id [ {} ] of type [ {} ]", id, bean.getClass().toString());
}
if (AopUtils.isAopProxy(bean)) {
log.debug("Spring is already managing proxy for bean of class {}.", bean.getClass().toString());
return bean;
}
if (AnnotationUtils.findAnnotation(bean.getClass(), Overridable.class) != null) {
// the bean is annotated as Overridable candidate
log.info("The bean with id [ {} ] of type [ {} ] is candidate to be overridden by plugin child contexts", id, bean.getClass().toString());
registerProxyCandidate(bean, id);
} else {
// let's look for annotation in methods
ReflectionUtils.doWithMethods(bean.getClass(), new MethodCallback() {
@Override
public void doWith(Method m) throws IllegalArgumentException, IllegalAccessException {
log.info("The method [ {} ] of bean [ {} ] is candidate to be overridden by plugin child contexts", m.toString(), id);
registerProxyCandidate(bean, id);
}
}, new MethodFilter() {
@Override
public boolean matches(Method m) {
// we search for public methods annotated as Overridable
return (m.getModifiers() & Modifier.PUBLIC) == Modifier.PUBLIC && AnnotationUtils.findAnnotation(m, Overridable.class) != null;
}
});
}
// if the bean is a candidate, then return the proxy
ProxyRegistry proxyRegistry = overridableCandidates.get(bean);
if (proxyRegistry != null) {
return proxyRegistry.proxy;
} else {
return bean;
}
}
Aggregations