Allow target to be a ClassName rather than an existing Class
See gh-29207
This commit is contained in:
@@ -94,9 +94,9 @@ class BeanDefinitionMethodGenerator {
|
||||
registerRuntimeHintsIfNecessary(generationContext.getRuntimeHints());
|
||||
BeanRegistrationCodeFragments codeFragments = getCodeFragments(generationContext,
|
||||
beanRegistrationsCode);
|
||||
Class<?> target = codeFragments.getTarget(this.registeredBean,
|
||||
ClassName target = codeFragments.getTarget(this.registeredBean,
|
||||
this.constructorOrFactoryMethod);
|
||||
if (!target.getName().startsWith("java.")) {
|
||||
if (!target.canonicalName().startsWith("java.")) {
|
||||
GeneratedClass generatedClass = generationContext.getGeneratedClasses()
|
||||
.getOrAddForFeatureComponent("BeanDefinitions", target, type -> {
|
||||
type.addJavadoc("Bean definitions for {@link $T}", target);
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.InstanceSupplier;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.javapoet.ClassName;
|
||||
import org.springframework.javapoet.CodeBlock;
|
||||
|
||||
/**
|
||||
@@ -52,9 +53,9 @@ public interface BeanRegistrationCodeFragments {
|
||||
* the code.
|
||||
* @param registeredBean the registered bean
|
||||
* @param constructorOrFactoryMethod the constructor or factory method
|
||||
* @return the target class
|
||||
* @return the target {@link ClassName}
|
||||
*/
|
||||
Class<?> getTarget(RegisteredBean registeredBean,
|
||||
ClassName getTarget(RegisteredBean registeredBean,
|
||||
Executable constructorOrFactoryMethod);
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.aot.generate.MethodReference;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.javapoet.ClassName;
|
||||
import org.springframework.javapoet.CodeBlock;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -51,7 +52,7 @@ public class BeanRegistrationCodeFragmentsDecorator implements BeanRegistrationC
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getTarget(RegisteredBean registeredBean,
|
||||
public ClassName getTarget(RegisteredBean registeredBean,
|
||||
Executable constructorOrFactoryMethod) {
|
||||
|
||||
return this.delegate.getTarget(registeredBean, constructorOrFactoryMethod);
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.support.InstanceSupplier;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.javapoet.ClassName;
|
||||
import org.springframework.javapoet.CodeBlock;
|
||||
import org.springframework.javapoet.ParameterizedTypeName;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -70,7 +71,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
|
||||
|
||||
|
||||
@Override
|
||||
public Class<?> getTarget(RegisteredBean registeredBean,
|
||||
public ClassName getTarget(RegisteredBean registeredBean,
|
||||
Executable constructorOrFactoryMethod) {
|
||||
|
||||
Class<?> target = extractDeclaringClass(registeredBean.getBeanType(), constructorOrFactoryMethod);
|
||||
@@ -79,7 +80,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
|
||||
Assert.state(parent != null, "No parent available for inner bean");
|
||||
target = parent.getBeanClass();
|
||||
}
|
||||
return target;
|
||||
return ClassName.get(target);
|
||||
}
|
||||
|
||||
private Class<?> extractDeclaringClass(ResolvableType beanType, Executable executable) {
|
||||
|
||||
Reference in New Issue
Block a user