invert if: do not skip returns as they may contain valuable info (IDEA-61892)

This commit is contained in:
anna
2010-12-22 22:25:20 +03:00
parent 79b47c42ad
commit 9010b36338
4 changed files with 21 additions and 2 deletions
@@ -209,7 +209,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
PsiStatement[] statements = ((PsiBlockStatement) thenBranch).getCodeBlock().getStatements();
int len = statements.length;
if (len > 0) {
if (statements[len - 1] instanceof PsiReturnStatement) len--;
//if (statements[len - 1] instanceof PsiReturnStatement) len--;
if (len > 0) {
PsiElement firstElement = statements [0];
while (firstElement.getPrevSibling() instanceof PsiWhiteSpace || firstElement.getPrevSibling() instanceof PsiComment) {
@@ -44,7 +44,7 @@ public class a {
ia[~i | (i+=(!b?2:i))] -= i + 3.3;
// Object += String
o += o + "string";
<error descr="Operator '+' cannot be applied to 'java.lang.Object','java.lang.String'">o += o + "string"</error>;
return 0;
}
@@ -0,0 +1,10 @@
// "Invert If Condition" "true"
class Test {
public static int create() {
if (true) {
return;
}
return "s";
}
}
@@ -0,0 +1,9 @@
// "Invert If Condition" "true"
class Test {
public static int create() {
if (!tr<caret>ue) {
return "s";
}
}
}