IDEA-99725 "Constant conditions & exceptions" inspection produces invalid code

This commit is contained in:
peter
2013-02-03 22:42:55 +01:00
parent 7d5c3aeabc
commit 8a3b6547f6
3 changed files with 29 additions and 1 deletions
@@ -49,7 +49,15 @@ public class ReplaceWithTernaryOperatorFix implements LocalQuickFix {
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement element = descriptor.getPsiElement();
PsiElement element = descriptor.getPsiElement();
while (true) {
PsiElement parent = element.getParent();
if (parent instanceof PsiReferenceExpression || parent instanceof PsiMethodCallExpression) {
element = parent;
} else {
break;
}
}
if (!(element instanceof PsiExpression)) {
return;
}
@@ -0,0 +1,10 @@
// "Replace with 'integer != null ?:'" "true"
import java.lang.Integer;
class A{
void test(){
Integer integer = null;
int i = integer != null ? integer.toString().length() : <selection>0</selection>;
}
}
@@ -0,0 +1,10 @@
// "Replace with 'integer != null ?:'" "true"
import java.lang.Integer;
class A{
void test(){
Integer integer = null;
int i = in<caret>teger.toString().length();
}
}