Skip to content

Commit a569fd3

Browse files
committed
[GR-38638] Add GraalTest method lookup with return type
PullRequest: graal/11953
2 parents ffe4764 + 5c1a452 commit a569fd3

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/GraalCompilerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,10 @@ protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, String method
13391339
return asResolvedJavaMethod(getMethod(clazz, methodName, parameterTypes));
13401340
}
13411341

1342+
protected ResolvedJavaMethod getResolvedJavaMethod(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
1343+
return asResolvedJavaMethod(getMethod(clazz, returnType, methodName, parameterTypes));
1344+
}
1345+
13421346
/**
13431347
* Gets the reflection {@link Method} from which a given {@link ResolvedJavaMethod} was created
13441348
* or null if {@code javaMethod} does not correspond to a reflection method.

compiler/src/org.graalvm.compiler.test/src/org/graalvm/compiler/test/GraalTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,30 @@ protected Method getMethod(Class<?> clazz, String methodName, Class<?>... parame
123123
}
124124
}
125125

126+
protected Method getMethod(Class<?> clazz, Class<?> returnType, String methodName, Class<?>... parameterTypes) {
127+
Method found = null;
128+
for (Method m : clazz.getMethods()) {
129+
if (m.getName().equals(methodName) && m.getReturnType().equals(returnType) && Arrays.equals(m.getParameterTypes(), parameterTypes)) {
130+
Assert.assertNull(found);
131+
found = m;
132+
}
133+
}
134+
if (found == null) {
135+
/* Now look for non-public methods (but this does not look in superclasses). */
136+
for (Method m : clazz.getDeclaredMethods()) {
137+
if (m.getName().equals(methodName) && m.getReturnType().equals(returnType) && Arrays.equals(m.getParameterTypes(), parameterTypes)) {
138+
Assert.assertNull(found);
139+
found = m;
140+
}
141+
}
142+
}
143+
if (found != null) {
144+
return found;
145+
} else {
146+
throw new RuntimeException("method not found: " + methodName + " returning " + returnType + " " + Arrays.toString(parameterTypes));
147+
}
148+
}
149+
126150
/**
127151
* Compares two given objects for {@linkplain Assert#assertEquals(Object, Object) equality}.
128152
* Does a deep copy equality comparison if {@code expected} is an array.

0 commit comments

Comments
 (0)