JS: move couple of helper functions from TranslationUtils to JsDescriptorUtils
This commit is contained in:
+2
-2
@@ -252,7 +252,7 @@ class ClassTranslator private constructor(
|
||||
val delegationClassDescriptor = (resolvedCall?.resultingDescriptor as? ClassConstructorDescriptor)?.constructedClass
|
||||
|
||||
if (resolvedCall != null && !KotlinBuiltIns.isAny(delegationClassDescriptor!!)) {
|
||||
if (TranslationUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
if (JsDescriptorUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
superCallGenerators += {
|
||||
val innerContext = context().innerBlock()
|
||||
ClassInitializerTranslator.emulateSuperCallToNativeError(
|
||||
@@ -468,7 +468,7 @@ class ClassTranslator private constructor(
|
||||
}
|
||||
|
||||
private fun mayBeAddThrowableProperties(context: TranslationContext) {
|
||||
if (!TranslationUtils.isImmediateSubtypeOfError(descriptor)) return
|
||||
if (!JsDescriptorUtils.isImmediateSubtypeOfError(descriptor)) return
|
||||
|
||||
val properties = listOf("message", "cause")
|
||||
.map { Name.identifier(it) }
|
||||
|
||||
+3
-4
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsDescriptorUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||
import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.AstUtilsKt;
|
||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -188,7 +187,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
return;
|
||||
}
|
||||
|
||||
if (TranslationUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
if (JsDescriptorUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
emulateSuperCallToNativeError(context, classDescriptor, superCall, JsLiteral.THIS);
|
||||
return;
|
||||
}
|
||||
@@ -385,9 +384,9 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
private void addThrowableCall() {
|
||||
if (!TranslationUtils.isExceptionClass(classDescriptor)) return;
|
||||
if (!JsDescriptorUtils.isExceptionClass(classDescriptor)) return;
|
||||
|
||||
if (TranslationUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
if (JsDescriptorUtils.isImmediateSubtypeOfError(classDescriptor)) {
|
||||
ClassDescriptor superClass = DescriptorUtilsKt.getSuperClassOrAny(classDescriptor);
|
||||
JsExpression invocation = new JsInvocation(
|
||||
pureFqn("captureStack", Namer.kotlinObject()),
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -188,4 +189,16 @@ public final class JsDescriptorUtils {
|
||||
String moduleName = moduleDescriptor.getName().asString();
|
||||
return moduleName.substring(1, moduleName.length() - 1);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isImmediateSubtypeOfError(@NotNull ClassDescriptor descriptor) {
|
||||
if (!isExceptionClass(descriptor)) return false;
|
||||
ClassDescriptor superClass = org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getSuperClassOrAny(descriptor);
|
||||
return TypeUtilsKt.isThrowable(superClass.getDefaultType()) || AnnotationsUtils.isNativeObject(superClass);
|
||||
}
|
||||
|
||||
public static boolean isExceptionClass(@NotNull ClassDescriptor descriptor) {
|
||||
ModuleDescriptor module = DescriptorUtils.getContainingModule(descriptor);
|
||||
return TypeUtilsKt.isSubtypeOf(descriptor.getDefaultType(), module.getBuiltIns().getThrowable().getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.utils;
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
@@ -24,6 +23,8 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableAccessorDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation;
|
||||
import org.jetbrains.kotlin.js.backend.ast.*;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryConstVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
@@ -41,7 +42,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.FindClassInModuleKt;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -399,16 +399,4 @@ public final class TranslationUtils {
|
||||
descriptor.getContainingDeclaration() instanceof ClassDescriptor &&
|
||||
ModalityKt.isOverridable(descriptor);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isImmediateSubtypeOfError(@NotNull ClassDescriptor descriptor) {
|
||||
if (!isExceptionClass(descriptor)) return false;
|
||||
ClassDescriptor superClass = DescriptorUtilsKt.getSuperClassOrAny(descriptor);
|
||||
return TypeUtilsKt.isThrowable(superClass.getDefaultType()) || AnnotationsUtils.isNativeObject(superClass);
|
||||
}
|
||||
|
||||
public static boolean isExceptionClass(@NotNull ClassDescriptor descriptor) {
|
||||
ModuleDescriptor module = DescriptorUtils.getContainingModule(descriptor);
|
||||
return TypeUtilsKt.isSubtypeOf(descriptor.getDefaultType(), module.getBuiltIns().getThrowable().getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user