use of org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant in project kotlin by JetBrains.
the class CompileTimeConstantUtils method canBeReducedToBooleanConstant.
public static boolean canBeReducedToBooleanConstant(@Nullable KtExpression expression, @NotNull BindingContext context, @Nullable Boolean expectedValue) {
KtExpression effectiveExpression = KtPsiUtil.deparenthesize(expression);
if (effectiveExpression == null)
return false;
CompileTimeConstant<?> compileTimeConstant = ConstantExpressionEvaluator.getConstant(effectiveExpression, context);
if (!(compileTimeConstant instanceof TypedCompileTimeConstant) || compileTimeConstant.getUsesVariableAsConstant())
return false;
ConstantValue constantValue = ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue();
if (!(constantValue instanceof BooleanValue))
return false;
Boolean value = ((BooleanValue) constantValue).getValue();
return expectedValue == null || expectedValue.equals(value);
}
Aggregations