First stab at !! operator
This commit is contained in:
committed by
Pavel V. Talanov
parent
296a5b6b6c
commit
0fc64bb6c2
@@ -141,4 +141,11 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
public void testPropertiesWithExplicitlyDefinedAccessorsWithoutBodies() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
|
||||
public void testExclExcl() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.jetbrains.k2js.translate.expression.foreach.ForTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.general.TranslatorVisitor;
|
||||
import org.jetbrains.k2js.translate.operation.BinaryOperationTranslator;
|
||||
import org.jetbrains.k2js.translate.operation.IncrementTranslator;
|
||||
import org.jetbrains.k2js.translate.operation.UnaryOperationTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.*;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
@@ -285,7 +284,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@NotNull
|
||||
public JsNode visitPostfixExpression(@NotNull JetPostfixExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return IncrementTranslator.translate(expression, context);
|
||||
return UnaryOperationTranslator.translate(expression, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+21
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.translate.operation;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.CallType;
|
||||
@@ -26,7 +29,11 @@ import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getBaseExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.notNullCheck;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -40,12 +47,26 @@ public final class UnaryOperationTranslator {
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
if (isExclExcl(expression)) {
|
||||
return translateExclExclOperator(expression, context);
|
||||
}
|
||||
if (IncrementTranslator.isIncrement(expression)) {
|
||||
return IncrementTranslator.translate(expression, context);
|
||||
}
|
||||
return translateAsCall(expression, context);
|
||||
}
|
||||
|
||||
private static boolean isExclExcl(@NotNull JetUnaryExpression expression) {
|
||||
return getOperationToken(expression).equals(JetTokens.EXCLEXCL);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
|
||||
JsExpression translatedExpression = translateAsExpression(getBaseExpression(expression), context);
|
||||
JsBinaryOperation notNullCheck = notNullCheck(context, translatedExpression);
|
||||
return new JsConditional(notNullCheck, translatedExpression, translatedExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsExpression translateAsCall(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
|
||||
fun box() : Boolean {
|
||||
val a : Int? = 0
|
||||
|
||||
return (a!! + 3) == 3
|
||||
}
|
||||
Reference in New Issue
Block a user