ComparatorResultComparisonInspection: support >/>=/</<= checks

Additional fix for IDEA-173177. Now conditions like "a.compareTo(b) > 1" are warned as well.
This commit is contained in:
Tagir Valeev
2017-06-08 10:14:34 +07:00
parent 6643c4a636
commit a5dcf8841f
5 changed files with 77 additions and 42 deletions
@@ -0,0 +1,19 @@
import java.util.*;
class Test {
void test(Comparator<String> cmp) {
if(cmp.compare("a", "b") <warning descr="Comparison of compare method result with specific constant">!=</warning> -1) {
System.out.println("Oops");
}
if(cmp.compare("a", "b") <warning descr="Comparison of compare method result with specific constant">></warning> 1) {
System.out.println("Bad");
}
if(cmp.compare("a", "b") >= 1) {
System.out.println("Ok");
}
if(cmp.compare("a", "b") < 1) {
System.out.println("Ok");
}
}
}
@@ -1,10 +0,0 @@
// "Replace with '>= 0'" "true"
import java.util.*;
class Test {
void test(Comparator<String> cmp) {
if(cmp.compare("a", "b") >= 0) {
System.out.println("Oops");
}
}
}
@@ -1,10 +0,0 @@
// "Replace with '>= 0'" "true"
import java.util.*;
class Test {
void test(Comparator<String> cmp) {
if(cmp.compare("a", "b") !<caret>= -1) {
System.out.println("Oops");
}
}
}