Allow a MethodReference to be produced from a GeneratedMethod

This commit updates GeneratedMethod and its underlying infrastructure
to be able to produce a MethodReference. This simplifies the need when
such a reference needs to be created manually and reuses more of what
MethodReference has to offer.

See gh-29005
This commit is contained in:
Stephane Nicoll 2022-08-24 07:21:02 +02:00
parent 649c2f56fd
commit 8a4a89b9d9
14 changed files with 101 additions and 43 deletions

View File

@ -163,8 +163,8 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc
method.addStatement("return ($T) factory.getObject()", method.addStatement("return ($T) factory.getObject()",
beanClass); beanClass);
}); });
return CodeBlock.of("$T.of($T::$L)", InstanceSupplier.class, return CodeBlock.of("$T.of($L)", InstanceSupplier.class,
beanRegistrationCode.getClassName(), generatedMethod.getName()); generatedMethod.toMethodReference().toCodeBlock());
} }
} }

View File

@ -44,7 +44,6 @@ import org.springframework.aot.generate.AccessVisibility;
import org.springframework.aot.generate.GeneratedClass; import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -944,8 +943,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
method.returns(this.target); method.returns(this.target);
method.addCode(generateMethodCode(generationContext.getRuntimeHints())); method.addCode(generateMethodCode(generationContext.getRuntimeHints()));
}); });
beanRegistrationCode.addInstancePostProcessor( beanRegistrationCode.addInstancePostProcessor(generateMethod.toMethodReference());
MethodReference.ofStatic(generatedClass.getName(), generateMethod.getName()));
if (this.candidateResolver != null) { if (this.candidateResolver != null) {
registerHints(generationContext.getRuntimeHints()); registerHints(generationContext.getRuntimeHints());

View File

@ -107,16 +107,14 @@ class BeanDefinitionMethodGenerator {
GeneratedMethod generatedMethod = generateBeanDefinitionMethod( GeneratedMethod generatedMethod = generateBeanDefinitionMethod(
generationContext, generatedClass.getName(), generatedMethods, generationContext, generatedClass.getName(), generatedMethods,
codeFragments, Modifier.PUBLIC); codeFragments, Modifier.PUBLIC);
return MethodReference.ofStatic(generatedClass.getName(), return generatedMethod.toMethodReference();
generatedMethod.getName());
} }
GeneratedMethods generatedMethods = beanRegistrationsCode.getMethods() GeneratedMethods generatedMethods = beanRegistrationsCode.getMethods()
.withPrefix(getName()); .withPrefix(getName());
GeneratedMethod generatedMethod = generateBeanDefinitionMethod(generationContext, GeneratedMethod generatedMethod = generateBeanDefinitionMethod(generationContext,
beanRegistrationsCode.getClassName(), generatedMethods, codeFragments, beanRegistrationsCode.getClassName(), generatedMethods, codeFragments,
Modifier.PRIVATE); Modifier.PRIVATE);
return MethodReference.ofStatic(beanRegistrationsCode.getClassName(), return generatedMethod.toMethodReference();
generatedMethod.getName());
} }
private BeanRegistrationCodeFragments getCodeFragments(GenerationContext generationContext, private BeanRegistrationCodeFragments getCodeFragments(GenerationContext generationContext,

View File

@ -65,8 +65,7 @@ class BeanRegistrationsAotContribution
BeanRegistrationsCodeGenerator codeGenerator = new BeanRegistrationsCodeGenerator(generatedClass); BeanRegistrationsCodeGenerator codeGenerator = new BeanRegistrationsCodeGenerator(generatedClass);
GeneratedMethod generatedMethod = codeGenerator.getMethods().add("registerBeanDefinitions", method -> GeneratedMethod generatedMethod = codeGenerator.getMethods().add("registerBeanDefinitions", method ->
generateRegisterMethod(method, generationContext, codeGenerator)); generateRegisterMethod(method, generationContext, codeGenerator));
beanFactoryInitializationCode.addInitializer( beanFactoryInitializationCode.addInitializer(generatedMethod.toMethodReference());
MethodReference.of(generatedClass.getName(), generatedMethod.getName()));
} }
private void generateRegisterMethod(MethodSpec.Builder method, private void generateRegisterMethod(MethodSpec.Builder method,

View File

@ -296,8 +296,8 @@ class InstanceSupplierCodeGenerator {
REGISTERED_BEAN_PARAMETER_NAME, declaringClass, factoryMethodName, args); REGISTERED_BEAN_PARAMETER_NAME, declaringClass, factoryMethodName, args);
} }
private CodeBlock generateReturnStatement(GeneratedMethod getInstanceMethod) { private CodeBlock generateReturnStatement(GeneratedMethod generatedMethod) {
return CodeBlock.of("$T.$L()", this.className, getInstanceMethod.getName()); return generatedMethod.toMethodReference().toInvokeCodeBlock();
} }
private CodeBlock generateWithGeneratorCode(boolean hasArguments, CodeBlock newInstance) { private CodeBlock generateWithGeneratorCode(boolean hasArguments, CodeBlock newInstance) {

View File

@ -129,8 +129,7 @@ class BeanDefinitionMethodGeneratorTests {
.addParameter(RegisteredBean.class, "registeredBean") .addParameter(RegisteredBean.class, "registeredBean")
.addParameter(TestBean.class, "testBean") .addParameter(TestBean.class, "testBean")
.returns(TestBean.class).addCode("return new $T($S);", TestBean.class, "postprocessed")); .returns(TestBean.class).addCode("return new $T($S);", TestBean.class, "postprocessed"));
beanRegistrationCode.addInstancePostProcessor(MethodReference.ofStatic( beanRegistrationCode.addInstancePostProcessor(generatedMethod.toMethodReference());
beanRegistrationCode.getClassName(), generatedMethod.getName()));
}; };
List<BeanRegistrationAotContribution> aotContributions = Collections List<BeanRegistrationAotContribution> aotContributions = Collections
.singletonList(aotContribution); .singletonList(aotContribution);
@ -167,8 +166,7 @@ class BeanDefinitionMethodGeneratorTests {
.addParameter(RegisteredBean.class, "registeredBean") .addParameter(RegisteredBean.class, "registeredBean")
.addParameter(TestBean.class, "testBean") .addParameter(TestBean.class, "testBean")
.returns(TestBean.class).addCode("return new $T($S);", TestBean.class, "postprocessed")); .returns(TestBean.class).addCode("return new $T($S);", TestBean.class, "postprocessed"));
beanRegistrationCode.addInstancePostProcessor(MethodReference.ofStatic( beanRegistrationCode.addInstancePostProcessor(generatedMethod.toMethodReference());
beanRegistrationCode.getClassName(), generatedMethod.getName()));
}; };
List<BeanRegistrationAotContribution> aotContributions = Collections List<BeanRegistrationAotContribution> aotContributions = Collections
.singletonList(aotContribution); .singletonList(aotContribution);

