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 {
|
public final class K2JSTranslator {
|
||||||
|
|
||||||
private static final List<String> LIB_FILE_NAMES = Arrays.asList(
|
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
|
@NotNull
|
||||||
|
|||||||
@@ -244,6 +244,10 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
public JsNode visitDotQualifiedExpression(@NotNull JetDotQualifiedExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
|
//TODO: problem with extension properties lies here
|
||||||
|
// if (PropertyAccessTranslator.canBePropertyGetterCall(expression, context)) {
|
||||||
|
// return PropertyAccessTranslator.translateAsPropertyGetterCall()
|
||||||
|
// }
|
||||||
if (expression.getSelectorExpression() instanceof JetCallExpression) {
|
if (expression.getSelectorExpression() instanceof JetCallExpression) {
|
||||||
return CallTranslator.translate(expression, context);
|
return CallTranslator.translate(expression, context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,11 +162,10 @@ public class WhenTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression translateCondition(@NotNull JetWhenCondition condition) {
|
private JsExpression translateCondition(@NotNull JetWhenCondition condition) {
|
||||||
if (condition instanceof JetWhenConditionIsPattern) {
|
if ((condition instanceof JetWhenConditionIsPattern) || (condition instanceof JetWhenConditionWithExpression)) {
|
||||||
return translatePatternCondition((JetWhenConditionIsPattern) condition);
|
return translatePatternCondition(condition);
|
||||||
}
|
}
|
||||||
throw new AssertionError("Unsupported when condition " + condition.getClass());
|
throw new AssertionError("Unsupported when condition " + condition.getClass());
|
||||||
}
|
}
|
||||||
@@ -177,19 +176,33 @@ public class WhenTranslator extends AbstractTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression translatePatternCondition(@NotNull JetWhenConditionIsPattern condition) {
|
private JsExpression translatePatternCondition(@NotNull JetWhenCondition condition) {
|
||||||
JsExpression patternMatchExpression = Translation.patternTranslator(context()).
|
JsExpression patternMatchExpression = Translation.patternTranslator(context()).
|
||||||
translatePattern(getPattern(condition), expressionToMatch);
|
translatePattern(getPattern(condition), expressionToMatch);
|
||||||
if (condition.isNegated()) {
|
if (isNegated(condition)) {
|
||||||
return AstUtil.negated(patternMatchExpression);
|
return AstUtil.negated(patternMatchExpression);
|
||||||
}
|
}
|
||||||
return patternMatchExpression;
|
return patternMatchExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNegated(@NotNull JetWhenCondition condition) {
|
||||||
|
if (condition instanceof JetWhenConditionIsPattern) {
|
||||||
|
return ((JetWhenConditionIsPattern) condition).isNegated();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetPattern getPattern(@NotNull JetWhenConditionIsPattern condition) {
|
private JetPattern getPattern(@NotNull JetWhenCondition condition) {
|
||||||
JetPattern pattern = condition.getPattern();
|
JetPattern pattern;
|
||||||
assert pattern != null : "Is condition should have a non null 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;
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ public final class PropertyAccessTranslator extends AccessTranslator {
|
|||||||
return new PropertyAccessTranslator(propertyDescriptor, null, isBackingFieldReference(expression), context);
|
return new PropertyAccessTranslator(propertyDescriptor, null, isBackingFieldReference(expression), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static PropertyAccessTranslator newInstance(@NotNull JetExpression expression,
|
public static PropertyAccessTranslator newInstance(@NotNull JetExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ fun box() : Boolean {
|
|||||||
when(a) {
|
when(a) {
|
||||||
!is 3 -> {a = 10;}
|
!is 3 -> {a = 10;}
|
||||||
!is 4 -> {a = 20;}
|
!is 4 -> {a = 20;}
|
||||||
|
else -> {a = 30;}
|
||||||
}
|
}
|
||||||
return (a == 10)
|
return (a == 10)
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ fun box() : Boolean {
|
|||||||
when(a) {
|
when(a) {
|
||||||
is 3 -> {a = 10;}
|
is 3 -> {a = 10;}
|
||||||
is 4 -> {a = 20;}
|
is 4 -> {a = 20;}
|
||||||
|
else -> {a = 30;}
|
||||||
}
|
}
|
||||||
return (a == 20)
|
return (a == 20)
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ fun main(args : Array<String>) {
|
|||||||
printBottles(99)
|
printBottles(99)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val bottles = Integer.parseInt(args[0]);
|
val bottles = parseInt(args[0]);
|
||||||
if (bottles != null) {
|
if (bottles != null) {
|
||||||
printBottles(bottles);
|
printBottles(bottles);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user