Add intrinsic functions to check availability of classes at runtime

Will be used whenever we add a new class to the runtime and use it in the
generated code: we'll now generate a call to one of these functions in <clinit>
of each class file which references the newly added class
This commit is contained in:
Alexander Udalov
2015-11-09 18:03:09 +03:00
parent 596a74d288
commit 77138ecdb7
@@ -213,6 +213,30 @@ public class Intrinsics {
throwUndefinedForReified(message);
}
public static void checkHasClass(String internalName) throws ClassNotFoundException {
String fqName = internalName.replace('/', '.');
try {
Class.forName(fqName);
}
catch (ClassNotFoundException e) {
throw sanitizeStackTrace(new ClassNotFoundException(
"Class " + fqName + " is not found. Please update the Kotlin runtime to the latest version", e
));
}
}
public static void checkHasClass(String internalName, String requiredVersion) throws ClassNotFoundException {
String fqName = internalName.replace('/', '.');
try {
Class.forName(fqName);
}
catch (ClassNotFoundException e) {
throw sanitizeStackTrace(new ClassNotFoundException(
"Class " + fqName + " is not found: this code requires the Kotlin runtime of version at least " + requiredVersion, e
));
}
}
private static <T extends Throwable> T sanitizeStackTrace(T throwable) {
return sanitizeStackTrace(throwable, Intrinsics.class.getName());
}