Skip to content

Commit a2445dc

Browse files
committed
Polishing
1 parent 911d1f2 commit a2445dc

File tree

6 files changed

+22
-33
lines changed

6 files changed

+22
-33
lines changed

spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private static List<TypeReference> toTypeReferences(Class<?>... proxiedInterface
158158
if (!invalidTypes.isEmpty()) {
159159
throw new IllegalArgumentException("The following must be non-sealed interfaces: " + invalidTypes);
160160
}
161-
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toList();
161+
return TypeReference.listOf(proxiedInterfaces);
162162
}
163163

164164
}

spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
import java.lang.reflect.Executable;
2121
import java.lang.reflect.Field;
2222
import java.lang.reflect.Method;
23-
import java.util.Arrays;
2423
import java.util.HashMap;
2524
import java.util.List;
2625
import java.util.Map;
2726
import java.util.function.Consumer;
28-
import java.util.stream.Collectors;
2927
import java.util.stream.Stream;
3028

3129
import org.springframework.aot.hint.TypeHint.Builder;
@@ -255,7 +253,7 @@ public ReflectionHints registerMethod(Method method, Consumer<ExecutableHint.Bui
255253
}
256254

257255
private List<TypeReference> mapParameters(Executable executable) {
258-
return Arrays.stream(executable.getParameterTypes()).map(TypeReference::of).collect(Collectors.toList());
256+
return TypeReference.listOf(executable.getParameterTypes());
259257
}
260258

261259
}

spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ private static final class ExecutableKey {
312312

313313
private ExecutableKey(String name, List<TypeReference> parameterTypes) {
314314
this.name = name;
315-
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName)
316-
.collect(Collectors.toList());
315+
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName).toList();
317316
}
318317

319318
@Override

spring-core/src/main/java/org/springframework/aot/hint/predicate/ProxyHintsPredicates.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.aot.hint.predicate;
1818

1919
import java.util.Arrays;
20+
import java.util.List;
2021
import java.util.function.Predicate;
2122

2223
import org.springframework.aot.hint.ProxyHints;
@@ -59,7 +60,9 @@ public Predicate<RuntimeHints> forInterfaces(Class<?>... interfaces) {
5960
*/
6061
public Predicate<RuntimeHints> forInterfaces(TypeReference... interfaces) {
6162
Assert.notEmpty(interfaces, "'interfaces' should not be empty");
63+
List<TypeReference> interfaceList = Arrays.asList(interfaces);
6264
return hints -> hints.proxies().jdkProxies().anyMatch(proxyHint ->
63-
proxyHint.getProxiedInterfaces().equals(Arrays.asList(interfaces)));
65+
proxyHint.getProxiedInterfaces().equals(interfaceList));
6466
}
67+
6568
}

spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
public class ReflectionHintsPredicates {
5050

5151
ReflectionHintsPredicates() {
52-
5352
}
5453

5554
/**
@@ -138,10 +137,10 @@ private Method getMethod(Class<?> type, String methodName) {
138137
return methods.iterator().next();
139138
}
140139
else if (methods.size() > 1) {
141-
throw new IllegalArgumentException(String.format("Found multiple methods named '%s' on class %s", methodName, type.getName()));
140+
throw new IllegalArgumentException("Found multiple methods named '%s' on class %s".formatted(methodName, type.getName()));
142141
}
143142
else {
144-
throw new IllegalArgumentException("No method named '" + methodName + "' on class " + type.getName());
143+
throw new IllegalArgumentException("No method named '%s' on class %s".formatted(methodName, type.getName()));
145144
}
146145
}
147146

@@ -160,7 +159,7 @@ public FieldHintPredicate onField(Class<?> type, String fieldName) {
160159
Assert.hasText(fieldName, "'fieldName' should not be empty");
161160
Field field = ReflectionUtils.findField(type, fieldName);
162161
if (field == null) {
163-
throw new IllegalArgumentException("No field named '" + fieldName + "' on class " + type.getName());
162+
throw new IllegalArgumentException("No field named '%s' on class %s".formatted(fieldName, type.getName()));
164163
}
165164
return new FieldHintPredicate(field);
166165
}
@@ -315,15 +314,13 @@ public boolean test(RuntimeHints runtimeHints) {
315314
/**
316315
* Indicate whether the specified {@code ExecutableHint} covers the
317316
* reflection needs of the specified executable definition.
318-
* @return {@code true} if the member matches (same type, name and parameters),
319-
* and the configured {@code ExecutableMode} is compatibe
317+
* @return {@code true} if the member matches (same type, name, and parameters),
318+
* and the configured {@code ExecutableMode} is compatible
320319
*/
321320
static boolean includes(ExecutableHint hint, String name,
322321
List<TypeReference> parameterTypes, ExecutableMode executableModes) {
323-
return hint.getName().equals(name)
324-
&& hint.getParameterTypes().equals(parameterTypes)
325-
&& (hint.getMode().equals(ExecutableMode.INVOKE)
326-
|| !executableModes.equals(ExecutableMode.INVOKE));
322+
return hint.getName().equals(name) && hint.getParameterTypes().equals(parameterTypes) &&
323+
(hint.getMode().equals(ExecutableMode.INVOKE) || !executableModes.equals(ExecutableMode.INVOKE));
327324
}
328325
}
329326

@@ -355,18 +352,15 @@ MemberCategory[] getDeclaredMemberCategories() {
355352
Predicate<RuntimeHints> exactMatch() {
356353
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
357354
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).constructors().anyMatch(executableHint -> {
358-
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
359-
.map(TypeReference::of).toList();
360-
return includes(executableHint, "<init>",
361-
parameters, this.executableMode);
355+
List<TypeReference> parameters = TypeReference.listOf(this.executable.getParameterTypes());
356+
return includes(executableHint, "<init>", parameters, this.executableMode);
362357
});
363358
}
364359

365360
}
366361

367362
public static class MethodHintPredicate extends ExecutableHintPredicate<Method> {
368363

369-
370364
MethodHintPredicate(Method method) {
371365
super(method);
372366
}
@@ -394,10 +388,8 @@ MemberCategory[] getDeclaredMemberCategories() {
394388
Predicate<RuntimeHints> exactMatch() {
395389
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
396390
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).methods().anyMatch(executableHint -> {
397-
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
398-
.map(TypeReference::of).toList();
399-
return includes(executableHint, this.executable.getName(),
400-
parameters, this.executableMode);
391+
List<TypeReference> parameters = TypeReference.listOf(this.executable.getParameterTypes());
392+
return includes(executableHint, this.executable.getName(), parameters, this.executableMode);
401393
});
402394
}
403395

@@ -422,8 +414,8 @@ public boolean test(RuntimeHints runtimeHints) {
422414

423415
private boolean memberCategoryMatch(TypeHint typeHint) {
424416
if (Modifier.isPublic(this.field.getModifiers())) {
425-
return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS)
426-
|| typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
417+
return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS) ||
418+
typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
427419
}
428420
else {
429421
return typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
@@ -434,6 +426,7 @@ private boolean exactMatch(TypeHint typeHint) {
434426
return typeHint.fields().anyMatch(fieldHint ->
435427
this.field.getName().equals(fieldHint.getName()));
436428
}
429+
437430
}
438431

439432
}

spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,13 @@ private static Consumer<JdkProxyHint> proxiedInterfaces(String... proxiedInterfa
9696

9797
private static Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
9898
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
99-
.containsExactly(toTypeReferences(proxiedInterfaces));
99+
.containsExactlyElementsOf(TypeReference.listOf(proxiedInterfaces));
100100
}
101101

102102
private static TypeReference[] toTypeReferences(String... proxiedInterfaces) {
103103
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new);
104104
}
105105

106-
private static TypeReference[] toTypeReferences(Class<?>... proxiedInterfaces) {
107-
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new);
108-
}
109-
110106

111107
sealed interface SealedInterface {
112108
}

0 commit comments

Comments
 (0)