Polishing
This commit is contained in:
@@ -27,31 +27,35 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
|
||||
import org.springframework.beans.factory.aot.BeanRegistrationCode;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.annotation.MergedAnnotations.Search;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.springframework.core.annotation.MergedAnnotations.SearchStrategy.TYPE_HIERARCHY;
|
||||
|
||||
/**
|
||||
* An AOT {@link BeanRegistrationAotProcessor} that detects the presence of
|
||||
* {@link RSocketExchange @RSocketExchange} on methods and creates
|
||||
* the required proxy hints.
|
||||
* Based on {@code HttpExchangeBeanRegistrationAotProcessor}
|
||||
* {@link RSocketExchange @RSocketExchange} on methods and creates the required
|
||||
* proxy hints.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @since 6.0
|
||||
* @since 6.0.5
|
||||
* @see org.springframework.web.service.annotation.HttpExchangeBeanRegistrationAotProcessor
|
||||
*/
|
||||
class RSocketExchangeBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
|
||||
Class<?> beanClass = registeredBean.getBeanClass();
|
||||
Set<Class<?>> exchangeInterfaces = new HashSet<>();
|
||||
Search search = MergedAnnotations.search(TYPE_HIERARCHY);
|
||||
for (Class<?> interfaceClass : ClassUtils.getAllInterfacesForClass(beanClass)) {
|
||||
ReflectionUtils.doWithMethods(interfaceClass, method -> {
|
||||
if (!exchangeInterfaces.contains(interfaceClass) &&
|
||||
MergedAnnotations.from(method, MergedAnnotations.SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(RSocketExchange.class).isPresent()) {
|
||||
search.from(method).isPresent(RSocketExchange.class)) {
|
||||
exchangeInterfaces.add(interfaceClass);
|
||||
}
|
||||
});
|
||||
@@ -62,6 +66,7 @@ class RSocketExchangeBeanRegistrationAotProcessor implements BeanRegistrationAot
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static class RSocketExchangeBeanRegistrationContribution implements BeanRegistrationAotContribution {
|
||||
|
||||
private final Set<Class<?>> rSocketExchangeInterfaces;
|
||||
@@ -71,14 +76,13 @@ class RSocketExchangeBeanRegistrationAotProcessor implements BeanRegistrationAot
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(GenerationContext generationContext,
|
||||
BeanRegistrationCode beanRegistrationCode) {
|
||||
public void applyTo(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode) {
|
||||
ProxyHints proxyHints = generationContext.getRuntimeHints().proxies();
|
||||
for (Class<?> httpExchangeInterface : this.rSocketExchangeInterfaces) {
|
||||
proxyHints.registerJdkProxy(AopProxyUtils
|
||||
.completeJdkProxyInterfaces(httpExchangeInterface));
|
||||
for (Class<?> rSocketExchangeInterface : this.rSocketExchangeInterfaces) {
|
||||
proxyHints.registerJdkProxy(AopProxyUtils.completeJdkProxyInterfaces(rSocketExchangeInterface));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,19 +29,19 @@ import org.springframework.core.MethodParameter;
|
||||
/**
|
||||
* A {@link ReflectiveProcessor} implementation for {@link RSocketExchange @RSocketExchange}
|
||||
* annotated methods. In addition to registering reflection hints for invoking
|
||||
* the annotated method, this implementation handles reflection-based
|
||||
* binding for return types and parameters.
|
||||
* Based on {@code HttpExchangeReflectiveProcessor}.
|
||||
* the annotated method, this implementation handles reflection-based binding for
|
||||
* return types and parameters.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @since 6.0
|
||||
* @since 6.0.5
|
||||
* @see org.springframework.web.service.annotation.HttpExchangeReflectiveProcessor
|
||||
*/
|
||||
public class RSocketExchangeReflectiveProcessor implements ReflectiveProcessor {
|
||||
class RSocketExchangeReflectiveProcessor implements ReflectiveProcessor {
|
||||
|
||||
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
|
||||
|
||||
|
||||
@Override
|
||||
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
|
||||
if (element instanceof Method method) {
|
||||
@@ -61,8 +61,8 @@ public class RSocketExchangeReflectiveProcessor implements ReflectiveProcessor {
|
||||
|
||||
protected void registerReturnTypeHints(ReflectionHints hints, MethodParameter returnTypeParameter) {
|
||||
if (!void.class.equals(returnTypeParameter.getParameterType())) {
|
||||
this.bindingRegistrar.registerReflectionHints(hints, returnTypeParameter
|
||||
.getGenericParameterType());
|
||||
this.bindingRegistrar.registerReflectionHints(hints, returnTypeParameter.getGenericParameterType());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
||||
org.springframework.messaging.rsocket.service.RSocketExchangeBeanRegistrationAotProcessor
|
||||
org.springframework.messaging.rsocket.service.RSocketExchangeBeanRegistrationAotProcessor
|
||||
|
||||
Reference in New Issue
Block a user