From f728d1cb25885606a4e36d324fb7819d6755572e Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 21 Aug 2012 15:38:49 +0400 Subject: [PATCH] Make notNullCheck for safe calls more readable Cherry-picked from: https://github.com/develar/kotlin/commit/5f4d9dd0a1d720d36e3387574223b80388ecdca7 --- .../k2js/translate/reference/CallType.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 index 1dcaa3c4f36..58f9a02a089 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallType.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/reference/CallType.java @@ -1,3 +1,4 @@ +/* /* * Copyright 2010-2012 JetBrains s.r.o. * @@ -16,10 +17,9 @@ package org.jetbrains.k2js.translate.reference; -import com.google.dart.compiler.backend.js.ast.JsBinaryOperation; 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.JsNullLiteral; +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; @@ -27,9 +27,8 @@ import org.jetbrains.jet.lang.psi.JetQualifiedExpression; import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression; import org.jetbrains.k2js.translate.context.TemporaryVariable; import org.jetbrains.k2js.translate.context.TranslationContext; -import org.jetbrains.k2js.translate.utils.TranslationUtils; -import static com.google.dart.compiler.util.AstUtil.newSequence; +import static org.jetbrains.k2js.translate.utils.TranslationUtils.notNullConditionalTestExpression; /** * @author Pavel Talanov @@ -41,11 +40,8 @@ public enum CallType { JsExpression constructCall(@Nullable JsExpression receiver, @NotNull CallConstructor constructor, @NotNull TranslationContext context) { assert receiver != null; - TemporaryVariable temporaryVariable = context.declareTemporary(receiver); - JsBinaryOperation notNullCheck = TranslationUtils.notNullConditionalTestExpression(temporaryVariable); - JsExpression methodCall = constructor.construct(temporaryVariable.reference()); - JsConditional callMethodIfNotNullElseNull = new JsConditional(notNullCheck, methodCall, JsNullLiteral.NULL); - return newSequence(temporaryVariable.assignmentExpression(), callMethodIfNotNullElseNull); + TemporaryVariable cachedValue = context.declareTemporary(receiver); + return new JsConditional(notNullConditionalTestExpression(cachedValue), constructor.construct(cachedValue.reference()), JsLiteral.NULL); } }, //TODO: bang qualifier is not implemented in frontend for now @@ -77,4 +73,4 @@ public enum CallType { JsExpression construct(@Nullable JsExpression receiver); } -} \ No newline at end of file +}