mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
invert if: don't include single rBrace in block
found by property testing
This commit is contained in:
+8
-3
@@ -287,9 +287,14 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
|
||||
|
||||
PsiBlockStatement codeBlock = (PsiBlockStatement) factory.createStatementFromText("{}", ifStatement);
|
||||
codeBlock.getCodeBlock().addRange(first, last);
|
||||
ct.replaceAndRestoreComments(ifStatement.getThenBranch(), codeBlock);
|
||||
first.getParent().deleteChildRange(first, last);
|
||||
if (first == last && PsiUtil.isJavaToken(last, JavaTokenType.RBRACE)) {
|
||||
ct.replaceAndRestoreComments(ifStatement.getThenBranch(), codeBlock);
|
||||
}
|
||||
else {
|
||||
codeBlock.getCodeBlock().addRange(first, last);
|
||||
ct.replaceAndRestoreComments(ifStatement.getThenBranch(), codeBlock);
|
||||
first.getParent().deleteChildRange(first, last);
|
||||
}
|
||||
}
|
||||
codeStyle.reformat(ifStatement);
|
||||
return ifStatement;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
void foo(boolean b, String[] entries) {
|
||||
{
|
||||
try {
|
||||
String filePath = "";
|
||||
for (String entry : entries) {
|
||||
final String rootPath = "";
|
||||
if (!b) {
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// "Invert 'if' condition" "true"
|
||||
class A {
|
||||
void foo(boolean b, String[] entries) {
|
||||
{
|
||||
try {
|
||||
String filePath = "";
|
||||
for (String entry : entries) {
|
||||
final String rootPath = "";
|
||||
i<caret>f (b) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user