Browse Source

Polishing

pull/29155/head
Sam Brannen 4 years ago
parent
commit
a2445dcb8a
  1. 2
      spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java
  2. 4
      spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java
  3. 3
      spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java
  4. 5
      spring-core/src/main/java/org/springframework/aot/hint/predicate/ProxyHintsPredicates.java
  5. 35
      spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java
  6. 6
      spring-core/src/test/java/org/springframework/aot/hint/ProxyHintsTests.java

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

@ -158,7 +158,7 @@ public final class JdkProxyHint implements ConditionalHint { @@ -158,7 +158,7 @@ public final class JdkProxyHint implements ConditionalHint {
if (!invalidTypes.isEmpty()) {
throw new IllegalArgumentException("The following must be non-sealed interfaces: " + invalidTypes);
}
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toList();
return TypeReference.listOf(proxiedInterfaces);
}
}

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

@ -20,12 +20,10 @@ import java.lang.reflect.Constructor; @@ -20,12 +20,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.aot.hint.TypeHint.Builder;
@ -255,7 +253,7 @@ public class ReflectionHints { @@ -255,7 +253,7 @@ public class ReflectionHints {
}
private List<TypeReference> mapParameters(Executable executable) {
return Arrays.stream(executable.getParameterTypes()).map(TypeReference::of).collect(Collectors.toList());
return TypeReference.listOf(executable.getParameterTypes());
}
}

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

