mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
ensure evaluation don't downcast to long (IDEA-167984)
This commit is contained in:
@@ -483,9 +483,12 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan
|
||||
else if (tokenType == JavaTokenType.TILDE) {
|
||||
if (operandValue instanceof Character) operandValue = Integer.valueOf(((Character)operandValue).charValue());
|
||||
if (isIntegral(operandValue)) {
|
||||
value = operandValue instanceof Long
|
||||
? Long.valueOf(~((Number)operandValue).longValue())
|
||||
: Integer.valueOf(~((Number)operandValue).intValue());
|
||||
if (operandValue instanceof Long) {
|
||||
value = Long.valueOf(~((Number)operandValue).longValue());
|
||||
}
|
||||
else {
|
||||
value = Integer.valueOf(~((Number)operandValue).intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tokenType == JavaTokenType.EXCL) {
|
||||
|
||||
@@ -37,4 +37,13 @@ public class ConstantEvaluatorTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
assertEquals(MyEnum.Foo, result);
|
||||
}
|
||||
|
||||
public void testPrefixExpressionEvaluation() throws Exception {
|
||||
PsiJavaFile file = (PsiJavaFile)myFixture.configureByText("A.java", "class A {public static final int VALUE = ~0 >>> 1;}");
|
||||
PsiClass aClass = file.getClasses()[0];
|
||||
PsiField vField = aClass.getFields()[0];
|
||||
Object result = JavaPsiFacade.getInstance(getProject()).getConstantEvaluationHelper().computeConstantExpression(vField.getInitializer());
|
||||
|
||||
assertEquals(2147483647, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user