Skip to content

Commit 509be35

Browse files
jungmrnveach
authored andcommitted
Issue #14014: Ignore left curly in line wrapping indentation handler
1 parent 6af8ecf commit 509be35

3 files changed

Lines changed: 75 additions & 16 deletions

File tree

src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/LineWrappingHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static LineWrappingOptions ofBoolean(boolean val) {
8181
* @see CaseHandler#getIndentImpl()
8282
*/
8383
private static final int[] IGNORED_LIST = {
84+
TokenTypes.LCURLY,
8485
TokenTypes.RCURLY,
8586
TokenTypes.LITERAL_NEW,
8687
TokenTypes.ARRAY_INIT,

src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,14 +2816,22 @@ public void testIndentationSwitchExpressionDeclaration() throws Exception {
28162816
checkConfig.addProperty("caseIndent", "4");
28172817
checkConfig.addProperty("lineWrappingIndentation", "8");
28182818
final String[] expected = {
2819-
"33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2820-
"34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2821-
"41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2822-
"42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2823-
"49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2824-
"50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2825-
"57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2826-
"58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2819+
"49:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2820+
"50:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2821+
"58:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2822+
"59:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2823+
"66:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2824+
"67:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2825+
"74:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2826+
"75:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
2827+
"82:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2828+
"83:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2829+
"91:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2830+
"92:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2831+
"99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2832+
"100:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2833+
"108:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
2834+
"109:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
28272835
};
28282836
verifyWarns(checkConfig,
28292837
getNonCompilablePath("InputIndentationCheckSwitchExpressionDeclaration.java"),

src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/InputIndentationCheckSwitchExpressionDeclaration.java

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,101 @@
1212
* forceStrictCondition = false //indent:1 exp:1
1313
*/ //indent:1 exp:1
1414
public class InputIndentationCheckSwitchExpressionDeclaration { //indent:0 exp:0
15-
//indent:82 exp:82
15+
1616
public void validDeclare() { //indent:4 exp:4
1717
String requestId = switch ("in") { //indent:8 exp:8
1818
case "correct" -> "true"; //indent:12 exp:12
1919
default -> "also correct"; //indent:12 exp:12
2020
}; //indent:8 exp:8
2121
} //indent:4 exp:4
22-
//indent:82 exp:82
22+
23+
public void validDeclareLeftCurlyOnNewLine() { //indent:4 exp:4
24+
String requestId = switch ("in") //indent:8 exp:8
25+
{ //indent:8 exp:8
26+
case "correct" -> "true"; //indent:12 exp:12
27+
default -> "also correct"; //indent:12 exp:12
28+
}; //indent:8 exp:8
29+
} //indent:4 exp:4
30+
2331
public void validAssign(String result) { //indent:4 exp:4
2432
result = switch ("in") { //indent:8 exp:8
2533
case "correct" -> "true"; //indent:12 exp:12
2634
default -> "also correct"; //indent:12 exp:12
2735
}; //indent:8 exp:8
2836
} //indent:4 exp:4
29-
//indent:82 exp:82
37+
38+
public void validAssignLeftCurlyOnNewLine(String result) { //indent:4 exp:4
39+
result = switch ("in") //indent:8 exp:8
40+
{ //indent:8 exp:8
41+
case "correct" -> "true"; //indent:12 exp:12
42+
default -> "also correct"; //indent:12 exp:12
43+
}; //indent:8 exp:8
44+
} //indent:4 exp:4
45+
3046
public void invalidDeclareWithBiggerIndent() { //indent:4 exp:4
3147
String requestId = switch ("in") { //indent:8 exp:8
3248
case "correct" -> "true"; //indent:12 exp:12
3349
case "incorrect" -> "true"; //indent:16 exp:12 warn
3450
default -> "also incorrect"; //indent:16 exp:12 warn
3551
}; //indent:8 exp:8
3652
} //indent:4 exp:4
37-
//indent:82 exp:82
53+
54+
public void invalidDeclareWithBiggerIndentLeftCurlyOnNewLine() { //indent:4 exp:4
55+
String requestId = switch ("in") //indent:8 exp:8
56+
{ //indent:8 exp:8
57+
case "correct" -> "true"; //indent:12 exp:12
58+
case "incorrect" -> "true"; //indent:16 exp:12 warn
59+
default -> "also incorrect"; //indent:16 exp:12 warn
60+
}; //indent:8 exp:8
61+
} //indent:4 exp:4
62+
3863
public void invalidAssignWithBiggerIndent(String result) { //indent:4 exp:4
3964
result = switch ("in") { //indent:8 exp:8
4065
case "correct" -> "true"; //indent:12 exp:12
4166
case "incorrect" -> "true"; //indent:16 exp:12 warn
4267
default -> "also incorrect"; //indent:16 exp:12 warn
4368
}; //indent:8 exp:8
4469
} //indent:4 exp:4
45-
//indent:82 exp:82
70+
public void invalidAssignWithBiggerIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
71+
result = switch ("in") //indent:8 exp:8
72+
{ //indent:8 exp:8
73+
case "correct" -> "true"; //indent:12 exp:12
74+
case "incorrect" -> "true"; //indent:16 exp:12 warn
75+
default -> "also incorrect"; //indent:16 exp:12 warn
76+
}; //indent:8 exp:8
77+
} //indent:4 exp:4
78+
4679
public void invalidDeclareWithLesserIndent() { //indent:4 exp:4
4780
String requestId = switch ("in") { //indent:8 exp:8
4881
case "correct" -> "true"; //indent:12 exp:12
4982
case "incorrect" -> "true"; //indent:8 exp:12 warn
5083
default -> "also incorrect"; //indent:8 exp:12 warn
5184
}; //indent:8 exp:8
5285
} //indent:4 exp:4
53-
//indent:82 exp:82
86+
87+
public void invalidDeclareWithLesserIndentLeftCurlyOnNewLine() { //indent:4 exp:4
88+
String requestId = switch ("in") //indent:8 exp:8
89+
{ //indent:8 exp:8
90+
case "correct" -> "true"; //indent:12 exp:12
91+
case "incorrect" -> "true"; //indent:8 exp:12 warn
92+
default -> "also incorrect"; //indent:8 exp:12 warn
93+
}; //indent:8 exp:8
94+
} //indent:4 exp:4
95+
5496
public void invalidAssignWithLesserIndent(String result) { //indent:4 exp:4
5597
result = switch ("in") { //indent:8 exp:8
5698
case "correct" -> "true"; //indent:12 exp:12
5799
case "incorrect" -> "true"; //indent:8 exp:12 warn
58100
default -> "also incorrect"; //indent:8 exp:12 warn
59101
}; //indent:8 exp:8
60102
} //indent:4 exp:4
61-
} //indent:0 exp:0
62-
//indent:82 exp:82
103+
104+
public void invalidAssignWithLesserIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
105+
result = switch ("in") //indent:8 exp:8
106+
{ //indent:8 exp:8
107+
case "correct" -> "true"; //indent:12 exp:12
108+
case "incorrect" -> "true"; //indent:8 exp:12 warn
109+
default -> "also incorrect"; //indent:8 exp:12 warn
110+
}; //indent:8 exp:8
111+
} //indent:4 exp:4
112+
} //indent:0 exp:0

0 commit comments

Comments
 (0)