mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed IDEA-192024
Java formatter breaks do ... while onto a new line if it exceeds the hard limit
This commit is contained in:
+9
-1
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user