From 0091ec715a95d894e5bdd43821eaad5cfee2b54c Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 28 Jun 2011 12:12:18 +0200 Subject: [PATCH] revert --- .../psi/impl/ConstantExpressionVisitor.java | 62 +++++++++---------- .../dataFlow/compileTimeConst/expected.xml | 6 ++ .../constantValues/ClassWithConstants.java | 8 +-- .../com/intellij/psi/ConstantValuesTest.java | 22 ------- 4 files changed, 37 insertions(+), 61 deletions(-) diff --git a/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java b/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java index 46cc161baf01..6555f82162c2 100644 --- a/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java +++ b/java/java-impl/src/com/intellij/psi/impl/ConstantExpressionVisitor.java @@ -113,43 +113,15 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan } Object rOperandValue = getStoredValue(expression.getROperand()); - - PsiJavaToken operationSign = expression.getOperationSign(); - final IElementType tokenType = operationSign.getTokenType(); - - Object value = null; - if (tokenType == JavaTokenType.ANDAND) { - if (lOperandValue instanceof Boolean && !((Boolean)lOperandValue).booleanValue()) { - myResult = Boolean.FALSE; - return; - } - if (rOperandValue instanceof Boolean && !((Boolean)rOperandValue).booleanValue()) { - myResult = Boolean.FALSE; - return; - } - if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { - value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() && ((Boolean)rOperandValue).booleanValue()); - } - } - else if (tokenType == JavaTokenType.OROR) { - if (lOperandValue instanceof Boolean && ((Boolean)lOperandValue).booleanValue()) { - myResult = Boolean.TRUE; - return; - } - if (rOperandValue instanceof Boolean && ((Boolean)rOperandValue).booleanValue()) { - myResult = Boolean.TRUE; - return; - } - if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { - value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() || ((Boolean)rOperandValue).booleanValue()); - } - } - if (rOperandValue == null) { myResult = null; return; } + PsiJavaToken operationSign = expression.getOperationSign(); + final IElementType tokenType = operationSign.getTokenType(); + + Object value = null; if (tokenType == JavaTokenType.PLUS) { if (lOperandValue instanceof String || rOperandValue instanceof String) { value = myInterner.intern(lOperandValue.toString() + rOperandValue.toString()); @@ -208,6 +180,32 @@ class ConstantExpressionVisitor extends JavaElementVisitor implements PsiConstan } } } + else if (tokenType == JavaTokenType.ANDAND) { + if (lOperandValue instanceof Boolean && !((Boolean)lOperandValue).booleanValue()) { + myResult = Boolean.FALSE; + return; + } + if (rOperandValue instanceof Boolean && !((Boolean)rOperandValue).booleanValue()) { + myResult = Boolean.FALSE; + return; + } + if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { + value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() && ((Boolean)rOperandValue).booleanValue()); + } + } + else if (tokenType == JavaTokenType.OROR) { + if (lOperandValue instanceof Boolean && ((Boolean)lOperandValue).booleanValue()) { + myResult = Boolean.TRUE; + return; + } + if (rOperandValue instanceof Boolean && ((Boolean)rOperandValue).booleanValue()) { + myResult = Boolean.TRUE; + return; + } + if (lOperandValue instanceof Boolean && rOperandValue instanceof Boolean) { + value = Boolean.valueOf(((Boolean)lOperandValue).booleanValue() || ((Boolean)rOperandValue).booleanValue()); + } + } else if (tokenType == JavaTokenType.LT) { if (lOperandValue instanceof Character) lOperandValue = Integer.valueOf(((Character)lOperandValue).charValue()); if (rOperandValue instanceof Character) rOperandValue = Integer.valueOf(((Character)rOperandValue).charValue()); diff --git a/java/java-tests/testData/inspection/dataFlow/compileTimeConst/expected.xml b/java/java-tests/testData/inspection/dataFlow/compileTimeConst/expected.xml index 65c2987e3d63..9b4185d3ca02 100644 --- a/java/java-tests/testData/inspection/dataFlow/compileTimeConst/expected.xml +++ b/java/java-tests/testData/inspection/dataFlow/compileTimeConst/expected.xml @@ -15,4 +15,10 @@ Constant conditions & exceptions Condition <code>b</code> is always <code>true</code>. + + Test.java + 5 + Constant conditions & exceptions + Condition <code>CONST</code> is always <code>true</code> + diff --git a/java/java-tests/testData/psi/constantValues/ClassWithConstants.java b/java/java-tests/testData/psi/constantValues/ClassWithConstants.java index 44108e221be6..374c0cf3bd85 100644 --- a/java/java-tests/testData/psi/constantValues/ClassWithConstants.java +++ b/java/java-tests/testData/psi/constantValues/ClassWithConstants.java @@ -9,12 +9,6 @@ public class ClassWithConstants { public static final byte BYTE_CONST = 4; public static final char CHAR_CONST = '5'; public static final boolean BOOL_CONST = true; - - public static final boolean BOOL_CONST2 = false && foo(); - public static final boolean BOOL_CONST3 = true || foo(); - static boolean foo() { - return false; - } public static final float FLOAT_CONST = 1.234f; public static final double DOUBLE_CONST = 3.456; public static final java.lang.String STRING_CONST = "a\r\n\"bcd"; @@ -22,4 +16,4 @@ public class ClassWithConstants { public static final double d1 = Double.POSITIVE_INFINITY; public static final double d2 = Double.NEGATIVE_INFINITY; public static final double d3 = Double.NaN; -} \ No newline at end of file +} diff --git a/java/java-tests/testSrc/com/intellij/psi/ConstantValuesTest.java b/java/java-tests/testSrc/com/intellij/psi/ConstantValuesTest.java index 28a5cfccc298..056e85d55921 100644 --- a/java/java-tests/testSrc/com/intellij/psi/ConstantValuesTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/ConstantValuesTest.java @@ -197,28 +197,6 @@ public class ConstantValuesTest extends PsiTestCase{ assertEquals(Boolean.TRUE, field.computeConstantValue()); } - public void testBoolean2(){ - PsiField field = myClass.findFieldByName("BOOL_CONST2", false); - assertNotNull(field); - final PsiExpression initializer = field.getInitializer(); - assertNotNull(initializer); - assertEquals(PsiType.BOOLEAN, initializer.getType()); - assertEquals("false && foo()", initializer.getText()); - - assertEquals(Boolean.FALSE, field.computeConstantValue()); - } - - public void testBoolean3(){ - PsiField field = myClass.findFieldByName("BOOL_CONST3", false); - assertNotNull(field); - final PsiExpression initializer = field.getInitializer(); - assertNotNull(initializer); - assertEquals(PsiType.BOOLEAN, initializer.getType()); - assertEquals("true || foo()", initializer.getText()); - - assertEquals(Boolean.TRUE, field.computeConstantValue()); - } - public void testFloat(){ PsiField field = myClass.findFieldByName("FLOAT_CONST", false); assertNotNull(field);