IDEA-209947 Explain boolean result from trivial contract

GitOrigin-RevId: 78eef614c45e43e307f8986c79005f2ca6a1fe01
This commit is contained in:
Tagir Valeev
2019-05-07 13:03:41 +03:00
committed by intellij-monorepo-bot
parent b87b7c31c1
commit 22624a343b
11 changed files with 257 additions and 30 deletions
@@ -3,7 +3,7 @@ Value is always false (s.length == list.size(); line#15)
Left operand is >= 1 (s.length; line#15)
Range is known from line #12 (s[0]; line#12)
and right operand is 0 (list.size(); line#15)
Range is known from line #13 (list.isEmpty(); line#13)
Range is known from line #13 (!list.isEmpty(); line#13)
*/
import java.util.List;
@@ -0,0 +1,19 @@
/*
Value is always true (!isString; line#13)
Value 'isString' is always 'false' (isString; line#13)
'isString == false' was established from condition (isString; line#10)
*/
public class ExplainMe {
public int foo(Object a) {
boolean isString = a instanceof String;
if (isString) {
return 0;
}
if (<selection>!isString</selection>) {
return 1;
}
return 0;
}
}
@@ -0,0 +1,12 @@
/*
Value is always true (list.add("foo"); line#9)
According to contract, method 'add' always returns 'true' value (add; line#9)
*/
import java.util.List;
class Test {
void test(List<String> list) {
if(<selection>list.add("foo")</selection>) {}
}
}
@@ -0,0 +1,22 @@
/*
Value is always true (map != null; line#18)
'map' was dereferenced (map; line#14)
*/
import java.util.Map;
public class ExplainMe {
void checkTheMap(Map<String, Integer> map) {
if (map == null) {
System.out.println("that's null");
}
if (map.get("ONE") == null) {
System.out.println("Okay");
}
if (<selection>map != null</selection>) {
System.out.println("not null");
}
}
}
@@ -1,12 +1,12 @@
/*
Value is always true (x < y; line#13)
Condition 'x < y' was checked before (x > y; line#7)
Condition 'x < y' was checked before (x == y; line#9)
*/
class Test {
void test(int x, int y) {
if (x > y) return;
if (x > y) return; // would be better to point also here, but acceptable
if (x == y) { // explanation doesn't point here: not entirely correct, but hard to fix; postponed
if (x == y) {
return;
}
@@ -0,0 +1,15 @@
/*
Value is always false (x; line#12)
'x == false' was established from condition (x; line#9)
*/
class Test {
void test(boolean x) {
if(x) {}
if(x) {
} else {
if(<selection>x</selection>) {}
}
}
}