Skip to content

Commit

Permalink
Merge pull request #34086 from rPraml
Browse files Browse the repository at this point in the history
* pr/34086:
  Polish "Resolve base type in parameterized type if necessary"
  Resolve base type in parameterized type if necessary

Closes gh-34086
  • Loading branch information
snicoll committed Jan 15, 2025
2 parents 2273850 + fe5f5d5 commit e7f3493
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -180,7 +180,7 @@ else if (genericType instanceof ParameterizedType parameterizedType) {
generics[i] = resolvedTypeArgument;
}
else {
generics[i] = ResolvableType.forType(typeArgument);
generics[i] = ResolvableType.forType(typeArgument).resolveType();
}
}
else if (typeArgument instanceof ParameterizedType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -211,6 +211,14 @@ void resolveNestedTypeVariable() throws Exception {
assertThat(ResolvableType.forType(resolved).getGeneric(0).getGeneric(0).resolve()).isEqualTo(String.class);
}

@Test
void resolvedTypeWithBase() {
Type type = method(WithBaseTypes.class, "get").getGenericReturnType();
Type resolvedType = resolveType(type, WithBaseTypes.class);
ParameterizedTypeReference<List<A>> reference = new ParameterizedTypeReference<>() {};
assertThat(resolvedType).isEqualTo(reference.getType());
}

private static Method method(Class<?> target, String methodName, Class<?>... parameterTypes) {
Method method = findMethod(target, methodName, parameterTypes);
assertThat(method).describedAs(target.getName() + "#" + methodName).isNotNull();
Expand Down Expand Up @@ -398,4 +406,12 @@ public interface ListOfListSupplier<T> {
public interface StringListOfListSupplier extends ListOfListSupplier<String> {
}

static class WithBaseTypes {

<T extends A> List<T> get() {
return List.of();
}

}

}

0 comments on commit e7f3493

Please sign in to comment.