From 77138ecdb77370e3fb3938734b740dfe32e43104 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 9 Nov 2015 18:03:09 +0300 Subject: [PATCH] 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 of each class file which references the newly added class --- .../src/kotlin/jvm/internal/Intrinsics.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java index f753a535a8b..0a2efcb5fa4 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/Intrinsics.java @@ -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 sanitizeStackTrace(T throwable) { return sanitizeStackTrace(throwable, Intrinsics.class.getName()); }