Skip to content

Commit

Permalink
Issue checkstyle#1509: Extra comma is required in multi-line array value
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladlis committed Apr 12, 2017
1 parent 73e8b21 commit 5f07415
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ public int[] getRequiredTokens() {
@Override
public void visitToken(DetailAST arrayInit) {
final DetailAST rcurly = arrayInit.findFirstToken(TokenTypes.RCURLY);
final DetailAST previousSibling = rcurly.getPreviousSibling();

// if curlies are on the same line
// or array is empty then check nothing
if (arrayInit.getLineNo() != rcurly.getLineNo()
&& arrayInit.getChildCount() != 1) {
final DetailAST prev = rcurly.getPreviousSibling();
if (prev.getType() != TokenTypes.COMMA) {
log(rcurly.getLineNo(), MSG_KEY);
}
&& arrayInit.getChildCount() != 1
&& rcurly.getLineNo() != previousSibling.getLineNo()
&& arrayInit.getLineNo() != previousSibling.getLineNo()
&& previousSibling.getType() != TokenTypes.COMMA) {
log(rcurly.getLineNo(), MSG_KEY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void testDefault()
createCheckConfig(ArrayTrailingCommaCheck.class);
final String[] expected = {
"17: " + getCheckMessage(MSG_KEY),
"34: " + getCheckMessage(MSG_KEY),
"37: " + getCheckMessage(MSG_KEY),
};
verify(checkConfig, getPath("InputArrayTrailingComma.java"), expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ public class InputArrayTrailingComma

int[] e1 = new int[] {
};

int[] f1 = new int[] {0, 1
};
}

0 comments on commit 5f07415

Please sign in to comment.