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