Do not indent control structures parentheses

Fixes:
IDEA-98552 for() statement: Place ')' on new line → "incorrect" alignment
IDEA-175560 Right parenthesis (rparen) on new line is not indented properly
This commit is contained in:
Rustam Vishnyakov
2018-04-25 18:10:02 +03:00
parent b1e88df085
commit 53d0972e83
5 changed files with 69 additions and 3 deletions
@@ -182,6 +182,9 @@ public class BlockContainingJavaBlock extends AbstractJavaBlock{
|| child.getElementType() == JavaElementType.TYPE_PARAMETER_LIST)) {
return Indent.getNoneIndent();
}
else if (child.getElementType() == JavaTokenType.LPARENTH || child.getElementType() == JavaTokenType.RPARENTH) {
return Indent.getNoneIndent();
}
else {
return Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS);
}
@@ -4,7 +4,7 @@ import java.util.List;
class Test {
void test(List<String> list, String key) {
if(key !=/*nullcheck*/ null && !key./*check*/isEmpty() /*and*/ /*key*/ //line comment
) {
) {
list.remove(key);
}
}
@@ -8,7 +8,7 @@ public class Foo {
int thisShouldBeWrapped = 0;
thisShouldBeWrapped < 10;
thisShouldBeWrapped++
) {
) {
}
}
}
@@ -7,7 +7,7 @@ public class Foo {
for (int thisShouldBeWrapped = 0;
thisShouldBeWrapped < 10;
thisShouldBeWrapped++
) {
) {
}
}
}
@@ -3442,4 +3442,67 @@ class JavaFormatterTest : AbstractJavaFormatterTest() {
"}"
)
}
/**
* See IDEA-98552, IDEA-175560
*/
fun testParenthesesIndentation() {
doTextTest(
"""
package com.company;
import java.util.Arrays;
import java.util.List;
class Test {
void foo(boolean bool1, boolean bool2) {
List<String> list = Arrays.asList(
"a", "b", "c"
);
// IDEA-98552
for (
String s : list
) {
System.out.println(s);
}
// IDEA-175560
if (bool1
&& bool2
) { // Indented at continuation indent level
// do stuff
}
}
}
""",
"""
package com.company;
import java.util.Arrays;
import java.util.List;
class Test {
void foo(boolean bool1, boolean bool2) {
List<String> list = Arrays.asList(
"a", "b", "c"
);
// IDEA-98552
for (
String s : list
) {
System.out.println(s);
}
// IDEA-175560
if (bool1
&& bool2
) { // Indented at continuation indent level
// do stuff
}
}
}
"""
)
}
}