@ -312,8 +312,7 @@ public final class TypeHint implements ConditionalHint { @@ -312,8 +312,7 @@ public final class TypeHint implements ConditionalHint {
private ExecutableKey(String name, List<TypeReference> parameterTypes) {
this.name = name;
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName)
.collect(Collectors.toList());
this.parameterTypes = parameterTypes.stream().map(TypeReference::getCanonicalName).toList();
}
@Override

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.aot.hint.predicate;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import org.springframework.aot.hint.ProxyHints;
@ -59,7 +60,9 @@ public class ProxyHintsPredicates { @@ -59,7 +60,9 @@ public class ProxyHintsPredicates {
*/
public Predicate<RuntimeHints> forInterfaces(TypeReference... interfaces) {
Assert.notEmpty(interfaces, "'interfaces' should not be empty");
List<TypeReference> interfaceList = Arrays.asList(interfaces);
return hints -> hints.proxies().jdkProxies().anyMatch(proxyHint ->
proxyHint.getProxiedInterfaces().equals(Arrays.asList(interfaces)));
proxyHint.getProxiedInterfaces().equals(interfaceList));
}
}

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

@ -49,7 +49,6 @@ import org.springframework.util.ReflectionUtils; @@ -49,7 +49,6 @@ import org.springframework.util.ReflectionUtils;
public class ReflectionHintsPredicates {
ReflectionHintsPredicates() {
}
/**
@ -138,10 +137,10 @@ public class ReflectionHintsPredicates { @@ -138,10 +137,10 @@ public class ReflectionHintsPredicates {
return methods.iterator().next();
}
else if (methods.size() > 1) {
throw new IllegalArgumentException(String.format("Found multiple methods named '%s' on class %s", methodName, type.getName()));
throw new IllegalArgumentException("Found multiple methods named '%s' on class %s".formatted(methodName, type.getName()));
}
else {
throw new IllegalArgumentException("No method named '" + methodName + "' on class " + type.getName());
throw new IllegalArgumentException("No method named '%s' on class %s".formatted(methodName, type.getName()));
}
}
@ -160,7 +159,7 @@ public class ReflectionHintsPredicates { @@ -160,7 +159,7 @@ public class ReflectionHintsPredicates {
Assert.hasText(fieldName, "'fieldName' should not be empty");
Field field = ReflectionUtils.findField(type, fieldName);
if (field == null) {
throw new IllegalArgumentException("No field named '" + fieldName + "' on class " + type.getName());
throw new IllegalArgumentException("No field named '%s' on class %s".formatted(fieldName, type.getName()));
}
return new FieldHintPredicate(field);
}
@ -315,15 +314,13 @@ public class ReflectionHintsPredicates { @@ -315,15 +314,13 @@ public class ReflectionHintsPredicates {
/**
* Indicate whether the specified {@code ExecutableHint} covers the
* reflection needs of the specified executable definition.
* @return {@code true} if the member matches (same type, name and parameters),
* and the configured {@code ExecutableMode} is compatibe
* @return {@code true} if the member matches (same type, name, and parameters),
* and the configured {@code ExecutableMode} is compatible
*/
static boolean includes(ExecutableHint hint, String name,
List<TypeReference> parameterTypes, ExecutableMode executableModes) {
return hint.getName().equals(name)
&& hint.getParameterTypes().equals(parameterTypes)
&& (hint.getMode().equals(ExecutableMode.INVOKE)
|| !executableModes.equals(ExecutableMode.INVOKE));
return hint.getName().equals(name) && hint.getParameterTypes().equals(parameterTypes) &&
(hint.getMode().equals(ExecutableMode.INVOKE) || !executableModes.equals(ExecutableMode.INVOKE));
}
}
@ -355,10 +352,8 @@ public class ReflectionHintsPredicates { @@ -355,10 +352,8 @@ public class ReflectionHintsPredicates {
Predicate<RuntimeHints> exactMatch() {
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).constructors().anyMatch(executableHint -> {
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
.map(TypeReference::of).toList();
return includes(executableHint, "<init>",
parameters, this.executableMode);
List<TypeReference> parameters = TypeReference.listOf(this.executable.getParameterTypes());
return includes(executableHint, "<init>", parameters, this.executableMode);
});
}
@ -366,7 +361,6 @@ public class ReflectionHintsPredicates { @@ -366,7 +361,6 @@ public class ReflectionHintsPredicates {
public static class MethodHintPredicate extends ExecutableHintPredicate<Method> {
MethodHintPredicate(Method method) {
super(method);
}
@ -394,10 +388,8 @@ public class ReflectionHintsPredicates { @@ -394,10 +388,8 @@ public class ReflectionHintsPredicates {
Predicate<RuntimeHints> exactMatch() {
return hints -> (hints.reflection().getTypeHint(this.executable.getDeclaringClass()) != null) &&
hints.reflection().getTypeHint(this.executable.getDeclaringClass()).methods().anyMatch(executableHint -> {
List<TypeReference> parameters = Arrays.stream(this.executable.getParameterTypes())
.map(TypeReference::of).toList();
return includes(executableHint, this.executable.getName(),
parameters, this.executableMode);
List<TypeReference> parameters = TypeReference.listOf(this.executable.getParameterTypes());
return includes(executableHint, this.executable.getName(), parameters, this.executableMode);
});
}
@ -422,8 +414,8 @@ public class ReflectionHintsPredicates { @@ -422,8 +414,8 @@ public class ReflectionHintsPredicates {
private boolean memberCategoryMatch(TypeHint typeHint) {
if (Modifier.isPublic(this.field.getModifiers())) {
return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS)
|| typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS) ||
typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
}
else {
return typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
@ -434,6 +426,7 @@ public class ReflectionHintsPredicates { @@ -434,6 +426,7 @@ public class ReflectionHintsPredicates {
return typeHint.fields().anyMatch(fieldHint ->
this.field.getName().equals(fieldHint.getName()));
}
}
}

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

@ -96,17 +96,13 @@ class ProxyHintsTests { @@ -96,17 +96,13 @@ class ProxyHintsTests {
private static Consumer<JdkProxyHint> proxiedInterfaces(Class<?>... proxiedInterfaces) {
return jdkProxyHint -> assertThat(jdkProxyHint.getProxiedInterfaces())
.containsExactly(toTypeReferences(proxiedInterfaces));
.containsExactlyElementsOf(TypeReference.listOf(proxiedInterfaces));
}
private static TypeReference[] toTypeReferences(String... proxiedInterfaces) {
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new);
}
private static TypeReference[] toTypeReferences(Class<?>... proxiedInterfaces) {
return Arrays.stream(proxiedInterfaces).map(TypeReference::of).toArray(TypeReference[]::new);
}
sealed interface SealedInterface {
}

Loading…
Cancel
Save