Browse Source

Polishing

pull/28842/head
Phillip Webb 2 years ago
parent
commit
578f155809
  1. 4
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java
  2. 14
      spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java
  3. 4
      spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

4
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java

@ -153,7 +153,7 @@ class BeanDefinitionMethodGenerator { @@ -153,7 +153,7 @@ class BeanDefinitionMethodGenerator {
nonGeneratedParent = nonGeneratedParent.getParent();
}
if (nonGeneratedParent != null) {
return StringUtils.uncapitalize(getSimpleBeanName(nonGeneratedParent.getBeanName()) + "InnerBean");
return getSimpleBeanName(nonGeneratedParent.getBeanName()) + "InnerBean";
}
return "innerBean";
}
@ -163,7 +163,7 @@ class BeanDefinitionMethodGenerator { @@ -163,7 +163,7 @@ class BeanDefinitionMethodGenerator {
beanName = (lastDot != -1) ? beanName.substring(lastDot + 1) : beanName;
int lastDollar = beanName.lastIndexOf('$');
beanName = (lastDollar != -1) ? beanName.substring(lastDollar + 1) : beanName;
return beanName;
return StringUtils.uncapitalize(beanName);
}
}

14
spring-core/src/main/java/org/springframework/aot/generate/GeneratedMethods.java

@ -69,13 +69,25 @@ public class GeneratedMethods { @@ -69,13 +69,25 @@ public class GeneratedMethods {
*/
public GeneratedMethod add(String suggestedName, Consumer<Builder> method) {
Assert.notNull(suggestedName, "'suggestedName' must not be null");
return add(new String[] { suggestedName }, method);
}
/**
* Add a new {@link GeneratedMethod}.
* @param suggestedNameParts the suggested name parts for the method
* @param method a {@link Consumer} used to build method
* @return the newly added {@link GeneratedMethod}
*/
public GeneratedMethod add(String[] suggestedNameParts, Consumer<Builder> method) {
Assert.notNull(suggestedNameParts, "'suggestedNameParts' must not be null");
Assert.notNull(method, "'method' must not be null");
String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedName));
String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedNameParts));
GeneratedMethod generatedMethod = new GeneratedMethod(generatedName, method);
this.generatedMethods.add(generatedMethod);
return generatedMethod;
}
public GeneratedMethods withPrefix(String prefix) {
Assert.notNull(prefix, "'prefix' must not be null");
return new GeneratedMethods(this.methodNameGenerator, this.prefix.and(prefix), this.generatedMethods);

4
spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

@ -825,8 +825,8 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar @@ -825,8 +825,8 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
EntityManagerFactoryUtils.class, ListableBeanFactory.class,
REGISTERED_BEAN_PARAMETER, unitName);
}
String methodName = "get" + StringUtils.capitalize(unitName) + "EntityManager";
GeneratedMethod generatedMethod = generatedMethods.add(methodName, method ->
String[] methodNameParts = { "get" , unitName, "EntityManager" };
GeneratedMethod generatedMethod = generatedMethods.add(methodNameParts, method ->
generateGetEntityManagerMethod(method, injectedElement));
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
}

Loading…
Cancel
Save