mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
[java-inspections] IDEA-273527 Incorrect generated code with "Can be replaced with 'Integer.compare'"
GitOrigin-RevId: 4918eebd8b1d6996a8330bf4cbfcc66a367ded18
This commit is contained in:
committed by
intellij-monorepo-bot
parent
987e0ec5e5
commit
05309a5d4e
@@ -124,7 +124,9 @@ public class UseCompareMethodInspection extends AbstractBaseJavaLocalInspectionT
|
||||
if (elseExpression instanceof PsiConditionalExpression) {
|
||||
Map<Integer, PsiExpression> m = extractConditions((PsiConditionalExpression)elseExpression);
|
||||
if (m == null) return null;
|
||||
result.putAll(m);
|
||||
for (var entry : m.entrySet()) {
|
||||
if (result.put(entry.getKey(), entry.getValue()) != null) return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return storeCondition(result, null, elseExpression) ? result : null;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Fix all ''compare()' method can be used to compare numbers' problems in file" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class Sort {
|
||||
static class Point {
|
||||
int x, y;
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
List<Point> l = Arrays.asList(new Point(1, 0), new Point(0, 1), new Point(0, 0)));
|
||||
l.sort((o1, o2) -> o1.x < o2.x ? -1 : o1.x > o2.x ? 1 : Integer.compare(o1.y, o2.y));
|
||||
System.out.println(l);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Fix all ''compare()' method can be used to compare numbers' problems in file" "false"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class Sort {
|
||||
static class Point {
|
||||
int x, y;
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
List<Point> l = Arrays.asList(new Point(1, 0), new Point(0, 1), new Point(0, 0)));
|
||||
l.sort((o1, o2) -> <caret>o1.x < o2.x ? -1 : o1.x > o2.x ? 1 : o1.y < o2.y ? -1 : o1.y > o2.y ? 1 : 0);
|
||||
System.out.println(l);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Fix all ''compare()' method can be used to compare numbers' problems in file" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class Sort {
|
||||
static class Point {
|
||||
int x, y;
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
List<Point> l = Arrays.asList(new Point(1, 0), new Point(0, 1), new Point(0, 0)));
|
||||
l.sort((o1, o2) -> o1.x < o2.x ? -1 : o1.x > o2.x ? 1 : <caret>o1.y < o2.y ? -1 : o1.y > o2.y ? 1 : 0);
|
||||
System.out.println(l);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,11 @@ package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.UseCompareMethodInspection;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase.JAVA_8;
|
||||
|
||||
|
||||
public class UseCompareMethodInspectionTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
@@ -29,6 +32,11 @@ public class UseCompareMethodInspectionTest extends LightQuickFixParameterizedTe
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/useCompareMethod";
|
||||
|
||||
Reference in New Issue
Block a user