migrated according to the last when changes
This commit is contained in:
@@ -40,8 +40,8 @@ import static org.jetbrains.k2js.translate.utils.DescriptorUtils.getNameForNames
|
||||
public final class K2JSTranslator {
|
||||
|
||||
private static final List<String> LIB_FILE_NAMES = Arrays.asList(
|
||||
"C:\\Dev\\Projects\\Kotlin\\jet\\stdlib\\ktSrc\\jssupport\\JsCollectionSupport.jet",
|
||||
"C:\\Dev\\Projects\\Kotlin\\jet\\stdlib\\ktSrc\\jssupport\\JsSupport.jet"
|
||||
"C:\\Dev\\Projects\\Kotlin\\jet\\stdlib\\ktSrc\\jssupport\\JsSupport.jet",
|
||||
"C:\\Dev\\Projects\\Kotlin\\jet\\stdlib\\ktSrc\\jssupport\\JsDeclarations.kt"
|
||||
);
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -244,6 +244,10 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
@NotNull
|
||||
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
//TODO: problem with extension properties lies here
|
||||
// if (PropertyAccessTranslator.canBePropertyGetterCall(expression, context)) {
|
||||
// return PropertyAccessTranslator.translateAsPropertyGetterCall()
|
||||
// }
|
||||
if (expression.getSelectorExpression() instanceof JetCallExpression) {
|
||||
return CallTranslator.translate(expression, context);
|
||||
}
|
||||
|
||||
@@ -162,11 +162,10 @@ public class WhenTranslator extends AbstractTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateCondition(@NotNull JetWhenCondition condition) {
|
||||
if (condition instanceof JetWhenConditionIsPattern) {
|
||||
return translatePatternCondition((JetWhenConditionIsPattern) condition);
|
||||
if ((condition instanceof JetWhenConditionIsPattern) || (condition instanceof JetWhenConditionWithExpression)) {
|
||||
return translatePatternCondition(condition);
|
||||
}
|
||||
throw new AssertionError("Unsupported when condition " + condition.getClass());
|
||||
}
|
||||
@@ -177,19 +176,33 @@ public class WhenTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsExpression translatePatternCondition(@NotNull JetWhenConditionIsPattern condition) {
|
||||
private JsExpression translatePatternCondition(@NotNull JetWhenCondition condition) {
|
||||
JsExpression patternMatchExpression = Translation.patternTranslator(context()).
|
||||
translatePattern(getPattern(condition), expressionToMatch);
|
||||
if (condition.isNegated()) {
|
||||
if (isNegated(condition)) {
|
||||
return AstUtil.negated(patternMatchExpression);
|
||||
}
|
||||
return patternMatchExpression;
|
||||
}
|
||||
|
||||
private boolean isNegated(@NotNull JetWhenCondition condition) {
|
||||
if (condition instanceof JetWhenConditionIsPattern) {
|
||||
return ((JetWhenConditionIsPattern) condition).isNegated();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetPattern getPattern(@NotNull JetWhenConditionIsPattern condition) {
|
||||
JetPattern pattern = condition.getPattern();
|
||||
assert pattern != null : "Is condition should have a non null pattern.";
|
||||
private JetPattern getPattern(@NotNull JetWhenCondition condition) {
|
||||
JetPattern pattern;
|
||||
if (condition instanceof JetWhenConditionIsPattern) {
|
||||
pattern = ((JetWhenConditionIsPattern) condition).getPattern();
|
||||
} else if (condition instanceof JetWhenConditionWithExpression) {
|
||||
pattern = ((JetWhenConditionWithExpression) condition).getPattern();
|
||||
} else {
|
||||
throw new AssertionError("Wrong type of JetWhenCondition");
|
||||
}
|
||||
assert pattern != null : "Condition should have a non null pattern.";
|
||||
return pattern;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ public final class PropertyAccessTranslator extends AccessTranslator {
|
||||
return new PropertyAccessTranslator(propertyDescriptor, null, isBackingFieldReference(expression), context);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static PropertyAccessTranslator newInstance(@NotNull JetExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
@@ -5,6 +5,7 @@ fun box() : Boolean {
|
||||
when(a) {
|
||||
!is 3 -> {a = 10;}
|
||||
!is 4 -> {a = 20;}
|
||||
else -> {a = 30;}
|
||||
}
|
||||
return (a == 10)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ fun box() : Boolean {
|
||||
when(a) {
|
||||
is 3 -> {a = 10;}
|
||||
is 4 -> {a = 20;}
|
||||
else -> {a = 30;}
|
||||
}
|
||||
return (a == 20)
|
||||
}
|
||||
@@ -33,7 +33,7 @@ fun main(args : Array<String>) {
|
||||
printBottles(99)
|
||||
}
|
||||
else {
|
||||
val bottles = Integer.parseInt(args[0]);
|
||||
val bottles = parseInt(args[0]);
|
||||
if (bottles != null) {
|
||||
printBottles(bottles);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user