use of org.jetbrains.kotlin.psi.KtConstantExpression in project kotlin by JetBrains.
the class UnaryOperationTranslator method translate.
@NotNull
public static JsExpression translate(@NotNull KtUnaryExpression expression, @NotNull TranslationContext context) {
IElementType operationToken = expression.getOperationReference().getReferencedNameElementType();
if (operationToken == KtTokens.EXCLEXCL) {
KtExpression baseExpression = getBaseExpression(expression);
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
return sure(translatedExpression, context);
}
if (operationToken == KtTokens.MINUS) {
KtExpression baseExpression = getBaseExpression(expression);
if (baseExpression instanceof KtConstantExpression) {
CompileTimeConstant<?> compileTimeValue = ConstantExpressionEvaluator.getConstant(expression, context.bindingContext());
assert compileTimeValue != null : message(expression, "Expression is not compile time value: " + expression.getText() + " ");
Object value = getCompileTimeValue(context.bindingContext(), expression, compileTimeValue);
if (value instanceof Long) {
return JsAstUtils.newLong((Long) value, context);
}
}
}
if (IncrementTranslator.isIncrement(operationToken)) {
return IncrementTranslator.translate(expression, context);
}
JsExpression baseExpression = TranslationUtils.translateBaseExpression(context, expression);
if (isExclForBinaryEqualLikeExpr(expression, baseExpression)) {
return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression);
}
ResolvedCall<? extends FunctionDescriptor> resolvedCall = CallUtilKt.getFunctionResolvedCallWithAssert(expression, context.bindingContext());
return CallTranslator.translate(context, resolvedCall, baseExpression);
}
Aggregations