Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly map generic return and parameter types in JavaReflectionTypeMapping #4812

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading