Search in sources :

Example 1 with KtUnaryExpression

use of org.jetbrains.kotlin.psi.KtUnaryExpression in project kotlin by JetBrains.

the class Translation method translateExpression.

@NotNull
public static JsNode translateExpression(@NotNull KtExpression expression, @NotNull TranslationContext context, @NotNull JsBlock block) {
    JsExpression aliasForExpression = context.aliasingContext().getAliasForExpression(expression);
    if (aliasForExpression != null) {
        return aliasForExpression;
    }
    CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
    if (compileTimeValue != null) {
        KotlinType type = context.bindingContext().getType(expression);
        if (type != null) {
            if (KotlinBuiltIns.isLong(type) || (KotlinBuiltIns.isInt(type) && expression instanceof KtUnaryExpression)) {
                JsExpression constantResult = translateConstant(compileTimeValue, expression, context);
                if (constantResult != null)
                    return constantResult;
            }
        }
    }
    TranslationContext innerContext = context.innerBlock();
    JsNode result = doTranslateExpression(expression, innerContext);
    context.moveVarsFrom(innerContext);
    block.getStatements().addAll(innerContext.dynamicContext().jsBlock().getStatements());
    return result;
}
Also used : KtUnaryExpression(org.jetbrains.kotlin.psi.KtUnaryExpression) KotlinType(org.jetbrains.kotlin.types.KotlinType) TranslationContext(org.jetbrains.kotlin.js.translate.context.TranslationContext) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)1 TranslationContext (org.jetbrains.kotlin.js.translate.context.TranslationContext)1 KtUnaryExpression (org.jetbrains.kotlin.psi.KtUnaryExpression)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1