Polishing

(cherry picked from commit 8fe1de4595)
This commit is contained in:
Juergen Hoeller
2026-05-13 19:46:07 +02:00
parent 57b62dd73a
commit 444877a475
3 changed files with 8 additions and 12 deletions
@@ -31,6 +31,7 @@ public class AotBeanProcessingException extends AotProcessingException {
private final RootBeanDefinition beanDefinition;
/**
* Create an instance with the {@link RegisteredBean} that fails to be
* processed, a detail message, and an optional root cause.
@@ -64,6 +65,7 @@ public class AotBeanProcessingException extends AotProcessingException {
return sb.toString();
}
/**
* Return the bean definition of the bean that failed to be processed.
*/
@@ -885,16 +885,13 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
});
GeneratedMethod generateMethod = generatedClass.getMethods().add("apply", method -> {
method.addJavadoc("Apply resource autowiring.");
method.addModifiers(javax.lang.model.element.Modifier.PUBLIC,
javax.lang.model.element.Modifier.STATIC);
method.addModifiers(javax.lang.model.element.Modifier.PUBLIC, javax.lang.model.element.Modifier.STATIC);
method.addParameter(RegisteredBean.class, REGISTERED_BEAN_PARAMETER);
method.addParameter(this.target, INSTANCE_PARAMETER);
method.returns(this.target);
method.addCode(generateMethodCode(generatedClass.getName(),
generationContext.getRuntimeHints()));
method.addCode(generateMethodCode(generatedClass.getName(), generationContext.getRuntimeHints()));
});
beanRegistrationCode.addInstancePostProcessor(generateMethod.toMethodReference());
registerHints(generationContext.getRuntimeHints());
}
@@ -856,12 +856,11 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
}
@SuppressWarnings("NullAway")
private void generateGetEntityManagerMethod(MethodSpec.Builder method, PersistenceElement injectedElement) {
String unitName = injectedElement.unitName;
Properties properties = injectedElement.properties;
method.addJavadoc("Get the '$L' {@link $T}.",
(StringUtils.hasLength(unitName)) ? unitName : "default",
(StringUtils.hasLength(unitName) ? unitName : "default"),
EntityManager.class);
method.addModifiers(javax.lang.model.element.Modifier.PUBLIC,
javax.lang.model.element.Modifier.STATIC);
@@ -871,10 +870,8 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
"$T entityManagerFactory = $T.findEntityManagerFactory(($T) $L.getBeanFactory(), $S)",
EntityManagerFactory.class, EntityManagerFactoryUtils.class,
ListableBeanFactory.class, REGISTERED_BEAN_PARAMETER, unitName);
boolean hasProperties = !CollectionUtils.isEmpty(properties);
if (hasProperties) {
method.addStatement("$T properties = new Properties()",
Properties.class);
if (properties != null) {
method.addStatement("$T properties = new Properties()", Properties.class);
for (String propertyName : new TreeSet<>(properties.stringPropertyNames())) {
method.addStatement("properties.put($S, $S)", propertyName, properties.getProperty(propertyName));
}
@@ -882,7 +879,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
method.addStatement(
"return $T.createSharedEntityManager(entityManagerFactory, $L, $L)",
SharedEntityManagerCreator.class,
(hasProperties) ? "properties" : null,
(properties != null ? "properties" : null),
injectedElement.synchronizedWithTransaction);
}
}