mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
ComparatorResultComparisonInspection: support >/>=/</<= checks
Additional fix for IDEA-173177. Now conditions like "a.compareTo(b) > 1" are warned as well.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,25 +15,46 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.ComparatorResultComparisonInspection;
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ComparatorResultComparisonInspectionTest extends LightQuickFixParameterizedTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{
|
||||
new ComparatorResultComparisonInspection()
|
||||
};
|
||||
public class ComparatorResultComparisonInspectionTest extends LightInspectionTestCase {
|
||||
public static final String TEST_DATA_DIR = "/codeInsight/daemonCodeAnalyzer/quickFix/comparatorResultComparison/";
|
||||
|
||||
public void testComparatorResultComparison() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
@Override
|
||||
protected InspectionProfileEntry getInspection() {
|
||||
return new ComparatorResultComparisonInspection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/comparatorResultComparison";
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + TEST_DATA_DIR;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComparatorResultComparisonInspectionFixTest extends LightQuickFixParameterizedTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return new LocalInspectionTool[]{new ComparatorResultComparisonInspection()};
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return TEST_DATA_DIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user