Skip to content

Commit

Permalink
[GR-38638] Add GraalTest method lookup with return type
Browse files Browse the repository at this point in the history
PullRequest: graal/11953
  • Loading branch information
andrewcraik committed Jun 16, 2022
2 parents ffe4764 + 5c1a452 commit a569fd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,10 @@ protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String method
return asResolvedJavaMethod(getMethod(clazz, methodName, parameterTypes));
}

protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
return asResolvedJavaMethod(getMethod(clazz, returnType, methodName, parameterTypes));
}

/**
* Gets the reflection {@link Method} from which a given {@link ResolvedJavaMethod} was created
* or null if {@code javaMethod} does not correspond to a reflection method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,30 @@ protected Method getMethod(Class<?> clazz, String methodName, Class<?>... parame
}
}

protected Method getMethod(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
Method found = null;
for (Method m : clazz.getMethods()) {
if (m.getName().equals(methodName) && m.getReturnType().equals(returnType) && Arrays.equals(m.getParameterTypes(), parameterTypes)) {
Assert.assertNull(found);
found = m;
}
}
if (found == null) {
/* Now look for non-public methods (but this does not look in superclasses). */
for (Method m : clazz.getDeclaredMethods()) {
if (m.getName().equals(methodName) && m.getReturnType().equals(returnType) && Arrays.equals(m.getParameterTypes(), parameterTypes)) {
Assert.assertNull(found);
found = m;
}
}
}
if (found != null) {
return found;
} else {
throw new RuntimeException("method not found: " + methodName + " returning " + returnType + " " + Arrays.toString(parameterTypes));
}
}

/**
* Compares two given objects for {@linkplain Assert#assertEquals(Object, Object) equality}.
* Does a deep copy equality comparison if {@code expected} is an array.
Expand Down

0 comments on commit a569fd3

Please sign in to comment.