Polishing

This commit is contained in:
Phillip Webb 2022-07-18 15:01:32 +01:00
parent 444e06fa22
commit 578f155809
3 changed files with 17 additions and 5 deletions

View File

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

View File

@ -69,13 +69,25 @@ public class GeneratedMethods {
*/ */
public GeneratedMethod add(String suggestedName, Consumer<Builder> method) { public GeneratedMethod add(String suggestedName, Consumer<Builder> method) {
Assert.notNull(suggestedName, "'suggestedName' must not be null"); 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"); 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); GeneratedMethod generatedMethod = new GeneratedMethod(generatedName, method);
this.generatedMethods.add(generatedMethod); this.generatedMethods.add(generatedMethod);
return generatedMethod; return generatedMethod;
} }
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.methodNameGenerator, this.prefix.and(prefix), this.generatedMethods);

View File

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