diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/callTranslator/CallInfoExtensions.kt b/js/js.translator/src/org/jetbrains/k2js/translate/callTranslator/CallInfoExtensions.kt index 7948372f25e..507afd16edb 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/callTranslator/CallInfoExtensions.kt +++ b/js/js.translator/src/org/jetbrains/k2js/translate/callTranslator/CallInfoExtensions.kt @@ -26,7 +26,8 @@ import org.jetbrains.k2js.translate.context.Namer import com.google.dart.compiler.backend.js.ast.JsNameRef import org.jetbrains.k2js.translate.utils.JsAstUtils import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.* -import org.jetbrains.k2js.translate.reference.CallType +import com.google.dart.compiler.backend.js.ast.JsLiteral +import org.jetbrains.k2js.translate.utils.TranslationUtils val CallInfo.callableDescriptor: CallableDescriptor @@ -51,11 +52,9 @@ fun CallInfo.constructSafeCallIsNeeded(result: JsExpression): JsExpression { BOTH_RECEIVERS, RECEIVER_ARGUMENT -> receiverObject else -> thisObject } - return CallType.SAFE.constructCall(nullableReceiverForSafeCall, object : CallType.CallConstructor { - override fun construct(receiver: JsExpression?): JsExpression { - return result - } - }, context) + val expression = TranslationUtils.notNullConditional(nullableReceiverForSafeCall!!, JsLiteral.NULL, context) + expression.setThenExpression(result) + return expression } val VariableAccessInfo.variableDescriptor: VariableDescriptor diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java b/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java index dba8659c6c4..07c109d3254 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/expression/ExpressionVisitor.java @@ -27,10 +27,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; -import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.resolve.constants.NullValue; -import org.jetbrains.jet.lang.types.JetType; -import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.k2js.translate.context.TemporaryVariable; import org.jetbrains.k2js.translate.context.TranslationContext; @@ -181,7 +178,7 @@ public final class ExpressionVisitor extends TranslatorVisitor { @NotNull public JsNode visitCallExpression(@NotNull JetCallExpression expression, @NotNull TranslationContext context) { - return CallExpressionTranslator.translate(expression, null, CallType.NORMAL, context).source(expression); + return CallExpressionTranslator.translate(expression, null, context).source(expression); } @Override diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java index ea9b7a91a76..e1b68279573 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/AbstractCallExpressionTranslator.java @@ -35,17 +35,16 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato protected final ResolvedCall resolvedCall; @Nullable protected final JsExpression receiver; - @NotNull - protected final CallType callType; - protected AbstractCallExpressionTranslator(@NotNull JetCallExpression expression, + protected AbstractCallExpressionTranslator( + @NotNull JetCallExpression expression, @Nullable JsExpression receiver, - @NotNull CallType type, @NotNull TranslationContext context) { + @NotNull TranslationContext context + ) { super(context); this.expression = expression; this.resolvedCall = getResolvedCallForCallExpression(bindingContext(), expression); this.receiver = receiver; - this.callType = type; } } diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java index 703993e6a33..4b0e05f0606 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallExpressionTranslator.java @@ -26,20 +26,23 @@ import org.jetbrains.k2js.translate.context.TranslationContext; public final class CallExpressionTranslator extends AbstractCallExpressionTranslator { @NotNull - public static JsExpression translate(@NotNull JetCallExpression expression, + public static JsExpression translate( + @NotNull JetCallExpression expression, @Nullable JsExpression receiver, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @NotNull TranslationContext context + ) { if (InlinedCallExpressionTranslator.shouldBeInlined(expression, context)) { - return InlinedCallExpressionTranslator.translate(expression, receiver, callType, context); + return InlinedCallExpressionTranslator.translate(expression, receiver, context); } - return (new CallExpressionTranslator(expression, receiver, callType, context)).translate(); + return (new CallExpressionTranslator(expression, receiver, context)).translate(); } - private CallExpressionTranslator(@NotNull JetCallExpression expression, + private CallExpressionTranslator( + @NotNull JetCallExpression expression, @Nullable JsExpression receiver, - @NotNull CallType callType, @NotNull TranslationContext context) { - super(expression, receiver, callType, context); + @NotNull TranslationContext context + ) { + super(expression, receiver, context); } @NotNull diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallType.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallType.java deleted file mode 100644 index fdf5118e963..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallType.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.translate.reference; - -import com.google.dart.compiler.backend.js.ast.JsConditional; -import com.google.dart.compiler.backend.js.ast.JsExpression; -import com.google.dart.compiler.backend.js.ast.JsLiteral; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression; -import org.jetbrains.jet.lang.psi.JetQualifiedExpression; -import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression; -import org.jetbrains.k2js.translate.context.TranslationContext; - -import static org.jetbrains.k2js.translate.utils.TranslationUtils.notNullConditional; - -public enum CallType { - SAFE { - @NotNull - @Override - public JsExpression constructCall( - @Nullable JsExpression receiver, @NotNull CallConstructor constructor, - @NotNull TranslationContext context - ) { - assert receiver != null; - JsConditional expression = notNullConditional(receiver, JsLiteral.NULL, context); - expression.setThenExpression(constructor.construct(expression.getThenExpression())); - return expression; - } - }, - //TODO: bang qualifier is not implemented in frontend for now - // BANG, - NORMAL { - @NotNull - @Override - public JsExpression constructCall( - @Nullable JsExpression receiver, @NotNull CallConstructor constructor, - @NotNull TranslationContext context - ) { - return constructor.construct(receiver); - } - }; - - @NotNull - public abstract JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor, - @NotNull TranslationContext context); - - @NotNull - public static CallType getCallTypeForQualifiedExpression(@NotNull JetQualifiedExpression expression) { - if (expression instanceof JetSafeQualifiedExpression) { - return SAFE; - } - assert expression instanceof JetDotQualifiedExpression; - return NORMAL; - } - - public interface CallConstructor { - @NotNull - JsExpression construct(@Nullable JsExpression receiver); - } - -} diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java index df25c84fa12..f23d35d2d60 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/InlinedCallExpressionTranslator.java @@ -62,16 +62,19 @@ public final class InlinedCallExpressionTranslator extends AbstractCallExpressio } @NotNull - public static JsExpression translate(@NotNull JetCallExpression expression, - @Nullable JsExpression receiver, - @NotNull CallType callType, - @NotNull TranslationContext context) { - return (new InlinedCallExpressionTranslator(expression, receiver, callType, context)).translate(); + public static JsExpression translate( + @NotNull JetCallExpression expression, + @Nullable JsExpression receiver, + @NotNull TranslationContext context + ) { + return (new InlinedCallExpressionTranslator(expression, receiver, context)).translate(); } - private InlinedCallExpressionTranslator(@NotNull JetCallExpression expression, @Nullable JsExpression receiver, - @NotNull CallType callType, @NotNull TranslationContext context) { - super(expression, receiver, callType, context); + private InlinedCallExpressionTranslator( + @NotNull JetCallExpression expression, @Nullable JsExpression receiver, + @NotNull TranslationContext context + ) { + super(expression, receiver, context); } @NotNull diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java b/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java index 4358becf436..906d55d3417 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/QualifiedExpressionTranslator.java @@ -48,15 +48,13 @@ public final class QualifiedExpressionTranslator { @NotNull TranslationContext context) { JsExpression receiver = translateReceiver(expression, context); JetExpression selector = getSelector(expression); - CallType callType = CallType.getCallTypeForQualifiedExpression(expression); - return dispatchToCorrectTranslator(receiver, selector, callType, context); + return dispatchToCorrectTranslator(receiver, selector, context); } @NotNull private static JsExpression dispatchToCorrectTranslator( @Nullable JsExpression receiver, @NotNull JetExpression selector, - @NotNull CallType callType, @NotNull TranslationContext context ) { if (ReferenceTranslator.canBePropertyAccess(selector, context)) { @@ -64,7 +62,7 @@ public final class QualifiedExpressionTranslator { return VariableAccessTranslator.newInstance(context, (JetSimpleNameExpression)selector, receiver).translateAsGet(); } if (selector instanceof JetCallExpression) { - return invokeCallExpressionTranslator(receiver, selector, callType, context); + return invokeCallExpressionTranslator(receiver, selector, context); } //TODO: never get there if (selector instanceof JetSimpleNameExpression) { @@ -78,12 +76,13 @@ public final class QualifiedExpressionTranslator { } @NotNull - private static JsExpression invokeCallExpressionTranslator(@Nullable JsExpression receiver, + private static JsExpression invokeCallExpressionTranslator( + @Nullable JsExpression receiver, @NotNull JetExpression selector, - @NotNull CallType callType, - @NotNull TranslationContext context) { + @NotNull TranslationContext context + ) { try { - return CallExpressionTranslator.translate((JetCallExpression) selector, receiver, callType, context); + return CallExpressionTranslator.translate((JetCallExpression) selector, receiver, context); } catch (RuntimeException e) { throw ErrorReportingUtils.reportErrorWithLocation(selector, e); }