Merge pull request #28664 from mhalbritter
* pr/28664: Polish "Fix enclosing class in TypeReference for inner type arrays" Fix enclosing class in TypeReference for inner type arrays Closes gh-28664
This commit is contained in:
@@ -28,13 +28,16 @@ final class ReflectionTypeReference extends AbstractTypeReference {
|
||||
private final Class<?> type;
|
||||
|
||||
private ReflectionTypeReference(Class<?> type) {
|
||||
super(type.getPackageName(), type.getSimpleName(), safeCreate(type.getEnclosingClass()));
|
||||
super(type.getPackageName(), type.getSimpleName(), getEnclosingClass(type));
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ReflectionTypeReference safeCreate(@Nullable Class<?> type) {
|
||||
return (type != null ? new ReflectionTypeReference(type) : null);
|
||||
private static TypeReference getEnclosingClass(Class<?> type) {
|
||||
Class<?> candidate = (type.isArray()
|
||||
? type.getComponentType().getEnclosingClass()
|
||||
: type.getEnclosingClass());
|
||||
return (candidate != null ? new ReflectionTypeReference(candidate) : null);
|
||||
}
|
||||
|
||||
static ReflectionTypeReference of(Class<?> type) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Tests for {@link ReflectionTypeReference}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
class ReflectionTypeReferenceTests {
|
||||
|
||||
@@ -38,10 +39,26 @@ class ReflectionTypeReferenceTests {
|
||||
}
|
||||
|
||||
static Stream<Arguments> reflectionTargetNames() {
|
||||
return Stream.of(Arguments.of(ReflectionTypeReference.of(int.class), "int"),
|
||||
return Stream.of(
|
||||
Arguments.of(ReflectionTypeReference.of(int.class), "int"),
|
||||
Arguments.of(ReflectionTypeReference.of(int[].class), "int[]"),
|
||||
Arguments.of(ReflectionTypeReference.of(Integer[].class), "java.lang.Integer[]"),
|
||||
Arguments.of(ReflectionTypeReference.of(Object[].class), "java.lang.Object[]"));
|
||||
Arguments.of(ReflectionTypeReference.of(Object[].class), "java.lang.Object[]"),
|
||||
Arguments.of(ReflectionTypeReference.of(StaticInner.class),
|
||||
"org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner"),
|
||||
Arguments.of(ReflectionTypeReference.of(StaticInner[].class),
|
||||
"org.springframework.aot.hint.ReflectionTypeReferenceTests$StaticInner[]"),
|
||||
Arguments.of(ReflectionTypeReference.of(Inner.class),
|
||||
"org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner"),
|
||||
Arguments.of(ReflectionTypeReference.of(Inner[].class),
|
||||
"org.springframework.aot.hint.ReflectionTypeReferenceTests$Inner[]")
|
||||
);
|
||||
}
|
||||
|
||||
static class StaticInner {
|
||||
}
|
||||
|
||||
class Inner {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user