diff options
author | Ruslan Iagudin <ruslan_iagudin@epam.com> | 2017-09-14 15:33:42 +0300 |
---|---|---|
committer | rnveach <rveach02@gmail.com> | 2017-09-22 08:11:49 -0400 |
commit | b56d64035982726edf727fe37b1f583a76c96ad7 (patch) | |
tree | e931caaab34915fc33971114b350911b145a3066 | |
parent | 81d52c347f48f9ed31e878fa5ba5f2666c0a5c44 (diff) | |
download | checkstyle-b56d64035982726edf727fe37b1f583a76c96ad7.tar.gz |
Issue #4425: fixed multidimensional array types
4 files changed, 15 insertions, 21 deletions
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/utils/CheckUtils.java b/src/main/java/com/puppycrawl/tools/checkstyle/utils/CheckUtils.java index 05de49d6a..b1222916e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/utils/CheckUtils.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/utils/CheckUtils.java @@ -76,18 +76,15 @@ public final class 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()); } /** @@ -152,15 +149,6 @@ public final class CheckUtils { } /** - * 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. * @param text the string to be parsed. diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java index 4c0302b7d..ba358780d 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/IllegalTypeCheckTest.java @@ -135,7 +135,7 @@ public class IllegalTypeCheckTest extends AbstractModuleTestSupport { @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"), @@ -143,6 +143,9 @@ public class IllegalTypeCheckTest extends AbstractModuleTestSupport { "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); } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java index b39ece624..8735f5392 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/illegaltype/InputIllegalTypeSameFileName.java @@ -26,4 +26,7 @@ public class InputIllegalTypeSameFileName } java.util.List<Integer> list = new ArrayList<>(); //WARNING private ArrayList<String> values; + private Boolean d; //WARNING + private Boolean[] d1; //WARNING + private Boolean[][] d2; //WARNING } diff --git a/src/xdocs/config_coding.xml b/src/xdocs/config_coding.xml index e9825310e..554b8ae05 100644 --- a/src/xdocs/config_coding.xml +++ b/src/xdocs/config_coding.xml @@ -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> |