Added BindingUtils.isStatement. Still issue not solved.
This commit is contained in:
@@ -101,6 +101,10 @@ public final class BindingUtils {
|
||||
return superClassDescriptors;
|
||||
}
|
||||
|
||||
static public boolean isStatement(@NotNull BindingContext context, @NotNull JetExpression expression) {
|
||||
return context.get(BindingContext.STATEMENT, expression);
|
||||
}
|
||||
|
||||
//TODO better implementation?
|
||||
private static boolean isNotAny(@NotNull DeclarationDescriptor superClassDescriptor) {
|
||||
return !superClassDescriptor.getName().equals("Any");
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.k2js.translate;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
@@ -183,7 +182,8 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@Override
|
||||
@NotNull
|
||||
public JsNode visitIfExpression(@NotNull JetIfExpression expression, @NotNull TranslationContext context) {
|
||||
if (isStatement(expression)) {
|
||||
boolean isStatement = BindingUtils.isStatement(context.bindingContext(), expression);
|
||||
if (isStatement) {
|
||||
return translateAsIfStatement(expression, context);
|
||||
} else {
|
||||
return translateAsConditionalExpression(expression, context);
|
||||
@@ -220,12 +220,6 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO: ask about a legal way to do it
|
||||
private boolean isStatement(@NotNull JetIfExpression expression) {
|
||||
PsiElement parent = expression.getParent();
|
||||
return (parent instanceof JetBlockExpression) || (parent instanceof JetIfExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsStatement translateNullableExpressionAsNotNullStatement(@Nullable JetExpression nullableExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
@@ -41,11 +41,10 @@ public final class ExpressionTest extends TranslationTest {
|
||||
performTest("if.kt", "foo", "box", 5);
|
||||
}
|
||||
|
||||
//TODO: test fails because of problem with isStatement()
|
||||
// @Test
|
||||
// public void ifElseIf() throws Exception {
|
||||
// performTest("elseif.kt", "foo", "box", 5);
|
||||
// }
|
||||
@Test
|
||||
public void ifElseIf() throws Exception {
|
||||
performTest("elseif.kt", "foo", "box", 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whileSimpleTest() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user