Fixed IDEA-192024

Java formatter breaks do ... while onto a new line if it exceeds the hard limit
This commit is contained in:
Rustam Vishnyakov
2018-08-13 20:44:49 +03:00
parent 5b9a8a967b
commit 311fa37496
2 changed files with 40 additions and 1 deletions
@@ -224,7 +224,8 @@ public class JavaChildWrapArranger {
}
else if (nodeType == JavaElementType.DO_WHILE_STATEMENT) {
if (role == ChildRole.LOOP_BODY || role == ChildRole.WHILE_KEYWORD) {
if (role == ChildRole.LOOP_BODY ||
role == ChildRole.WHILE_KEYWORD && isAfterNonBlockStatement(child)) {
return Wrap.createWrap(WrapType.NORMAL, true);
}
}
@@ -241,6 +242,13 @@ public class JavaChildWrapArranger {
return suggestedWrap;
}
private static boolean isAfterNonBlockStatement(@NotNull ASTNode node) {
ASTNode prev = node.getTreePrev();
if (prev instanceof PsiWhiteSpace) prev = prev.getTreePrev();
return prev != null && prev.getElementType() != JavaElementType.BLOCK_STATEMENT;
}
private static boolean isTypeAnnotationOrFalseIfDumb(@NotNull ASTNode child) {
PsiElement node = child.getPsi();
PsiElement next = PsiTreeUtil.skipSiblingsForward(node, PsiWhiteSpace.class, PsiAnnotation.class);
@@ -3670,4 +3670,35 @@ public class Test {
"}"
)
}
fun testIdea192024() {
codeStyleBean.apply{
rightMargin = 30
}
doTextTest(
"""
public class Main {
public static void main(String[] args) {
int longCountVar = 0;
do {
System.out.println("Test");
longCountVar ++;
} while(longCountVar <= 1000);
}
}""".trimIndent(),
"""
public class Main {
public static void main(String[] args) {
int longCountVar = 0;
do {
System.out.println("Test");
longCountVar++;
} while (longCountVar <= 1000);
}
}""".trimIndent()
)
}
}