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:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user