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

@@ -99,7 +99,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr
List.class, toCodeBlock(persistenceManagedTypes.getManagedPackages()));
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) {

View File

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