mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
revert
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -15,4 +15,10 @@
|
||||
<problem_class>Constant conditions & exceptions</problem_class>
|
||||
<description>Condition <code>b</code> is always <code>true</code>.</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>5</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constant conditions & exceptions</problem_class>
|
||||
<description>Condition <code>CONST</code> is always <code>true</code></description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user