diff --git a/config/checkstyle_input_suppressions.xml b/config/checkstyle_input_suppressions.xml
index db6a158841e..b14039b891b 100644
--- a/config/checkstyle_input_suppressions.xml
+++ b/config/checkstyle_input_suppressions.xml
@@ -153,26 +153,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1037,26 +1017,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java
index 4ab152d8cb9..1f9538cdc0a 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java
@@ -55,9 +55,9 @@ public void testMaximumNumber()
checkConfig.addProperty("limitedTokens", "LITERAL_NATIVE");
checkConfig.addProperty("maximumNumber", "0");
final String[] expected = {
- "17:12: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "LITERAL_NATIVE", "LITERAL_NATIVE"),
+ "32:12: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "LITERAL_NATIVE", "LITERAL_NATIVE"),
};
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens2.java"), expected);
}
@Test
@@ -70,9 +70,9 @@ public void testMessage()
checkConfig.addProperty("maximumNumber", "0");
checkConfig.addProperty("maximumMessage", "Using ''native'' is not allowed.");
final String[] expected = {
- "17:12: Using 'native' is not allowed.",
+ "32:12: Using 'native' is not allowed.",
};
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens3.java"), expected);
}
@Test
@@ -84,9 +84,9 @@ public void testMinimumNumber()
checkConfig.addProperty("limitedTokens", "LITERAL_DEFAULT");
checkConfig.addProperty("minimumNumber", "2");
final String[] expected = {
- "8:9: " + getCheckMessage(MSG_KEY_MIN, 1, 2, "LITERAL_SWITCH", "LITERAL_DEFAULT"),
+ "23:9: " + getCheckMessage(MSG_KEY_MIN, 1, 2, "LITERAL_SWITCH", "LITERAL_DEFAULT"),
};
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens4.java"), expected);
}
@Test
@@ -99,7 +99,7 @@ public void testMinimumDepth()
checkConfig.addProperty("maximumNumber", "0");
checkConfig.addProperty("minimumDepth", "3");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens5.java"), expected);
}
@Test
@@ -112,7 +112,7 @@ public void testMaximumDepth()
checkConfig.addProperty("maximumNumber", "0");
checkConfig.addProperty("maximumDepth", "1");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens6.java"), expected);
}
@Test
@@ -127,22 +127,22 @@ public void testEmptyStatements()
checkConfig.addProperty("maximumMessage", "Empty statement.");
final String[] expected = {
- "7:7: Empty statement.",
- "12:7: Empty statement.",
- "17:19: Empty statement.",
- "21:10: Empty statement.",
- "24:16: Empty statement.",
- "28:10: Empty statement.",
- "38:10: Empty statement.",
- "44:13: Empty statement.",
- "46:13: Empty statement.",
- "49:19: Empty statement.",
+ "22:7: Empty statement.",
+ "27:7: Empty statement.",
+ "32:19: Empty statement.",
+ "36:10: Empty statement.",
+ "39:16: Empty statement.",
+ "43:10: Empty statement.",
"53:10: Empty statement.",
- "56:9: Empty statement.",
- "61:10: Empty statement.",
- "67:10: Empty statement.",
- "71:10: Empty statement.",
- "75:10: Empty statement.",
+ "59:13: Empty statement.",
+ "61:13: Empty statement.",
+ "64:19: Empty statement.",
+ "68:10: Empty statement.",
+ "71:9: Empty statement.",
+ "76:10: Empty statement.",
+ "82:10: Empty statement.",
+ "86:10: Empty statement.",
+ "90:10: Empty statement.",
};
verify(checkConfig, getPath("InputDescendantTokenEmptyStatement.java"), expected);
@@ -159,7 +159,7 @@ public void testMissingSwitchDefault() throws Exception {
checkConfig.addProperty("minimumMessage", "switch without \"default\" clause.");
final String[] expected = {
- "17:9: switch without \"default\" clause.",
+ "32:9: switch without \"default\" clause.",
};
verify(checkConfig, getPath("InputDescendantTokenMissingSwitchDefault.java"), expected);
@@ -177,9 +177,9 @@ public void testStringLiteralEquality() throws Exception {
"Literal Strings should be compared using equals(), not ''==''.");
final String[] expected = {
- "7:18: Literal Strings should be compared using equals(), not '=='.",
- "12:20: Literal Strings should be compared using equals(), not '=='.",
- "17:22: Literal Strings should be compared using equals(), not '=='.",
+ "22:18: Literal Strings should be compared using equals(), not '=='.",
+ "27:20: Literal Strings should be compared using equals(), not '=='.",
+ "32:22: Literal Strings should be compared using equals(), not '=='.",
};
verify(checkConfig, getPath("InputDescendantTokenStringLiteralEquality.java"), expected);
}
@@ -195,11 +195,11 @@ public void testIllegalTokenDefault() throws Exception {
checkConfig.addProperty("maximumMessage", "Using ''{2}'' is not allowed.");
final String[] expected = {
- "8:9: Using 'LITERAL_SWITCH' is not allowed.",
- "11:18: Using 'POST_DEC' is not allowed.",
- "12:18: Using 'POST_INC' is not allowed.",
+ "23:9: Using 'LITERAL_SWITCH' is not allowed.",
+ "26:18: Using 'POST_DEC' is not allowed.",
+ "27:18: Using 'POST_INC' is not allowed.",
};
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens7.java"), expected);
}
@Test
@@ -213,9 +213,9 @@ public void testIllegalTokenNative() throws Exception {
checkConfig.addProperty("maximumMessage", "Using ''{2}'' is not allowed.");
final String[] expected = {
- "17:12: Using 'LITERAL_NATIVE' is not allowed.",
+ "32:12: Using 'LITERAL_NATIVE' is not allowed.",
};
- verify(checkConfig, getPath("InputDescendantTokenIllegalTokens.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenIllegalTokens8.java"), expected);
}
@Test
@@ -228,8 +228,8 @@ public void testReturnFromCatch() throws Exception {
checkConfig.addProperty("maximumMessage", "Return from catch is not allowed.");
final String[] expected = {
- "7:11: Return from catch is not allowed.",
- "15:11: Return from catch is not allowed.",
+ "22:11: Return from catch is not allowed.",
+ "30:11: Return from catch is not allowed.",
};
verify(checkConfig, getPath("InputDescendantTokenReturnFromCatch.java"), expected);
@@ -245,8 +245,8 @@ public void testReturnFromFinally() throws Exception {
checkConfig.addProperty("maximumMessage", "Return from finally is not allowed.");
final String[] expected = {
- "7:11: Return from finally is not allowed.",
- "15:11: Return from finally is not allowed.",
+ "22:11: Return from finally is not allowed.",
+ "30:11: Return from finally is not allowed.",
};
verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
@@ -263,7 +263,7 @@ public void testNoSum() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
- verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally2.java"), expected);
}
@Test
@@ -277,13 +277,13 @@ public void testWithSumCustomMsg() throws Exception {
checkConfig.addProperty("sumTokenCounts", "true");
final String[] expected = {
- "22:32: this cannot be null.",
- "22:50: this cannot be null.",
- "23:33: this cannot be null.",
- "23:51: this cannot be null.",
+ "37:32: this cannot be null.",
+ "37:50: this cannot be null.",
+ "38:33: this cannot be null.",
+ "38:51: this cannot be null.",
};
- verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally3.java"), expected);
}
@Test
@@ -296,13 +296,13 @@ public void testWithSumDefaultMsg() throws Exception {
checkConfig.addProperty("sumTokenCounts", "true");
final String[] expected = {
- "22:32: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"),
- "22:50: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"),
- "23:33: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"),
- "23:51: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"),
+ "37:32: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"),
+ "37:50: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"),
+ "38:33: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"),
+ "38:51: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"),
};
- verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally4.java"), expected);
}
@Test
@@ -314,16 +314,16 @@ public void testWithSumLessThenMinDefMsg() throws Exception {
checkConfig.addProperty("sumTokenCounts", "true");
final String[] expected = {
- "16:44: " + getCheckMessage(MSG_KEY_SUM_MIN, 0, 3, "EQUAL"),
- "22:32: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
- "22:50: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
- "23:33: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
- "23:51: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
- "25:13: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
- "25:36: " + getCheckMessage(MSG_KEY_SUM_MIN, 1, 3, "EQUAL"),
+ "31:44: " + getCheckMessage(MSG_KEY_SUM_MIN, 0, 3, "EQUAL"),
+ "37:32: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
+ "37:50: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
+ "38:33: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
+ "38:51: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "NOT_EQUAL"),
+ "40:13: " + getCheckMessage(MSG_KEY_SUM_MIN, 2, 3, "EQUAL"),
+ "40:36: " + getCheckMessage(MSG_KEY_SUM_MIN, 1, 3, "EQUAL"),
};
- verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally5.java"), expected);
}
@Test
@@ -336,16 +336,16 @@ public void testWithSumLessThenMinCustomMsg() throws Exception {
checkConfig.addProperty("minimumMessage", "custom message");
final String[] expected = {
- "16:44: custom message",
- "22:32: custom message",
- "22:50: custom message",
- "23:33: custom message",
- "23:51: custom message",
- "25:13: custom message",
- "25:36: custom message",
+ "31:44: custom message",
+ "37:32: custom message",
+ "37:50: custom message",
+ "38:33: custom message",
+ "38:51: custom message",
+ "40:13: custom message",
+ "40:36: custom message",
};
- verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenReturnFromFinally6.java"), expected);
}
@Test
@@ -357,8 +357,8 @@ public void testMaxTokenType() throws Exception {
checkConfig.addProperty("maximumNumber", "0");
checkConfig.addProperty("maximumDepth", "2");
final String[] expected = {
- "6:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "LCURLY"),
- "6:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "RCURLY"),
+ "21:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "LCURLY"),
+ "21:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "RCURLY"),
};
verify(checkConfig, getPath("InputDescendantTokenLastTokenType.java"), expected);
}
@@ -372,10 +372,10 @@ public void testMaxTokenTypeReverseOrder() throws Exception {
checkConfig.addProperty("maximumNumber", "0");
checkConfig.addProperty("maximumDepth", "2");
final String[] expected = {
- "6:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "LCURLY"),
- "6:48: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "RCURLY"),
+ "21:49: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "LCURLY"),
+ "21:49: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "OBJBLOCK", "RCURLY"),
};
- verify(checkConfig, getPath("InputDescendantTokenLastTokenType.java"), expected);
+ verify(checkConfig, getPath("InputDescendantTokenLastTokenType2.java"), expected);
}
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenEmptyStatement.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenEmptyStatement.java
index 357a328bb06..50d9727510d 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenEmptyStatement.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenEmptyStatement.java
@@ -1,10 +1,25 @@
+/*
+DescendantToken
+limitedTokens = (EMPTY_STAT
+minimumDepth = (default)0
+maximumDepth = 0
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Empty statement.
+tokens = EMPTY_STAT
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
public class InputDescendantTokenEmptyStatement
{
public InputDescendantTokenEmptyStatement()
{
- ;
+ ; // violation
}
public void EmptyMethod()
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens.java
index 0c569b61d63..370ee7897c7 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens.java
@@ -1,6 +1,21 @@
+/*
+DescendantToken
+limitedTokens = (default)
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = (default)2147483647
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = (default)empty
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
-public class InputDescendantTokenIllegalTokens
+public class InputDescendantTokenIllegalTokens // ok
{
public void methodWithPreviouslyIllegalTokens()
{
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens2.java
new file mode 100644
index 00000000000..e0ddace2c22
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens2.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_NATIVE
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = LITERAL_NATIVE
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens2
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i)
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod(); // violation
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens3.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens3.java
new file mode 100644
index 00000000000..43319803939
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens3.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_NATIVE
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Using ''native'' is not allowed.
+tokens = LITERAL_NATIVE
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens3
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i)
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod(); // violation
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens4.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens4.java
new file mode 100644
index 00000000000..bda74e6d858
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens4.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_DEFAULT
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = 2
+maximumNumber = (default)2147483647
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = LITERAL_SWITCH
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens4
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i) // violation
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod();
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens5.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens5.java
new file mode 100644
index 00000000000..a44fd3edeb0
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens5.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_DEFAULT
+minimumDepth = 3
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = LITERAL_SWITCH
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens5 // ok
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i)
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod();
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens6.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens6.java
new file mode 100644
index 00000000000..20239e09334
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens6.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_DEFAULT
+minimumDepth = (default)0
+maximumDepth = 1
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = LITERAL_SWITCH
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens6 // ok
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i)
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod();
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens7.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens7.java
new file mode 100644
index 00000000000..4bae489043c
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens7.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_SWITCH, POST_INC, POST_DEC
+minimumDepth = (default)0
+maximumDepth = 0
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Using ''{2}'' is not allowed.
+tokens = LITERAL_SWITCH, POST_INC, POST_DEC
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens7
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i) // violation
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod();
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens8.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens8.java
new file mode 100644
index 00000000000..dd355ce4535
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenIllegalTokens8.java
@@ -0,0 +1,33 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_NATIVE
+minimumDepth = (default)0
+maximumDepth = 0
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Using ''{2}'' is not allowed.
+tokens = LITERAL_NATIVE
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenIllegalTokens8
+{
+ public void methodWithPreviouslyIllegalTokens()
+ {
+ int i = 0;
+ switch (i)
+ {
+ default:
+ i--;
+ i++;
+ break;
+ }
+ }
+
+ public native void nativeMethod(); // violation
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType.java
index 88a850ad18c..04ee96c9ac4 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType.java
@@ -1,6 +1,21 @@
+/*
+DescendantToken
+limitedTokens = LCURLY, RCURLY
+minimumDepth = (default)0
+maximumDepth = 2
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = OBJBLOCK
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
/**
* Created by valeria on 8/19/17.
*/
-public class InputDescendantTokenLastTokenType {}
+public class InputDescendantTokenLastTokenType {} // violation
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType2.java
new file mode 100644
index 00000000000..38971e74b23
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenLastTokenType2.java
@@ -0,0 +1,21 @@
+/*
+DescendantToken
+limitedTokens = RCURLY, LCURLY
+minimumDepth = (default)0
+maximumDepth = 2
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = OBJBLOCK
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+/**
+ * Created by valeria on 8/19/17.
+ */
+public class InputDescendantTokenLastTokenType2 {} // violation
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenMissingSwitchDefault.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenMissingSwitchDefault.java
index 1f977b1de3a..d97f368f734 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenMissingSwitchDefault.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenMissingSwitchDefault.java
@@ -1,3 +1,18 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_DEFAULT
+minimumDepth = (default)0
+maximumDepth = 2
+minimumNumber = 1
+maximumNumber = (default)2147483647
+sumTokenCounts = (default)false
+minimumMessage = switch without "default" clause.
+maximumMessage = (default)null
+tokens = LITERAL_SWITCH
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
public class InputDescendantTokenMissingSwitchDefault {
@@ -14,7 +29,7 @@ public void foo() {
class bad_test {
public void foo() {
int i = 1;
- switch (i) {
+ switch (i) { // violation
case 1: i++; break;
case 2: i--; break;
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromCatch.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromCatch.java
index 8cf1f90a9d3..d8234e3a1cb 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromCatch.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromCatch.java
@@ -1,10 +1,25 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_RETURN
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Return from catch is not allowed.
+tokens = LITERAL_CATCH
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
public class InputDescendantTokenReturnFromCatch {
public void foo() {
try {
System.currentTimeMillis();
- } catch (Exception e) {
+ } catch (Exception e) { // violation
return;
}
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally.java
index 33f3be43367..3df76b50e18 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally.java
@@ -1,10 +1,25 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_RETURN
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Return from finally is not allowed.
+tokens = LITERAL_FINALLY
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
public class InputDescendantTokenReturnFromFinally {
public void foo() {
try {
System.currentTimeMillis();
- } finally {
+ } finally { // violation
return;
}
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally2.java
new file mode 100644
index 00000000000..e17cee9164b
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally2.java
@@ -0,0 +1,42 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_THIS, LITERAL_NULL
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = (default)0
+maximumNumber = 1
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = What are you doing?
+tokens = NOT_EQUAL, EQUAL
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenReturnFromFinally2 { // ok
+ public void foo() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ return;
+ }
+ }
+
+ public void bar() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ if (System.currentTimeMillis() == 0) {
+ return; // return from if statement
+ }
+ }
+ }
+ public void thisNull() {
+ boolean result = (this == null) || (null == this);
+ boolean result2 = (this != null) && (null != this);
+ boolean result3 = (this.getClass().getName()
+ == String.valueOf(null == System.getProperty("abc")));
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally3.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally3.java
new file mode 100644
index 00000000000..a8384f9b878
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally3.java
@@ -0,0 +1,42 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_THIS, LITERAL_NULL
+minimumDepth = (default)0
+maximumDepth = 1
+minimumNumber = (default)0
+maximumNumber = 1
+sumTokenCounts = true
+minimumMessage = this cannot be null.
+maximumMessage = (default)null
+tokens = NOT_EQUAL, EQUAL
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenReturnFromFinally3 {
+ public void foo() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ return;
+ }
+ }
+
+ public void bar() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ if (System.currentTimeMillis() == 0) {
+ return; // return from if statement
+ }
+ }
+ }
+ public void thisNull() {
+ boolean result = (this == null) || (null == this); // violation
+ boolean result2 = (this != null) && (null != this);
+ boolean result3 = (this.getClass().getName()
+ == String.valueOf(null == System.getProperty("abc")));
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally4.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally4.java
new file mode 100644
index 00000000000..1fbd2ed55fe
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally4.java
@@ -0,0 +1,42 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_THIS, LITERAL_NULL
+minimumDepth = (default)0
+maximumDepth = 1
+minimumNumber = (default)0
+maximumNumber = 1
+sumTokenCounts = true
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = NOT_EQUAL, EQUAL
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenReturnFromFinally4 {
+ public void foo() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ return;
+ }
+ }
+
+ public void bar() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ if (System.currentTimeMillis() == 0) {
+ return; // return from if statement
+ }
+ }
+ }
+ public void thisNull() {
+ boolean result = (this == null) || (null == this); // violation
+ boolean result2 = (this != null) && (null != this);
+ boolean result3 = (this.getClass().getName()
+ == String.valueOf(null == System.getProperty("abc")));
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally5.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally5.java
new file mode 100644
index 00000000000..552684fbc3d
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally5.java
@@ -0,0 +1,42 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_THIS, LITERAL_NULL
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = 3
+maximumNumber = (default)2147483647
+sumTokenCounts = true
+minimumMessage = (default)null
+maximumMessage = (default)null
+tokens = NOT_EQUAL, EQUAL
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenReturnFromFinally5 {
+ public void foo() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ return;
+ }
+ }
+
+ public void bar() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ if (System.currentTimeMillis() == 0) { // violation
+ return; // return from if statement
+ }
+ }
+ }
+ public void thisNull() {
+ boolean result = (this == null) || (null == this);
+ boolean result2 = (this != null) && (null != this);
+ boolean result3 = (this.getClass().getName()
+ == String.valueOf(null == System.getProperty("abc")));
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally6.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally6.java
new file mode 100644
index 00000000000..df39067c934
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenReturnFromFinally6.java
@@ -0,0 +1,42 @@
+/*
+DescendantToken
+limitedTokens = LITERAL_THIS, LITERAL_NULL
+minimumDepth = (default)0
+maximumDepth = (default)2147483647
+minimumNumber = 3
+maximumNumber = (default)2147483647
+sumTokenCounts = true
+minimumMessage = custom message
+maximumMessage = (default)null
+tokens = NOT_EQUAL, EQUAL
+
+
+*/
+
+package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
+
+public class InputDescendantTokenReturnFromFinally6 {
+ public void foo() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ return;
+ }
+ }
+
+ public void bar() {
+ try {
+ System.currentTimeMillis();
+ } finally {
+ if (System.currentTimeMillis() == 0) { // violation
+ return; // return from if statement
+ }
+ }
+ }
+ public void thisNull() {
+ boolean result = (this == null) || (null == this);
+ boolean result2 = (this != null) && (null != this);
+ boolean result3 = (this.getClass().getName()
+ == String.valueOf(null == System.getProperty("abc")));
+ }
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
index 187a810e883..a6a419a96dd 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/descendanttoken/InputDescendantTokenStringLiteralEquality.java
@@ -1,10 +1,25 @@
+/*
+DescendantToken
+limitedTokens = STRING_LITERAL
+minimumDepth = (default)0
+maximumDepth = 1
+minimumNumber = (default)0
+maximumNumber = 0
+sumTokenCounts = (default)false
+minimumMessage = (default)null
+maximumMessage = Literal Strings should be compared using equals(), not ''==''.
+tokens = EQUAL, NOT_EQUAL
+
+
+*/
+
package com.puppycrawl.tools.checkstyle.checks.descendanttoken;
public class InputDescendantTokenStringLiteralEquality
{
void foo(String name)
{
- if (name == "Lars")
+ if (name == "Lars") // violation
{
// flagged, should use equals
}