Skip to content

Commit fcf61bb

Browse files
committed
svm: add JVMCIReflectionUtil#getResolvedReturnType()
1 parent e03fe09 commit fcf61bb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/JVMCIReflectionUtil.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package com.oracle.svm.util;
2626

27+
import java.lang.reflect.Method;
2728
import java.util.Arrays;
2829
import java.util.Collections;
2930
import java.util.List;
@@ -158,7 +159,7 @@ private static ResolvedJavaMethod findMethod(ResolvedJavaType declaringClass, Re
158159
if (res == null) {
159160
res = m;
160161
} else {
161-
throw new GraalError("More than one method with signature %s in %s", res.format("%h(%p)"), declaringClass.toClassName());
162+
throw new GraalError("More than one method with signature %s in %s", res.format("%H.%n(%p)"), declaringClass.toClassName());
162163
}
163164
}
164165
return res;
@@ -236,4 +237,18 @@ public static String getPackageName(ResolvedJavaType type) {
236237
int dot = cn.lastIndexOf('.');
237238
return (dot != -1) ? cn.substring(0, dot).intern() : "";
238239
}
240+
241+
/**
242+
* Gets the return type for a {@link ResolvedJavaMethod}. This is the same as calling
243+
* {@link Method#getReturnType()} on the underlying method.
244+
*
245+
* @throws GraalError if the return type is not a {@link ResolvedJavaType}
246+
*/
247+
public static ResolvedJavaType getResolvedReturnType(ResolvedJavaMethod m) {
248+
JavaType returnType = m.getSignature().getReturnType(m.getDeclaringClass());
249+
if (returnType instanceof ResolvedJavaType resolvedJavaType) {
250+
return resolvedJavaType;
251+
}
252+
throw new GraalError("Method does not have a resolved return type: %s", m.format("%H.%n(%p)"));
253+
}
239254
}

0 commit comments

Comments
 (0)