aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorVladislav Lisetskiy <vladlis54@gmail.com>2016-04-26 23:41:31 +0300
committerRoman Ivanov <ivanov-jr@mail.ru>2016-05-30 06:08:21 -0700
commite5c8a2a88433c9439b2cd17a60de6913a45ae0b6 (patch)
treedb337285b423d45823d62981f8e80bd910c040a6 /src/test
parent2438c5aca23721cc51bfcec7c4f7a555a6957df7 (diff)
downloadcheckstyle-e5c8a2a88433c9439b2cd17a60de6913a45ae0b6.tar.gz
Issue #3126: Fix a lot of CommentsIndentationCheck false-positives and false-negatives
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java44
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationCommentIsAtTheEndOfBlock.java157
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInEmptyBlock.java5
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInSwitchBlock.java39
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationJavadoc.java21
-rw-r--r--src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationSurroundingCode.java16
6 files changed, 276 insertions, 6 deletions
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java
index 449c2092a..3d4d4e630 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/indentation/CommentsIndentationCheckTest.java
@@ -37,7 +37,7 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
/**
*
* @author <a href="mailto:nesterenko-aleksey@list.ru">Aleksey Nesterenko</a>
-* @author <a href="mailto:andreyselkin@gmail.com">Aleksey Nesterenko</a>
+* @author <a href="mailto:andreyselkin@gmail.com">Andrei Selkin</a>
*
*/
public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
@@ -57,7 +57,7 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
"33: " + getCheckMessage(MSG_KEY_SINGLE, 35, 5, 4),
"37: " + getCheckMessage(MSG_KEY_SINGLE, 36, 0, 8),
"47: " + getCheckMessage(MSG_KEY_SINGLE, 46, 15, 12),
- "49: " + getCheckMessage(MSG_KEY_SINGLE, 48, 10, 8),
+ "49: " + getCheckMessage(MSG_KEY_SINGLE, 45, 10, 8),
"54: " + getCheckMessage(MSG_KEY_SINGLE, 53, 13, 8),
"74: " + getCheckMessage(MSG_KEY_SINGLE, 70, 18, 8),
"88: " + getCheckMessage(MSG_KEY_SINGLE, 85, 31, 8),
@@ -78,11 +78,24 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
"277: " + getCheckMessage(MSG_KEY_SINGLE, 276, 9, 8),
"316: " + getCheckMessage(MSG_KEY_SINGLE, 315, 9, 8),
"322: " + getCheckMessage(MSG_KEY_SINGLE, 323, 0, 4),
- "336: " + getCheckMessage(MSG_KEY_SINGLE, 337, 0, 4),
+ "336: " + getCheckMessage(MSG_KEY_SINGLE, 333, 0, 8),
"355: " + getCheckMessage(MSG_KEY_SINGLE, 352, 9, 8),
"380: " + getCheckMessage(MSG_KEY_BLOCK, 381, 12, 8),
"393: " + getCheckMessage(MSG_KEY_SINGLE, 392, 12, 8),
"400: " + getCheckMessage(MSG_KEY_SINGLE, 401, 8, 10),
+ "457: " + getCheckMessage(MSG_KEY_SINGLE, 455, 0, 8),
+ "473: " + getCheckMessage(MSG_KEY_BLOCK, 469, 10, 8),
+ "483: " + getCheckMessage(MSG_KEY_BLOCK, 477, 10, 8),
+ "491: " + getCheckMessage(MSG_KEY_BLOCK, 487, 10, 8),
+ "499: " + getCheckMessage(MSG_KEY_BLOCK, 495, 10, 8),
+ "507: " + getCheckMessage(MSG_KEY_BLOCK, 503, 10, 8),
+ "518: " + getCheckMessage(MSG_KEY_SINGLE, 511, 10, 8),
+ "525: " + getCheckMessage(MSG_KEY_SINGLE, 522, 0, 8),
+ "532: " + getCheckMessage(MSG_KEY_SINGLE, 529, 0, 8),
+ "538: " + getCheckMessage(MSG_KEY_SINGLE, 536, 0, 8),
+ "546: " + getCheckMessage(MSG_KEY_SINGLE, 542, 4, 8),
+ "551: " + getCheckMessage(MSG_KEY_SINGLE, 550, 12, 8),
+ "557: " + getCheckMessage(MSG_KEY_SINGLE, 555, 0, 8),
};
final String testInputFile = "InputCommentsIndentationCommentIsAtTheEndOfBlock.java";
verify(checkConfig, getPath(testInputFile), expected);
@@ -93,6 +106,7 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
final DefaultConfiguration checkConfig =
createCheckConfig(CommentsIndentationCheck.class);
final String[] expected = {
+ "19: " + getCheckMessage(MSG_KEY_BLOCK, 20, 12, 16),
"25: " + getCheckMessage(MSG_KEY_SINGLE, "24, 26", 19, "16, 12"),
"31: " + getCheckMessage(MSG_KEY_SINGLE, "30, 32", 19, "16, 12"),
"48: " + getCheckMessage(MSG_KEY_SINGLE, 49, 6, 16),
@@ -109,6 +123,8 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
"204: " + getCheckMessage(MSG_KEY_SINGLE, 205, 20, 17),
"205: " + getCheckMessage(MSG_KEY_SINGLE, "202, 206", 17, "16, 12"),
"229: " + getCheckMessage(MSG_KEY_SINGLE, "228, 230", 6, "12, 12"),
+ "276: " + getCheckMessage(MSG_KEY_BLOCK, "275, 279", 11, "16, 12"),
+ "281: " + getCheckMessage(MSG_KEY_SINGLE, "280, 282", 11, "16, 12"),
};
final String testInputFile = "InputCommentsIndentationInSwitchBlock.java";
verify(checkConfig, getPath(testInputFile), expected);
@@ -143,6 +159,9 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
"90: " + getCheckMessage(MSG_KEY_SINGLE, 91, 14, 8),
"98: " + getCheckMessage(MSG_KEY_SINGLE, 99, 13, 8),
"108: " + getCheckMessage(MSG_KEY_SINGLE, 109, 33, 8),
+ "130: " + getCheckMessage(MSG_KEY_BLOCK, 131, 12, 8),
+ "135: " + getCheckMessage(MSG_KEY_BLOCK, 136, 4, 8),
+ "141: " + getCheckMessage(MSG_KEY_BLOCK, 140, 4, 8),
};
final String testInputFile = "InputCommentsIndentationSurroundingCode.java";
verify(checkConfig, getPath(testInputFile), expected);
@@ -183,7 +202,10 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
"25: " + getCheckMessage(MSG_KEY_BLOCK, 27, 16, 12),
"28: " + getCheckMessage(MSG_KEY_BLOCK, 31, 16, 12),
"51: " + getCheckMessage(MSG_KEY_BLOCK, 53, 23, 36),
- };
+ "130: " + getCheckMessage(MSG_KEY_BLOCK, 131, 12, 8),
+ "135: " + getCheckMessage(MSG_KEY_BLOCK, 136, 4, 8),
+ "141: " + getCheckMessage(MSG_KEY_BLOCK, 140, 4, 8),
+ };
final String testInputFile = "InputCommentsIndentationSurroundingCode.java";
verify(checkConfig, getPath(testInputFile), expected);
}
@@ -203,4 +225,18 @@ public class CommentsIndentationCheckTest extends BaseCheckTestSupport {
Assert.assertEquals("Unexpected token type: methodStub", msg);
}
}
+
+ @Test
+ public void testJavadoc() throws Exception {
+ final DefaultConfiguration checkConfig = createCheckConfig(CommentsIndentationCheck.class);
+ final String[] expected = {
+ "3: " + getCheckMessage(MSG_KEY_BLOCK, 6, 2, 0),
+ "8: " + getCheckMessage(MSG_KEY_BLOCK, 9, 0, 4),
+ "11: " + getCheckMessage(MSG_KEY_BLOCK, 14, 8, 4),
+ "17: " + getCheckMessage(MSG_KEY_BLOCK, 18, 10, 8),
+ };
+ final String testInputFile = "InputCommentsIndentationJavadoc.java";
+ verify(checkConfig, getPath(testInputFile), expected);
+ }
+
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationCommentIsAtTheEndOfBlock.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationCommentIsAtTheEndOfBlock.java
index 1e769770f..170123220 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationCommentIsAtTheEndOfBlock.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationCommentIsAtTheEndOfBlock.java
@@ -397,11 +397,166 @@ public class InputCommentsIndentationCommentIsAtTheEndOfBlock {
/*
comment
*/
- // comment
+ // violation
foo1();
// comment
}
+ void foo59() {
+ foo1();
+ /*
+ comment */
+ // comment
+ }
+
+
+ void foo61() {
+ foo1();
+ /*
+ * comment
+ */
+ /*
+ * comment
+ */
+ }
+
+ void foo62() {
+ if (true) {
+ System.out.println();
+ }
+ else {
+
+ }
+ /*
+ comment
+ */
+ /*
+ comment
+ */
+ }
+
+ void foo63() {
+ try {
+ System.out.println();
+ }
+ catch (Exception e){
+
+ }
+
+ /*
+ comment
+ */
+ /*
+ comment
+ */
+ }
+
+ void foo64() {
+ foo1();
+
+// violation
+ }
+
+ void foo65() {
+ int i = 1
+ + 1
+ + 1;
+ // comment
+ // comment
+ }
+
+ void foo66() {
+ if (true) {
+ getClass();
+ }
+
+ /* violation */
+ }
+
+ void foo67() {
+ try {
+ getClass();
+ } finally {
+ hashCode();
+ }
+
+ /* violation */
+ }
+
+ void foo68() {
+ for (int i = 0; i < 0; i++) {
+ getClass();
+ }
+
+ /* violation */
+ }
+
+ void foo69() {
+ while (true) {
+ getClass();
+ }
+
+ /* violation */
+ }
+
+ void foo70() {
+ do {
+ getClass();
+ } while (true);
+
+ /* violation */
+ }
+
+ void foo71() {
+ switch("") {
+ case "!":
+ break;
+ default:
+ break;
+ }
+
+ // violation
+ }
+
+ void foo72() {
+ int u = 1;
+
+/* comment */
+// violation
+ }
+
+ void foo73() {
+ class Foo { }
+
+/* comment */
+// violation
+ }
+
+ interface Bar1 {
+ interface NestedBar { }
+
+// violation
+ }
+
+ static class Bar2 {
+ enum Foo {
+ A;
+ }
+
+ // violation
+ }
+
+ static class Bar3 {
+ @interface Foo { }
+ // violation
+ }
+
+ void foo74() {
+ getClass(); // comment
+// comment
+// comment
+ }
+
// We almost reached the end of the class here.
}
// The END of the class.
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInEmptyBlock.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInEmptyBlock.java
index d032fa8cf..68c5f55c8 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInEmptyBlock.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInEmptyBlock.java
@@ -83,4 +83,9 @@ public class InputCommentsIndentationInEmptyBlock {
private static class MyClass extends Object {
// no members
}
+
+ private static class MyClass1 extends Object {
+
+ // no members
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInSwitchBlock.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInSwitchBlock.java
index 69c419cfd..000a4ee8b 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInSwitchBlock.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationInSwitchBlock.java
@@ -16,7 +16,7 @@ public class InputCommentsIndentationInSwitchBlock {
// comment
break;
case "3":
- /* com */
+ /* violation */
foo1();
/* com */
break;
@@ -265,4 +265,41 @@ public class InputCommentsIndentationInSwitchBlock {
case 1:
}
}
+
+ public void foo13() {
+ int a = 5;
+ switch (a) {
+ case 1:
+ /* comment */
+ case 2:
+ hashCode();
+ /*
+ violation
+ */
+ case 3: // comment
+ hashCode();
+ // violation
+ case 4: // comment
+ if (true) {
+
+ }
+ else {
+
+ }
+ // comment
+ case 5:
+ String s = ""
+ + 1
+ + "123";
+ break;
+ // comment
+ case 6:
+ String q = ""
+ + 1
+ + "123";
+ // comment
+ case 7:
+ break;
+ }
+ }
}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationJavadoc.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationJavadoc.java
new file mode 100644
index 000000000..de2e7a76b
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationJavadoc.java
@@ -0,0 +1,21 @@
+package com.puppycrawl.tools.checkstyle.checks.indentation;
+
+ /**
+ * violation
+ */
+public class InputCommentsIndentationJavadoc {
+
+/** violation */
+ int i;
+
+ /**
+ * violation
+ */
+ void foo() {}
+
+ enum Bar {
+ /** violation */
+ A;
+ }
+
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationSurroundingCode.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationSurroundingCode.java
index 0a13df6e7..3040dc93b 100644
--- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationSurroundingCode.java
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/InputCommentsIndentationSurroundingCode.java
@@ -125,5 +125,21 @@ public class InputCommentsIndentationSurroundingCode
};
}
+ public void foo11() {
+
+ /* empty */
+ hashCode();
+ }
+
+ public void foo12() {
+ /* empty */
+ hashCode();
+ }
+
+ public void foo13() {
+ hashCode();
+ /* empty */
+ }
+
} // The Check should not throw NPE here!
// The Check should not throw NPE here!