mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: don't suggest to replace if with switch on non-constant (IDEA-204135)
This commit is contained in:
+9
-1
@@ -230,7 +230,15 @@ public class SwitchUtils {
|
||||
}
|
||||
final PsiExpression left = check.getLeft();
|
||||
final PsiExpression right = check.getRight();
|
||||
return PsiUtil.isConstantExpression(left) ? right : left;
|
||||
if (PsiUtil.isConstantExpression(left)) {
|
||||
return right;
|
||||
}
|
||||
else if (PsiUtil.isConstantExpression(right)) {
|
||||
return left;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canBeCaseLabel(PsiExpression expression, LanguageLevel languageLevel) {
|
||||
|
||||
+24
@@ -92,4 +92,28 @@ class IfCanBeSwitch {
|
||||
System.out.println("-");
|
||||
}
|
||||
}
|
||||
}
|
||||
class MyText implements Comparable<MyText> {
|
||||
|
||||
private String name;
|
||||
|
||||
String getSuperType() {
|
||||
return name.startsWith("a") ? "b" : "c";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MyText o) {
|
||||
String superType = getSuperType();
|
||||
if (superType.equals(o.getSuperType())) {
|
||||
return this.name.compareTo(o.name);
|
||||
} else if (superType.equals("a")) {
|
||||
return -1;
|
||||
} else if (superType.equals("b")) {
|
||||
return 1;
|
||||
} else if (superType.equals("c")) {
|
||||
return o.getSuperType().equals("a") ? 1 : -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user