View File

@ -33,7 +33,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils; import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.hint.ResourceHints; import org.springframework.aot.hint.ResourceHints;
import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.TypeReference;
import org.springframework.beans.PropertyValues; import org.springframework.beans.PropertyValues;
@ -536,7 +535,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
.add("addImportAwareBeanPostProcessors", method -> .add("addImportAwareBeanPostProcessors", method ->
generateAddPostProcessorMethod(method, mappings)); generateAddPostProcessorMethod(method, mappings));
beanFactoryInitializationCode beanFactoryInitializationCode
.addInitializer(MethodReference.of(generatedMethod.getName())); .addInitializer(generatedMethod.toMethodReference());
ResourceHints hints = generationContext.getRuntimeHints().resources(); ResourceHints hints = generationContext.getRuntimeHints().resources();
mappings.forEach( mappings.forEach(
(target, from) -> hints.registerType(TypeReference.of(from))); (target, from) -> hints.registerType(TypeReference.of(from)));

View File

@ -55,7 +55,7 @@ public final class GeneratedClass {
GeneratedClass(ClassName name, Consumer<TypeSpec.Builder> type) { GeneratedClass(ClassName name, Consumer<TypeSpec.Builder> type) {
this.name = name; this.name = name;
this.type = type; this.type = type;
this.methods = new GeneratedMethods(this::generateSequencedMethodName); this.methods = new GeneratedMethods(name, this::generateSequencedMethodName);
} }

View File

@ -18,6 +18,9 @@ package org.springframework.aot.generate;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.lang.model.element.Modifier;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.MethodSpec;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -25,11 +28,14 @@ import org.springframework.util.Assert;
* A generated method. * A generated method.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
* @since 6.0 * @since 6.0
* @see GeneratedMethods * @see GeneratedMethods
*/ */
public final class GeneratedMethod { public final class GeneratedMethod {
private final ClassName className;
private final String name; private final String name;
private final MethodSpec methodSpec; private final MethodSpec methodSpec;
@ -39,12 +45,14 @@ public final class GeneratedMethod {
* Create a new {@link GeneratedMethod} instance with the given name. This * Create a new {@link GeneratedMethod} instance with the given name. This
* constructor is package-private since names should only be generated via * constructor is package-private since names should only be generated via
* {@link GeneratedMethods}. * {@link GeneratedMethods}.
* @param className the declaring class of the method
* @param name the generated method name * @param name the generated method name
* @param method consumer to generate the method * @param method consumer to generate the method
*/ */
GeneratedMethod(String name, Consumer<MethodSpec.Builder> method) { GeneratedMethod(ClassName className, String name, Consumer<MethodSpec.Builder> method) {
this.className = className;
this.name = name; this.name = name;
MethodSpec.Builder builder = MethodSpec.methodBuilder(getName()); MethodSpec.Builder builder = MethodSpec.methodBuilder(this.name);
method.accept(builder); method.accept(builder);
this.methodSpec = builder.build(); this.methodSpec = builder.build();
Assert.state(this.name.equals(this.methodSpec.name), Assert.state(this.name.equals(this.methodSpec.name),
@ -60,6 +68,16 @@ public final class GeneratedMethod {
return this.name; return this.name;
} }
/**
* Return a {@link MethodReference} to this generated method.
* @return a method reference
*/
public MethodReference toMethodReference() {
return (this.methodSpec.modifiers.contains(Modifier.STATIC)
? MethodReference.ofStatic(this.className, this.name)
: MethodReference.of(this.className, this.name));
}
/** /**
* Return the {@link MethodSpec} for this generated method. * Return the {@link MethodSpec} for this generated method.
* @return the method spec * @return the method spec

View File

@ -22,6 +22,7 @@ import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.MethodSpec;
import org.springframework.javapoet.MethodSpec.Builder; import org.springframework.javapoet.MethodSpec.Builder;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -30,11 +31,14 @@ import org.springframework.util.Assert;
* A managed collection of generated methods. * A managed collection of generated methods.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
* @since 6.0 * @since 6.0
* @see GeneratedMethod * @see GeneratedMethod
*/ */
public class GeneratedMethods { public class GeneratedMethods {
private final ClassName className;
private final Function<MethodName, String> methodNameGenerator; private final Function<MethodName, String> methodNameGenerator;
private final MethodName prefix; private final MethodName prefix;
@ -44,18 +48,22 @@ public class GeneratedMethods {
/** /**
* Create a new {@link GeneratedMethods} using the specified method name * Create a new {@link GeneratedMethods} using the specified method name
* generator. * generator.
* @param className the declaring class name
* @param methodNameGenerator the method name generator * @param methodNameGenerator the method name generator
*/ */
GeneratedMethods(Function<MethodName, String> methodNameGenerator) { GeneratedMethods(ClassName className, Function<MethodName, String> methodNameGenerator) {
Assert.notNull(className, "'className' must not be null");
Assert.notNull(methodNameGenerator, "'methodNameGenerator' must not be null"); Assert.notNull(methodNameGenerator, "'methodNameGenerator' must not be null");
this.className = className;
this.methodNameGenerator = methodNameGenerator; this.methodNameGenerator = methodNameGenerator;
this.prefix = MethodName.NONE; this.prefix = MethodName.NONE;
this.generatedMethods = new ArrayList<>(); this.generatedMethods = new ArrayList<>();
} }
private GeneratedMethods(Function<MethodName, String> methodNameGenerator, private GeneratedMethods(ClassName className, Function<MethodName, String> methodNameGenerator,
MethodName prefix, List<GeneratedMethod> generatedMethods) { MethodName prefix, List<GeneratedMethod> generatedMethods) {
this.className = className;
this.methodNameGenerator = methodNameGenerator; this.methodNameGenerator = methodNameGenerator;
this.prefix = prefix; this.prefix = prefix;
this.generatedMethods = generatedMethods; this.generatedMethods = generatedMethods;
@ -82,7 +90,7 @@ public class GeneratedMethods {
Assert.notNull(suggestedNameParts, "'suggestedNameParts' must not be null"); Assert.notNull(suggestedNameParts, "'suggestedNameParts' must not be null");
Assert.notNull(method, "'method' must not be null"); Assert.notNull(method, "'method' must not be null");
String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedNameParts)); String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedNameParts));
GeneratedMethod generatedMethod = new GeneratedMethod(generatedName, method); GeneratedMethod generatedMethod = new GeneratedMethod(this.className, generatedName, method);
this.generatedMethods.add(generatedMethod); this.generatedMethods.add(generatedMethod);
return generatedMethod; return generatedMethod;
} }
@ -90,7 +98,8 @@ public class GeneratedMethods {
public GeneratedMethods withPrefix(String prefix) { public GeneratedMethods withPrefix(String prefix) {
Assert.notNull(prefix, "'prefix' must not be null"); Assert.notNull(prefix, "'prefix' must not be null");
return new GeneratedMethods(this.methodNameGenerator, this.prefix.and(prefix), this.generatedMethods); return new GeneratedMethods(this.className, this.methodNameGenerator,
this.prefix.and(prefix), this.generatedMethods);
} }
/** /**

View File

@ -18,8 +18,12 @@ package org.springframework.aot.generate;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.lang.model.element.Modifier;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.MethodSpec;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -29,30 +33,55 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* Tests for {@link GeneratedMethod}. * Tests for {@link GeneratedMethod}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
*/ */
class GeneratedMethodTests { class GeneratedMethodTests {
private static final Consumer<MethodSpec.Builder> methodSpecCustomizer = method -> {}; private static final ClassName TEST_CLASS_NAME = ClassName.get("com.example", "Test");
private static final Consumer<MethodSpec.Builder> emptyMethod = method -> {};
private static final String NAME = "spring"; private static final String NAME = "spring";
@Test @Test
void getNameReturnsName() { void getNameReturnsName() {
GeneratedMethod generatedMethod = new GeneratedMethod(NAME, methodSpecCustomizer); GeneratedMethod generatedMethod = new GeneratedMethod(TEST_CLASS_NAME, NAME, emptyMethod);
assertThat(generatedMethod.getName()).isSameAs(NAME); assertThat(generatedMethod.getName()).isSameAs(NAME);
} }
@Test @Test
void generateMethodSpecReturnsMethodSpec() { void generateMethodSpecReturnsMethodSpec() {
GeneratedMethod generatedMethod = new GeneratedMethod(NAME, method -> method.addJavadoc("Test")); GeneratedMethod generatedMethod = create(method -> method.addJavadoc("Test"));
assertThat(generatedMethod.getMethodSpec().javadoc).asString().contains("Test"); assertThat(generatedMethod.getMethodSpec().javadoc).asString().contains("Test");
} }
@Test @Test
void generateMethodSpecWhenMethodNameIsChangedThrowsException() { void generateMethodSpecWhenMethodNameIsChangedThrowsException() {
assertThatIllegalStateException().isThrownBy(() -> assertThatIllegalStateException().isThrownBy(() ->
new GeneratedMethod(NAME, method -> method.setName("badname")).getMethodSpec()) create(method -> method.setName("badname")).getMethodSpec())
.withMessage("'method' consumer must not change the generated method name"); .withMessage("'method' consumer must not change the generated method name");
}
@Test
void toMethodReferenceWithInstanceMethod() {
GeneratedMethod generatedMethod = create(emptyMethod);
MethodReference methodReference = generatedMethod.toMethodReference();
assertThat(methodReference).isNotNull();
assertThat(methodReference.toInvokeCodeBlock("test"))
.isEqualTo(CodeBlock.of("test.spring()"));
}
@Test
void toMethodReferenceWithStaticMethod() {
GeneratedMethod generatedMethod = create(method -> method.addModifiers(Modifier.STATIC));
MethodReference methodReference = generatedMethod.toMethodReference();
assertThat(methodReference).isNotNull();
assertThat(methodReference.toInvokeCodeBlock())
.isEqualTo(CodeBlock.of("com.example.Test.spring()"));
}
private GeneratedMethod create(Consumer<MethodSpec.Builder> method) {
return new GeneratedMethod(TEST_CLASS_NAME, NAME, method);
} }
} }

View File

@ -23,6 +23,7 @@ import java.util.function.Function;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.MethodSpec;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -32,38 +33,49 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
* Tests for {@link GeneratedMethods}. * Tests for {@link GeneratedMethods}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
*/ */
class GeneratedMethodsTests { class GeneratedMethodsTests {
private static final ClassName TEST_CLASS_NAME = ClassName.get("com.example", "Test");
private static final Consumer<MethodSpec.Builder> methodSpecCustomizer = method -> {}; private static final Consumer<MethodSpec.Builder> methodSpecCustomizer = method -> {};
private final GeneratedMethods methods = new GeneratedMethods(MethodName::toString); private final GeneratedMethods methods = new GeneratedMethods(TEST_CLASS_NAME, MethodName::toString);
@Test
void createWhenClassNameIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() ->
new GeneratedMethods(null, MethodName::toString))
.withMessage("'className' must not be null");
}
@Test @Test
void createWhenMethodNameGeneratorIsNullThrowsException() { void createWhenMethodNameGeneratorIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new GeneratedMethods(null)) assertThatIllegalArgumentException().isThrownBy(() ->
new GeneratedMethods(TEST_CLASS_NAME, null))
.withMessage("'methodNameGenerator' must not be null"); .withMessage("'methodNameGenerator' must not be null");
} }
@Test @Test
void createWithExistingGeneratorUsesGenerator() { void createWithExistingGeneratorUsesGenerator() {
Function<MethodName, String> generator = name -> "__" + name.toString(); Function<MethodName, String> generator = name -> "__" + name.toString();
GeneratedMethods methods = new GeneratedMethods(generator); GeneratedMethods methods = new GeneratedMethods(TEST_CLASS_NAME, generator);
assertThat(methods.add("test", methodSpecCustomizer).getName()).hasToString("__test"); assertThat(methods.add("test", methodSpecCustomizer).getName()).hasToString("__test");
} }
@Test @Test
void addWithStringNameWhenSuggestedMethodIsNullThrowsException() { void addWithStringNameWhenSuggestedMethodIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
this.methods.add((String) null, methodSpecCustomizer)) this.methods.add((String) null, methodSpecCustomizer))
.withMessage("'suggestedName' must not be null"); .withMessage("'suggestedName' must not be null");
} }
@Test @Test
void addWithStringNameWhenMethodIsNullThrowsException() { void addWithStringNameWhenMethodIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() ->
this.methods.add("test", null)) this.methods.add("test", null))
.withMessage("'method' must not be null"); .withMessage("'method' must not be null");
} }
@Test @Test
@ -71,7 +83,7 @@ class GeneratedMethodsTests {
this.methods.add("springBeans", methodSpecCustomizer); this.methods.add("springBeans", methodSpecCustomizer);
this.methods.add("springContext", methodSpecCustomizer); this.methods.add("springContext", methodSpecCustomizer);
assertThat(this.methods.stream().map(GeneratedMethod::getName).map(Object::toString)) assertThat(this.methods.stream().map(GeneratedMethod::getName).map(Object::toString))
.containsExactly("springBeans", "springContext"); .containsExactly("springBeans", "springContext");
} }
@Test @Test

