Search in sources :

Example 1 with InOperationTranslator

use of org.jetbrains.kotlin.js.translate.operation.InOperationTranslator in project kotlin by JetBrains.

the class WhenTranslator method translateRangeCondition.

@NotNull
private JsExpression translateRangeCondition(@NotNull KtWhenConditionInRange condition, @NotNull TranslationContext context) {
    KtExpression patternExpression = condition.getRangeExpression();
    assert patternExpression != null : "Expression pattern should have an expression: " + PsiUtilsKt.getTextWithLocation(condition);
    JsExpression expressionToMatch = getExpressionToMatch();
    assert expressionToMatch != null : "Range pattern is only available for 'when (C) { in ... }'  expressions: " + PsiUtilsKt.getTextWithLocation(condition);
    Map<KtExpression, JsExpression> subjectAliases = new HashMap<KtExpression, JsExpression>();
    subjectAliases.put(whenExpression.getSubjectExpression(), expressionToMatch);
    TranslationContext callContext = context.innerContextWithAliasesForExpressions(subjectAliases);
    boolean negated = condition.getOperationReference().getReferencedNameElementType() == KtTokens.NOT_IN;
    return new InOperationTranslator(callContext, expressionToMatch, condition.getRangeExpression(), condition.getOperationReference(), negated).translate();
}
Also used : HashMap(java.util.HashMap) TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) InOperationTranslator(org.jetbrains.kotlin.js.translate.operation.InOperationTranslator) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1 TranslationContext (org.jetbrains.kotlin.js.translate.context.TranslationContext)1 InOperationTranslator (org.jetbrains.kotlin.js.translate.operation.InOperationTranslator)1