Skip to content

Commit c999c94

Browse files
committed
svm: add JVMCIReflectionUtil#getPackageName()
1 parent 3cdd6fd commit c999c94

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,20 @@ public static List<ResolvedJavaField> getAllFields(ResolvedJavaType declaringCla
210210
System.arraycopy(instanceFields, 0, allFields, staticFields.length, instanceFields.length);
211211
return Collections.unmodifiableList(Arrays.asList(allFields));
212212
}
213+
214+
/**
215+
* Gets the package name for a {@link ResolvedJavaType}. This is the same as calling
216+
* {@link Class#getPackageName()} on the underlying class.
217+
* <p>
218+
* Implementation derived from {@link Class#getPackageName()}.
219+
*/
220+
public static String getPackageName(ResolvedJavaType type) {
221+
ResolvedJavaType c = type.isArray() ? type.getElementalType() : type;
222+
if (c.isPrimitive()) {
223+
return "java.lang";
224+
}
225+
String cn = c.toClassName();
226+
int dot = cn.lastIndexOf('.');
227+
return (dot != -1) ? cn.substring(0, dot).intern() : "";
228+
}
213229
}

0 commit comments

Comments
 (0)