Skip to content

Commit

Permalink
Issue checkstyle#14014: Ignore left curly in line wrapping indentatio…
Browse files Browse the repository at this point in the history
…n handler
  • Loading branch information
jungm committed Nov 12, 2023
1 parent d52eb5d commit f5b01b9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static LineWrappingOptions ofBoolean(boolean val) {
* @see CaseHandler#getIndentImpl()
*/
private static final int[] IGNORED_LIST = {
TokenTypes.LCURLY,
TokenTypes.RCURLY,
TokenTypes.LITERAL_NEW,
TokenTypes.ARRAY_INIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2816,14 +2816,22 @@ public void testIndentationSwitchExpressionDeclaration() throws Exception {
checkConfig.addProperty("caseIndent", "4");
checkConfig.addProperty("lineWrappingIndentation", "8");
final String[] expected = {
"33:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"34:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"41:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"42:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"49:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"50:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"57:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"58:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"49:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"50:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"58:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"59:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"66:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"67:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"74:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"75:17: " + getCheckMessage(MSG_CHILD_ERROR, "case", 16, 12),
"82:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"83:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"91:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"92:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"99:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"100:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"108:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"109:9: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
};
verifyWarns(checkConfig,
getNonCompilablePath("InputIndentationCheckSwitchExpressionDeclaration.java"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,101 @@
* forceStrictCondition = false //indent:1 exp:1
*/ //indent:1 exp:1
public class InputIndentationCheckSwitchExpressionDeclaration { //indent:0 exp:0
//indent:82 exp:82

public void validDeclare() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
//indent:82 exp:82

public void validDeclareLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void validAssign(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4
//indent:82 exp:82

public void validAssignLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
default -> "also correct"; //indent:12 exp:12
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidDeclareWithBiggerIndent() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
//indent:82 exp:82

public void invalidDeclareWithBiggerIndentLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidAssignWithBiggerIndent(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
//indent:82 exp:82
public void invalidAssignWithBiggerIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:16 exp:12 warn
default -> "also incorrect"; //indent:16 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidDeclareWithLesserIndent() { //indent:4 exp:4
String requestId = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
//indent:82 exp:82

public void invalidDeclareWithLesserIndentLeftCurlyOnNewLine() { //indent:4 exp:4
String requestId = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4

public void invalidAssignWithLesserIndent(String result) { //indent:4 exp:4
result = switch ("in") { //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
} //indent:0 exp:0
//indent:82 exp:82

public void invalidAssignWithLesserIndentLeftCurlyOnNewLine(String result) { //indent:4 exp:4
result = switch ("in") //indent:8 exp:8
{ //indent:8 exp:8
case "correct" -> "true"; //indent:12 exp:12
case "incorrect" -> "true"; //indent:8 exp:12 warn
default -> "also incorrect"; //indent:8 exp:12 warn
}; //indent:8 exp:8
} //indent:4 exp:4
} //indent:0 exp:0

0 comments on commit f5b01b9

Please sign in to comment.