IDEA-184278 Track relations like "greater than", "less than" in data flow

This commit is contained in:
Tagir Valeev
2018-01-07 12:27:39 +07:00
parent 8dec945235
commit fd12754e17
5 changed files with 133 additions and 48 deletions
@@ -0,0 +1,44 @@
import java.util.*;
class LessThanRelations {
// IDEA-184278
void m(int value) {
for (int i = 0; i < value; i++) {
if (<warning descr="Condition 'i < value' is always 'true'">i < value</warning>) System.out.println();
}
}
void transitive(int a, int b, int c) {
if(a > b && b >= c) {
System.out.println("possible");
if(<warning descr="Condition 'c == a' is always 'false'">c == a</warning>) {
System.out.println("Impossible");
}
if(<warning descr="Condition 'c > a' is always 'false'">c > a</warning>) {
System.out.println("Impossible");
}
}
}
void aioobe(Object[] arr, int pos) {
if(pos >= arr.length) {
System.out.println(arr[<warning descr="Array index is out of bounds">pos</warning>]);
}
}
void wrongOrder(Object[] arr, Object e) {
int index = 0;
while(arr[index] != e && <warning descr="Condition 'index < arr.length' is always 'true' when reached">index < arr.length</warning>) {
index++;
}
System.out.println(index);
}
void list(List<String> list, int index) {
if(index >= list.size()) {
System.out.println("Big index");
} else if(index > 0 && <warning descr="Condition '!list.isEmpty()' is always 'true' when reached">!<warning descr="Condition 'list.isEmpty()' is always 'false' when reached">list.isEmpty()</warning></warning>) {
System.out.println("ok");
}
}
}
@@ -23,7 +23,7 @@ class Zoo2 {
void foo(Some me, Some other) {
if (me.depth < other.depth) {
System.out.println("less");
} else if (other.depth > me.depth) {
} else if (<warning descr="Condition 'other.depth > me.depth' is always 'false'">other.depth > me.depth</warning>) {
System.out.println("more");
}
}