Skip to content

Commit

Permalink
Correctly map generic return and parameter types in `JavaReflectionTy…
Browse files Browse the repository at this point in the history
…peMapping` (#4812)
  • Loading branch information
jkschneider authored Dec 24, 2024
1 parent da57352 commit ef0f845
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ default void generic() {
assertThat(generic.getName()).isEqualTo("?");
assertThat(generic.getVariance()).isEqualTo(COVARIANT);
assertThat(TypeUtils.asFullyQualified(generic.getBounds().get(0)).getFullyQualifiedName()).isEqualTo("org.openrewrite.java.C");

generic = (JavaType.GenericTypeVariable) TypeUtils.asParameterized(methodType("generic").getReturnType()).getTypeParameters().get(0);
assertThat(generic.getName()).isEqualTo("?");
assertThat(generic.getVariance()).isEqualTo(COVARIANT);
assertThat(TypeUtils.asFullyQualified(generic.getBounds().get(0)).getFullyQualifiedName()).isEqualTo("org.openrewrite.java.C");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,13 @@ private JavaType.Method method(Method method, JavaType.FullyQualified declaringT
List<JavaType> parameterTypes = emptyList();
if (method.getParameters().length > 0) {
parameterTypes = new ArrayList<>(method.getParameters().length);
for (Parameter parameter : method.getParameters()) {
Type parameterizedType = parameter.getParameterizedType();
parameterTypes.add(type(parameterizedType == null ? parameter.getType() : parameterizedType));
for (Type parameter : method.getGenericParameterTypes()) {
parameterTypes.add(type(parameter));
}
}

mappedMethod.unsafeSet(declaringType, type(method.getReturnType()), parameterTypes, thrownExceptions, annotations);
JavaType returnType = type(method.getGenericReturnType());
mappedMethod.unsafeSet(declaringType, returnType, parameterTypes, thrownExceptions, annotations);
return mappedMethod;
}
}

0 comments on commit ef0f845

Please sign in to comment.