View File

@ -99,7 +99,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr
List.class, toCodeBlock(persistenceManagedTypes.getManagedPackages())); List.class, toCodeBlock(persistenceManagedTypes.getManagedPackages()));
method.addStatement("return $T.of($L, $L)", beanType, "managedClassNames", "managedPackages"); method.addStatement("return $T.of($L, $L)", beanType, "managedClassNames", "managedPackages");
}); });
return CodeBlock.of("() -> $T.$L()", beanRegistrationCode.getClassName(), generatedMethod.getName()); return generatedMethod.toMethodReference().toCodeBlock();
} }
private CodeBlock toCodeBlock(List<String> values) { private CodeBlock toCodeBlock(List<String> values) {

View File

@ -43,7 +43,6 @@ import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GeneratedMethods; import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHints;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.PropertyValues; import org.springframework.beans.PropertyValues;
@ -797,8 +796,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
method.returns(this.target); method.returns(this.target);
method.addCode(generateMethodCode(generationContext.getRuntimeHints(), generatedClass.getMethods())); method.addCode(generateMethodCode(generationContext.getRuntimeHints(), generatedClass.getMethods()));
}); });
beanRegistrationCode.addInstancePostProcessor(MethodReference beanRegistrationCode.addInstancePostProcessor(generatedMethod.toMethodReference());
.ofStatic(generatedClass.getName(), generatedMethod.getName()));
} }
private CodeBlock generateMethodCode(RuntimeHints hints, GeneratedMethods generatedMethods) { private CodeBlock generateMethodCode(RuntimeHints hints, GeneratedMethods generatedMethods) {