diff --git a/pom.xml b/pom.xml
index da38728d3..dd0015f0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1095,7 +1095,6 @@
.*.checks.SuppressWarningsHolder7593
.*.checks.TrailingCommentCheck9093
.*.checks.TranslationCheck8183
- .*.checks.UncommentedMainCheck8388
.*.checks.UniquePropertiesCheck\$.*7590
.*.checks.coding.AbstractSuperCheck7889
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java
index 852af0f22..b5390d49a 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java
@@ -115,6 +115,7 @@ public class UncommentedMainCheck
@Override
public void visitToken(DetailAST ast) {
+
switch (ast.getType()) {
case TokenTypes.PACKAGE_DEF:
visitPackageDef(ast);
@@ -235,13 +236,8 @@ public class UncommentedMainCheck
final DetailAST arrayType = arrayDecl.getFirstChild();
- if (arrayType.getType() == TokenTypes.IDENT
- || arrayType.getType() == TokenTypes.DOT) {
- final FullIdent type = FullIdent.createFullIdent(arrayType);
- return "String".equals(type.getText())
- || "java.lang.String".equals(type.getText());
- }
-
- return false;
+ final FullIdent type = FullIdent.createFullIdent(arrayType);
+ return "String".equals(type.getText())
+ || "java.lang.String".equals(type.getText());
}
}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java
index 419ed9d05..0a971a1ba 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java
@@ -21,10 +21,15 @@ package com.puppycrawl.tools.checkstyle.checks;
import static com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck.MSG_KEY;
+import org.junit.Assert;
import org.junit.Test;
+import antlr.CommonHiddenStreamToken;
+
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class UncommentedMainCheckTest
extends BaseCheckTestSupport {
@@ -53,4 +58,52 @@ public class UncommentedMainCheckTest
};
verify(checkConfig, getPath("InputUncommentedMain.java"), expected);
}
+
+ @Test
+ public void testTokens() throws Exception {
+ UncommentedMainCheck check = new UncommentedMainCheck();
+ Assert.assertNotNull(check.getRequiredTokens());
+ Assert.assertNotNull(check.getAcceptableTokens());
+ Assert.assertArrayEquals(check.getDefaultTokens(), check.getAcceptableTokens());
+ Assert.assertArrayEquals(check.getDefaultTokens(), check.getRequiredTokens());
+ }
+
+ @Test
+ public void testDeepDepth() throws Exception {
+ final DefaultConfiguration checkConfig = createCheckConfig(UncommentedMainCheck.class);
+ final String[] expected = {
+ };
+ verify(checkConfig, getPath("InputUncommentedMain2.java"), expected);
+ }
+
+ @Test
+ public void testWrongName() throws Exception {
+ final DefaultConfiguration checkConfig = createCheckConfig(UncommentedMainCheck.class);
+ final String[] expected = {
+ };
+ verify(checkConfig, getPath("InputUncommentedMain3.java"), expected);
+ }
+
+ @Test
+ public void testWrongArrayType() throws Exception {
+ final DefaultConfiguration checkConfig = createCheckConfig(UncommentedMainCheck.class);
+ final String[] expected = {
+ };
+ verify(checkConfig, getPath("InputUncommentedMain4.java"), expected);
+ }
+
+ @Test
+ public void testIllegalStateException() throws Exception {
+ UncommentedMainCheck check = new UncommentedMainCheck();
+ DetailAST ast = new DetailAST();
+ ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
+ try {
+ check.visitToken(ast);
+ Assert.fail();
+ }
+ catch (IllegalStateException ex) {
+ ast.toString().equals(ex.getMessage());
+ }
+
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain2.java
new file mode 100644
index 000000000..dff167c4d
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain2.java
@@ -0,0 +1,41 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2003
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle;
+
+
+public class InputUncommentedMain2
+{
+ private class PC {
+
+ // uncommented main with depth 2
+ public void main(String[] args)
+ {
+ System.out.println("InputUncommentedMain.main()");
+ }
+
+ //lets go deeper
+ private class PC2 {
+
+ // uncommented main with depth 3
+ public void main(String[] args)
+ {
+ System.out.println("InputUncommentedMain.main()");
+ }
+
+
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ System.out.println("InputUncommentedMain.main()");
+ }
+
+}
+
+interface IF {
+
+ void main(String[] args);
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain3.java b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain3.java
new file mode 100644
index 000000000..f7b4773e9
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain3.java
@@ -0,0 +1,13 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2003
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle;
+
+class oneMoreClass {
+
+ public static void anyWrongMethodName(String[] args)
+ {
+ System.out.println("InputUncommentedMain.main()");
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain4.java b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain4.java
new file mode 100644
index 000000000..49764c0b4
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/InputUncommentedMain4.java
@@ -0,0 +1,14 @@
+////////////////////////////////////////////////////////////////////////////////
+// Test case file for checkstyle.
+// Created: 2003
+////////////////////////////////////////////////////////////////////////////////
+package com.puppycrawl.tools.checkstyle;
+
+class InputUncommentedMainTest4
+{
+ // one more uncommented main
+ public static void main(int[] args)
+ {
+ System.out.println("test1.main()");
+ }
+}