Skip to content

Commit

Permalink
Issue #4425: fixed multidimensional array types
Browse files Browse the repository at this point in the history
  • Loading branch information
sergileon authored and rnveach committed Sep 22, 2017
1 parent 81d52c3 commit b56d640
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,15 @@ private CheckUtils() {
* @param typeAST a type node.
* @return {@code FullIdent} for given type.
*/
public static FullIdent createFullType(DetailAST typeAST) {
final DetailAST arrayDeclaratorAST =
typeAST.findFirstToken(TokenTypes.ARRAY_DECLARATOR);
final FullIdent fullType;
public static FullIdent createFullType(final DetailAST typeAST) {
DetailAST ast = typeAST;

if (arrayDeclaratorAST == null) {
fullType = createFullTypeNoArrays(typeAST);
// ignore array part of type
while (ast.findFirstToken(TokenTypes.ARRAY_DECLARATOR) != null) {
ast = ast.findFirstToken(TokenTypes.ARRAY_DECLARATOR);
}
else {
fullType = createFullTypeNoArrays(arrayDeclaratorAST);
}
return fullType;

return FullIdent.createFullIdent(ast.getFirstChild());
}

/**
Expand Down Expand Up @@ -151,15 +148,6 @@ private static boolean isElseWithCurlyBraces(DetailAST ast) {
&& isElse(ast.getParent());
}

/**
* Returns FullIndent for given type.
* @param typeAST a type node (no array)
* @return {@code FullIdent} for given type.
*/
private static FullIdent createFullTypeNoArrays(DetailAST typeAST) {
return FullIdent.createFullIdent(typeAST.getFirstChild());
}

/**
* Returns the value represented by the specified string of the specified
* type. Returns 0 for types other than float, double, int, and long.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ public void testSameFileNameFalsePositive() throws Exception {
@Test
public void testSameFileNameGeneral() throws Exception {
checkConfig.addAttribute("illegalClassNames",
"List, InputIllegalTypeGregorianCalendar, java.io.File, ArrayList");
"List, InputIllegalTypeGregorianCalendar, java.io.File, ArrayList, Boolean");
final String[] expected = {
"10:5: " + getCheckMessage(MSG_KEY, "InputIllegalTypeGregorianCalendar"),
"16:23: " + getCheckMessage(MSG_KEY, "InputIllegalTypeGregorianCalendar"),
"24:9: " + getCheckMessage(MSG_KEY, "List"),
"25:9: " + getCheckMessage(MSG_KEY, "java.io.File"),
"27:5: " + getCheckMessage(MSG_KEY, "java.util.List"),
"28:13: " + getCheckMessage(MSG_KEY, "ArrayList"),
"29:13: " + getCheckMessage(MSG_KEY, "Boolean"),
"30:13: " + getCheckMessage(MSG_KEY, "Boolean"),
"31:13: " + getCheckMessage(MSG_KEY, "Boolean"),
};
verify(checkConfig, getPath("InputIllegalTypeSameFileName.java"), expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ private void foo() {
}
java.util.List<Integer> list = new ArrayList<>(); //WARNING
private ArrayList<String> values;
private Boolean d; //WARNING
private Boolean[] d1; //WARNING
private Boolean[][] d2; //WARNING
}
2 changes: 1 addition & 1 deletion src/xdocs/config_coding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ class SomeClass
<p>Since Checkstyle 3.2</p>
<p>
Checks that particular classes are never used as types in variable
declarations, return values or parameters.
declarations, one-dimensional and multi-dimensional arrays, return values or parameters.
</p>

<p>
Expand Down

0 comments on commit b56d640

Please sign in to comment.