mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
boolean binary expressions of the format false && non_constant and true || non_constant can be evaluated as constant at compile time
This commit is contained in:
@@ -9,6 +9,12 @@ 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";
|
||||
|
||||
@@ -197,6 +197,28 @@ 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