Make IntegerValueTypeConstant implements CompileTimeValue<Number>. getValue() method for it is now deprecated - getValue(expectedType) should be used
This commit is contained in:
+3
-10
@@ -24,14 +24,14 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.evaluate.EvaluatePackage;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.NullValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
@@ -85,14 +85,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
return JsLiteral.NULL;
|
||||
}
|
||||
|
||||
Object value = compileTimeValue.getValue();
|
||||
if (value instanceof IntegerValueTypeConstructor) {
|
||||
JetType expectedType = context.bindingContext().get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
CompileTimeConstant<?> newConstant =
|
||||
EvaluatePackage.getCompileTimeConstantForNumberType((IntegerValueTypeConstructor) value, expectedType);
|
||||
assert newConstant != null: "IntegerValueTypeConstant should always have notnull value " + compileTimeValue;
|
||||
value = newConstant.getValue();
|
||||
}
|
||||
Object value = getCompileTimeValue(context.bindingContext(), expression, compileTimeValue);
|
||||
if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
|
||||
return context.program().getNumberLiteral(((Number) value).intValue());
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -187,7 +189,19 @@ public final class BindingUtils {
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull JetExpression expression) {
|
||||
CompileTimeConstant<?> compileTimeValue = context.get(BindingContext.COMPILE_TIME_VALUE, expression);
|
||||
if (compileTimeValue != null) {
|
||||
return compileTimeValue.getValue();
|
||||
return getCompileTimeValue(context, expression, compileTimeValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object getCompileTimeValue(@NotNull BindingContext context, @NotNull JetExpression expression, @NotNull CompileTimeConstant<?> constant) {
|
||||
if (constant != null) {
|
||||
if (constant instanceof IntegerValueTypeConstant) {
|
||||
JetType expectedType = context.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
return ((IntegerValueTypeConstant) constant).getValue(expectedType == null ? TypeUtils.NO_EXPECTED_TYPE : expectedType);
|
||||
}
|
||||
return constant.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user