Skip to content

Commit 87b83e8

Browse files
committed
Make MethodName package-private
Closes gh-28832
1 parent 0ea4ee1 commit 87b83e8

File tree

5 files changed

+8
-34
lines changed

5 files changed

+8
-34
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import org.springframework.aot.generate.GeneratedMethod;
2626
import org.springframework.aot.generate.GeneratedMethods;
2727
import org.springframework.aot.generate.GenerationContext;
28-
import org.springframework.aot.generate.MethodName;
2928
import org.springframework.aot.generate.MethodReference;
3029
import org.springframework.beans.factory.config.BeanDefinition;
3130
import org.springframework.beans.factory.support.RegisteredBean;
3231
import org.springframework.javapoet.ClassName;
3332
import org.springframework.lang.Nullable;
33+
import org.springframework.util.StringUtils;
3434

3535
/**
3636
* Generates a method that returns a {@link BeanDefinition} to be registered.
@@ -153,7 +153,7 @@ private String getName() {
153153
nonGeneratedParent = nonGeneratedParent.getParent();
154154
}
155155
if (nonGeneratedParent != null) {
156-
return MethodName.of(getSimpleBeanName(nonGeneratedParent.getBeanName()), "innerBean").toString();
156+
return StringUtils.uncapitalize(getSimpleBeanName(nonGeneratedParent.getBeanName()) + "InnerBean");
157157
}
158158
return "innerBean";
159159
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ private GeneratedMethods(Function<MethodName, String> methodNameGenerator,
6868
* @return the newly added {@link GeneratedMethod}
6969
*/
7070
public GeneratedMethod add(String suggestedName, Consumer<Builder> method) {
71-
Assert.notNull(suggestedName, "'suggestedName' must not be null");
72-
return add(MethodName.of(suggestedName), method);
73-
}
74-
75-
/**
76-
* Add a new {@link GeneratedMethod}.
77-
* @param suggestedName the suggested name for the method
78-
* @param method a {@link Consumer} used to build the method
79-
* @return the newly added {@link GeneratedMethod}
80-
*/
81-
public GeneratedMethod add(MethodName suggestedName, Consumer<Builder> method) {
8271
Assert.notNull(suggestedName, "'suggestedName' must not be null");
8372
Assert.notNull(method, "'method' must not be null");
8473
String generatedName = this.methodNameGenerator.apply(this.prefix.and(suggestedName));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Phillip Webb
2929
* @since 6.0
3030
*/
31-
public final class MethodName {
31+
final class MethodName {
3232

3333
private static final String[] PREFIXES = { "get", "set", "is" };
3434

@@ -51,7 +51,7 @@ private MethodName(String value) {
5151
* @param parts the parts the form the name
5252
* @return a method name instance
5353
*/
54-
public static MethodName of(String... parts) {
54+
static MethodName of(String... parts) {
5555
Assert.notNull(parts, "'parts' must not be null");
5656
return new MethodName(join(parts));
5757
}
@@ -61,7 +61,7 @@ public static MethodName of(String... parts) {
6161
* @param name the name to concatenate
6262
* @return a new method name instance
6363
*/
64-
public MethodName and(MethodName name) {
64+
MethodName and(MethodName name) {
6565
Assert.notNull(name, "'name' must not be null");
6666
return and(name.value);
6767
}
@@ -71,7 +71,7 @@ public MethodName and(MethodName name) {
7171
* @param parts the parts to concatenate
7272
* @return a new method name instance
7373
*/
74-
public MethodName and(String... parts) {
74+
MethodName and(String... parts) {
7575
Assert.notNull(parts, "'parts' must not be null");
7676
String joined = join(parts);
7777
String prefix = getPrefix(joined);

spring-core/src/test/java/org/springframework/aot/generate/GeneratedMethodsTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ void createWithExistingGeneratorUsesGenerator() {
5252
assertThat(methods.add("test", methodSpecCustomizer).getName()).hasToString("__test");
5353
}
5454

55-
@Test
56-
void addWithMethodNameWhenSuggestedMethodIsNullThrowsException() {
57-
assertThatIllegalArgumentException().isThrownBy(() ->
58-
this.methods.add((MethodName) null, methodSpecCustomizer))
59-
.withMessage("'suggestedName' must not be null");
60-
}
61-
62-
@Test
63-
void addWithMethodNameWhenMethodIsNullThrowsException() {
64-
assertThatIllegalArgumentException().isThrownBy(() ->
65-
this.methods.add(MethodName.of("test"), null))
66-
.withMessage("'method' must not be null");
67-
}
68-
6955
@Test
7056
void addWithStringNameWhenSuggestedMethodIsNullThrowsException() {
7157
assertThatIllegalArgumentException().isThrownBy(() ->

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.springframework.aot.generate.GeneratedMethod;
4444
import org.springframework.aot.generate.GeneratedMethods;
4545
import org.springframework.aot.generate.GenerationContext;
46-
import org.springframework.aot.generate.MethodName;
4746
import org.springframework.aot.generate.MethodReference;
4847
import org.springframework.aot.hint.RuntimeHints;
4948
import org.springframework.beans.BeanUtils;
@@ -826,8 +825,8 @@ private CodeBlock generateResourceToInjectCode(GeneratedMethods generatedMethods
826825
EntityManagerFactoryUtils.class, ListableBeanFactory.class,
827826
REGISTERED_BEAN_PARAMETER, unitName);
828827
}
829-
GeneratedMethod generatedMethod = generatedMethods
830-
.add(MethodName.of("get", unitName, "EntityManager"), method ->
828+
String methodName = "get" + StringUtils.capitalize(unitName) + "EntityManager";
829+
GeneratedMethod generatedMethod = generatedMethods.add(methodName, method ->
831830
generateGetEntityManagerMethod(method, injectedElement));
832831
return CodeBlock.of("$L($L)", generatedMethod.getName(), REGISTERED_BEAN_PARAMETER);
833832
}

0 commit comments

Comments
 (0)