[java] BlockJoinLinesHandler: avoid removing block when there's only comment inside (IDEA-264288)

GitOrigin-RevId: dad4d5ffb573d186463589162adbd2fcd610157d
This commit is contained in:
Tagir Valeev
2021-03-15 14:41:10 +07:00
committed by intellij-monorepo-bot
parent d2628e93a5
commit cb7790bead
4 changed files with 19 additions and 1 deletions

View File

@@ -56,7 +56,7 @@ public class BlockJoinLinesHandler implements JoinLinesHandlerDelegate {
if (foundStatement != null) return -1;
foundStatement = element;
}
if (foundStatement == null) return -1;
if (!(foundStatement instanceof PsiStatement)) return -1;
PsiElement parent = codeBlock.getParent();
if (isPotentialShortIf(foundStatement) && parent instanceof PsiBlockStatement) {
PsiElement grandParent = parent.getParent();

View File

@@ -0,0 +1,9 @@
class C {
private static void fn(boolean cond) {
<caret>if (cond) {
// comment
} else {
}
}
}

View File

@@ -0,0 +1,8 @@
class C {
private static void fn(boolean cond) {
if (cond) {// comment
} else {
}
}
}

View File

@@ -198,6 +198,7 @@ public class JoinLinesTest extends LightJavaCodeInsightTestCase {
public void testUnwrapCodeBlockIfElse() { doTest(); }
public void testUnwrapCodeBlockIfElse2() { doTest(); }
public void testIfBlockWithComment() { doTest(); }
public void testAssignmentExpression() { doTest(); }
public void testAssignmentExpression2() { doTest(); }
public void testAssignmentExpressionPrecedence() { doTest(); }