Skip to content

Commit 8627bef

Browse files
committed
Polishing
1 parent 16e7f1f commit 8627bef

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ public FileSystemGeneratedFiles(Function<Kind, Path> roots) {
7373
private static Function<Kind, Path> conventionRoots(Path root) {
7474
Assert.notNull(root, "'root' must not be null");
7575
return kind -> switch (kind) {
76-
case SOURCE -> root.resolve("sources");
77-
case RESOURCE -> root.resolve("resources");
78-
case CLASS -> root.resolve("classes");
76+
case SOURCE -> root.resolve("sources");
77+
case RESOURCE -> root.resolve("resources");
78+
case CLASS -> root.resolve("classes");
7979
};
8080
}
8181

8282
@Override
8383
public void addFile(Kind kind, String path, InputStreamSource content) {
8484
Assert.notNull(kind, "'kind' must not be null");
8585
Assert.hasLength(path, "'path' must not be empty");
86-
Assert.notNull(content, "'kind' must not be null");
86+
Assert.notNull(content, "'content' must not be null");
8787
Path root = this.roots.apply(kind).toAbsolutePath().normalize();
8888
Path relativePath = root.resolve(path).toAbsolutePath().normalize();
8989
Assert.isTrue(relativePath.startsWith(root), () -> "'path' must be relative");

spring-core/src/main/java/org/springframework/util/ObjectUtils.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,33 +250,35 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
250250
* @return the new array (of the same component type; never {@code null})
251251
*/
252252
public static <A, O extends A> A[] addObjectToArray(@Nullable A[] array, @Nullable O obj) {
253-
return addObjectToArray(array, obj, (array != null) ? array.length : 0);
253+
return addObjectToArray(array, obj, (array != null ? array.length : 0));
254254
}
255255

256256
/**
257-
* Append the given object to the given array, returning a new array
258-
* consisting of the input array contents plus the given object.
259-
* @param array the array to append to (can be {@code null})
257+
* Add the given object to the given array at the specified position, returning
258+
* a new array consisting of the input array contents plus the given object.
259+
* @param array the array to add to (can be {@code null})
260260
* @param obj the object to append
261+
* @param position the position at which to add the object
261262
* @return the new array (of the same component type; never {@code null})
263+
* @since 6.0
262264
*/
263265
public static <A, O extends A> A[] addObjectToArray(@Nullable A[] array, @Nullable O obj, int position) {
264-
Class<?> compType = Object.class;
266+
Class<?> componentType = Object.class;
265267
if (array != null) {
266-
compType = array.getClass().getComponentType();
268+
componentType = array.getClass().getComponentType();
267269
}
268270
else if (obj != null) {
269-
compType = obj.getClass();
271+
componentType = obj.getClass();
270272
}
271-
int newArrLength = (array != null ? array.length + 1 : 1);
273+
int newArrayLength = (array != null ? array.length + 1 : 1);
272274
@SuppressWarnings("unchecked")
273-
A[] newArr = (A[]) Array.newInstance(compType, newArrLength);
275+
A[] newArray = (A[]) Array.newInstance(componentType, newArrayLength);
274276
if (array != null) {
275-
System.arraycopy(array, 0, newArr, 0, position);
276-
System.arraycopy(array, position, newArr, position + 1, array.length - position);
277+
System.arraycopy(array, 0, newArray, 0, position);
278+
System.arraycopy(array, position, newArray, position + 1, array.length - position);
277279
}
278-
newArr[position] = obj;
279-
return newArr;
280+
newArray[position] = obj;
281+
return newArray;
280282
}
281283

282284
/**

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ void addFilesCopiesToFileSystem() {
4646
generatedFiles.addResourceFile("META-INF/test", "test");
4747
generatedFiles.addClassFile("com/example/TestProxy.class",
4848
new ByteArrayResource("!".getBytes(StandardCharsets.UTF_8)));
49-
assertThat(this.root.resolve("sources/com/example/Test.java")).content()
50-
.isEqualTo("{}");
51-
assertThat(this.root.resolve("resources/META-INF/test")).content()
52-
.isEqualTo("test");
53-
assertThat(this.root.resolve("classes/com/example/TestProxy.class")).content()
54-
.isEqualTo("!");
49+
assertThat(this.root.resolve("sources/com/example/Test.java")).content().isEqualTo("{}");
50+
assertThat(this.root.resolve("resources/META-INF/test")).content().isEqualTo("test");
51+
assertThat(this.root.resolve("classes/com/example/TestProxy.class")).content().isEqualTo("!");
5552
}
5653

5754
@Test
@@ -62,12 +59,9 @@ void addFilesWithCustomRootsCopiesToFileSystem() {
6259
generatedFiles.addResourceFile("META-INF/test", "test");
6360
generatedFiles.addClassFile("com/example/TestProxy.class",
6461
new ByteArrayResource("!".getBytes(StandardCharsets.UTF_8)));
65-
assertThat(this.root.resolve("the-SOURCE/com/example/Test.java")).content()
66-
.isEqualTo("{}");
67-
assertThat(this.root.resolve("the-RESOURCE/META-INF/test")).content()
68-
.isEqualTo("test");
69-
assertThat(this.root.resolve("the-CLASS/com/example/TestProxy.class")).content()
70-
.isEqualTo("!");
62+
assertThat(this.root.resolve("the-SOURCE/com/example/Test.java")).content().isEqualTo("{}");
63+
assertThat(this.root.resolve("the-RESOURCE/META-INF/test")).content().isEqualTo("test");
64+
assertThat(this.root.resolve("the-CLASS/com/example/TestProxy.class")).content().isEqualTo("!");
7165
}
7266

7367
@Test
@@ -80,17 +74,15 @@ void createWhenRootIsNullThrowsException() {
8074
@Test
8175
void createWhenRootsIsNullThrowsException() {
8276
assertThatIllegalArgumentException()
83-
.isThrownBy(
84-
() -> new FileSystemGeneratedFiles((Function<Kind, Path>) null))
77+
.isThrownBy(() -> new FileSystemGeneratedFiles((Function<Kind, Path>) null))
8578
.withMessage("'roots' must not be null");
8679
}
8780

8881
@Test
8982
void createWhenRootsResultsInNullThrowsException() {
9083
assertThatIllegalArgumentException()
91-
.isThrownBy(
92-
() -> new FileSystemGeneratedFiles(kind -> (kind != Kind.CLASS)
93-
? this.root.resolve(kind.toString()) : null))
84+
.isThrownBy(() -> new FileSystemGeneratedFiles(kind -> (kind != Kind.CLASS) ?
85+
this.root.resolve(kind.toString()) : null))
9486
.withMessage("'roots' must return a value for all file kinds");
9587
}
9688

@@ -102,8 +94,7 @@ void addFileWhenPathIsOutsideOfRootThrowsException() {
10294
assertPathMustBeRelative(generatedFiles, "test/../../test");
10395
}
10496

105-
private void assertPathMustBeRelative(FileSystemGeneratedFiles generatedFiles,
106-
String path) {
97+
private void assertPathMustBeRelative(FileSystemGeneratedFiles generatedFiles, String path) {
10798
assertThatIllegalArgumentException()
10899
.isThrownBy(() -> generatedFiles.addResourceFile(path, "test"))
109100
.withMessage("'path' must be relative");

0 commit comments

Comments
 (0)