Skip to content

Commit 3536666

Browse files
committed
Polishing
1 parent 263811e commit 3536666

File tree

8 files changed

+23
-30
lines changed

8 files changed

+23
-30
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ JavaFile generateJavaFile() {
7373
TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(this.name);
7474
this.typeSpecCustomizer.accept(typeSpecBuilder);
7575
this.methods.doWithMethodSpecs(typeSpecBuilder::addMethod);
76-
return JavaFile.builder(this.name.packageName(), typeSpecBuilder.build())
77-
.build();
76+
return JavaFile.builder(this.name.packageName(), typeSpecBuilder.build()).build();
7877
}
7978

8079
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ public GeneratedClass generate(Consumer<TypeSpec.Builder> typeSpecCustomizer) {
142142
* @param typeSpecCustomizer a customizer for the {@link TypeSpec.Builder}
143143
* @return a {@link GeneratedClass} instance
144144
*/
145-
public GeneratedClass getOrGenerate(String id,
146-
Consumer<TypeSpec.Builder> typeSpecCustomizer) {
145+
public GeneratedClass getOrGenerate(String id, Consumer<TypeSpec.Builder> typeSpecCustomizer) {
147146
Assert.hasLength(id, "'id' must not be empty");
148147
Assert.notNull(typeSpecCustomizer, "'typeSpecCustomizer' must not be null");
149148
Owner owner = new Owner(id, GeneratedClasses.this.classNameGenerator

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* Interface that can be used to add {@link Kind#SOURCE source},
27-
* {@link Kind#RESOURCE resource} or {@link Kind#CLASS class} files generated
27+
* {@link Kind#RESOURCE resource}, or {@link Kind#CLASS class} files generated
2828
* during ahead-of-time processing. Source and resource files are written using
2929
* UTF-8 encoding.
3030
*
@@ -191,14 +191,14 @@ enum Kind {
191191
SOURCE,
192192

193193
/**
194-
* A resource file that should be directly added to final application.
194+
* A resource file that should be directly added to the final application.
195195
* For example, a {@code .properties} file.
196196
*/
197197
RESOURCE,
198198

199199
/**
200200
* A class file containing bytecode. For example, the result of a proxy
201-
* generated using cglib.
201+
* generated using CGLIB.
202202
*/
203203
CLASS
204204

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class GeneratedMethod {
4141

4242
/**
4343
* Create a new {@link GeneratedMethod} instance with the given name. This
44-
* constructor is package-private since names should only be generated via a
44+
* constructor is package-private since names should only be generated via
4545
* {@link GeneratedMethods}.
4646
* @param name the generated name
4747
*/
@@ -66,7 +66,7 @@ public String getName() {
6666
*/
6767
public MethodSpec getSpec() {
6868
Assert.state(this.spec != null,
69-
() -> String.format("Method '%s' has no method spec defined", this.name));
69+
() -> "Method '%s' has no method spec defined".formatted(this.name));
7070
return this.spec;
7171
}
7272

@@ -86,8 +86,8 @@ public GeneratedMethod using(Consumer<MethodSpec.Builder> builder) {
8686
}
8787

8888
private void assertNameHasNotBeenChanged(MethodSpec spec) {
89-
Assert.isTrue(this.name.equals(spec.name), () -> String
90-
.format("'spec' must use the generated name \"%s\"", this.name));
89+
Assert.isTrue(this.name.equals(spec.name),
90+
() -> "'spec' must use the generated name '%s'".formatted(this.name));
9191
}
9292

9393
@Override

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public void addFile(Kind kind, String path, InputStreamSource content) {
4545
Assert.notNull(content, "'content' must not be null");
4646
Map<String, InputStreamSource> paths = this.files.computeIfAbsent(kind,
4747
key -> new LinkedHashMap<>());
48-
Assert.state(!paths.containsKey(path),
49-
() -> "Path '" + path + "' already in use");
48+
Assert.state(!paths.containsKey(path), () -> "Path '" + path + "' already in use");
5049
paths.put(path, content);
5150
}
5251

@@ -57,8 +56,7 @@ public void addFile(Kind kind, String path, InputStreamSource content) {
5756
*/
5857
public Map<String, InputStreamSource> getGeneratedFiles(Kind kind) {
5958
Assert.notNull(kind, "'kind' must not be null");
60-
return Collections
61-
.unmodifiableMap(this.files.getOrDefault(kind, Collections.emptyMap()));
59+
return Collections.unmodifiableMap(this.files.getOrDefault(kind, Collections.emptyMap()));
6260
}
6361

6462
/**
@@ -72,8 +70,7 @@ public Map<String, InputStreamSource> getGeneratedFiles(Kind kind) {
7270
public String getGeneratedFileContent(Kind kind, String path) throws IOException {
7371
InputStreamSource source = getGeneratedFile(kind, path);
7472
if (source != null) {
75-
return new String(source.getInputStream().readAllBytes(),
76-
StandardCharsets.UTF_8);
73+
return new String(source.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
7774
}
7875
return null;
7976
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ private String addSequence(String name) {
9595
public static String join(Object... parts) {
9696
Stream<String> capitalizedPartNames = Arrays.stream(parts)
9797
.map(MethodNameGenerator::getPartName).map(StringUtils::capitalize);
98-
return StringUtils
99-
.uncapitalize(capitalizedPartNames.collect(Collectors.joining()));
98+
return StringUtils.uncapitalize(capitalizedPartNames.collect(Collectors.joining()));
10099
}
101100

102101
private static String getPartName(@Nullable Object part) {

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ public CodeBlock toCodeBlock() {
144144
*/
145145
public CodeBlock toCodeBlock(@Nullable String instanceVariable) {
146146
return switch (this.kind) {
147-
case INSTANCE -> toCodeBlockForInstance(instanceVariable);
148-
case STATIC -> toCodeBlockForStatic(instanceVariable);
147+
case INSTANCE -> toCodeBlockForInstance(instanceVariable);
148+
case STATIC -> toCodeBlockForStatic(instanceVariable);
149149
};
150150
}
151151

152152
private CodeBlock toCodeBlockForInstance(@Nullable String instanceVariable) {
153153
instanceVariable = (instanceVariable != null) ? instanceVariable : "this";
154154
return CodeBlock.of("$L::$L", instanceVariable, this.methodName);
155-
156155
}
157156

158157
private CodeBlock toCodeBlockForStatic(@Nullable String instanceVariable) {
@@ -180,8 +179,8 @@ public CodeBlock toInvokeCodeBlock(@Nullable String instanceVariable,
180179
CodeBlock... arguments) {
181180

182181
return switch (this.kind) {
183-
case INSTANCE -> toInvokeCodeBlockForInstance(instanceVariable, arguments);
184-
case STATIC -> toInvokeCodeBlockForStatic(instanceVariable, arguments);
182+
case INSTANCE -> toInvokeCodeBlockForInstance(instanceVariable, arguments);
183+
case STATIC -> toInvokeCodeBlockForStatic(instanceVariable, arguments);
185184
};
186185
}
187186

@@ -225,9 +224,9 @@ private void addArguments(CodeBlock.Builder builder, CodeBlock[] arguments) {
225224
@Override
226225
public String toString() {
227226
return switch (this.kind) {
228-
case INSTANCE -> ((this.declaringClass != null) ? "<" + this.declaringClass + ">"
229-
: "<instance>") + "::" + this.methodName;
230-
case STATIC -> this.declaringClass + "::" + this.methodName;
227+
case INSTANCE -> ((this.declaringClass != null) ? "<" + this.declaringClass + ">"
228+
: "<instance>") + "::" + this.methodName;
229+
case STATIC -> this.declaringClass + "::" + this.methodName;
231230
};
232231
}
233232

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void getNameReturnsName() {
4343
void getSpecReturnsSpec() {
4444
GeneratedMethod method = new GeneratedMethod(NAME);
4545
method.using(builder -> builder.addJavadoc("Test"));
46-
assertThat(method.getSpec().javadoc.toString()).contains("Test");
46+
assertThat(method.getSpec().javadoc).asString().contains("Test");
4747
}
4848

4949
@Test
@@ -57,7 +57,7 @@ void getSpecReturnsSpecWhenNoSpecDefinedThrowsException() {
5757
void usingAddsSpec() {
5858
GeneratedMethod method = new GeneratedMethod(NAME);
5959
method.using(builder -> builder.addModifiers(Modifier.PUBLIC));
60-
assertThat(method.getSpec().toString())
60+
assertThat(method.getSpec()).asString()
6161
.isEqualToIgnoringNewLines("public void spring() {}");
6262
}
6363

@@ -66,7 +66,7 @@ void usingWhenBuilderChanagesNameThrowsException() {
6666
GeneratedMethod method = new GeneratedMethod(NAME);
6767
assertThatIllegalArgumentException()
6868
.isThrownBy(() -> method.using(builder -> builder.setName("badname")))
69-
.withMessage("'spec' must use the generated name \"spring\"");
69+
.withMessage("'spec' must use the generated name 'spring'");
7070
}
7171

7272
}

0 commit comments

Comments
 (0)