diff options
author | Andrei Selkin <andreyselkin@gmail.com> | 2015-10-31 14:57:50 +0300 |
---|---|---|
committer | Roman Ivanov <ivanov-jr@mail.ru> | 2015-10-31 15:48:32 -0700 |
commit | e21676f52f3d68294122244cea63b4ecbe92de8f (patch) | |
tree | 2fff2e63ae6130c8c18acaf7d31864eb9504f4ab /src/it | |
parent | 866daeeb2ad31e6a5a78235aa46819d9f966ee1c (diff) | |
download | checkstyle-e21676f52f3d68294122244cea63b4ecbe92de8f.tar.gz |
Issue #2078: Update ITs for CommentsIndentationCheck
Diffstat (limited to 'src/it')
6 files changed, 1004 insertions, 150 deletions
diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationTest.java index 2ab5082a9..7600d3f1d 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationTest.java @@ -39,27 +39,166 @@ public class CommentsIndentationTest extends BaseCheckTestSupport { } @Test - public void commentsIndentationTest() throws Exception { + public void testCommentIsAtTheEndOfBlock() throws Exception { + final String[] expected = { + "18: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 17, 25, 8), + "33: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 35, 5, 4), + "37: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 36, 0, 8), + "47: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 46, 15, 12), + "49: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 48, 10, 8), + "54: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 53, 13, 8), + "74: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 70, 18, 8), + "88: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 85, 31, 8), + "100: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 98, 21, 8), + "115: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 116, 29, 12), + "138: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 131, 26, 8), + "164: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 161, 33, 8), + "174: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 173, 21, 8), + "186: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 184, 34, 8), + "208: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 206, 26, 8), + "214: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 213, 0, 8), + "228: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 225, 12, 8), + "234: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 233, 0, 8), + "248: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 245, 12, 8), + "255: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 252, 0, 8), + "265: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 264, 14, 8), + "271: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 269, 9, 8), + "277: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 276, 9, 8), + "316: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 315, 9, 8), + "322: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 323, 0, 4), + "336: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 337, 0, 4), + "355: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 352, 9, 8), + }; + + final Configuration checkConfig = builder.getCheckConfig("CommentsIndentation"); + final String filePath = + builder.getFilePath("CommentsIndentationCommentIsAtTheEndOfBlockInput"); + + final Integer[] warnList = builder.getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } + + @Test + public void testCommentIsInsideSwitchBlock() throws Exception { + final String[] expected = { + "25: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "24, 26", 19, "16, 12"), + "31: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "30, 32", 19, "16, 12"), + "48: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 49, 6, 16), + "55: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 56, 8, 12), + "59: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 58, 22, 16), + "68: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "65, 69", 14, "12, 16"), + "88: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 89, 24, 20), + "113: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "112, 114", 15, "17, 12"), + "125: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 126, 8, 12), + "138: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 139, 4, 8), + "157: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "156, 158", 18, "16, 12"), + "200: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "199, 201", 4, "12, 12"), + "203: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 204, 22, 20), + "204: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 205, 20, 17), + "205: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "202, 206", 17, "16, 12"), + "229: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + "228, 230", 6, "12, 12"), + }; + + final Configuration checkConfig = builder.getCheckConfig("CommentsIndentation"); + final String filePath = + builder.getFilePath("CommentsIndentationInSwitchBlockInput"); + + final Integer[] warnList = builder.getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } + @Test + public void testCommentIsInsideEmptyBlock() throws Exception { + final String[] expected = { + "9: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 10, 19, 23), + "10: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.block", + 12, 23, 31), + "33: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 34, 0, 8), + "57: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 58, 0, 8), + "71: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 72, 0, 8), + }; + + final Configuration checkConfig = builder.getCheckConfig("CommentsIndentation"); + final String filePath = + builder.getFilePath("CommentsIndentationInEmptyBlockInput"); + + final Integer[] warnList = builder.getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } + + @Test + public void testSurroundingCode() throws Exception { final String[] expected = { - "1: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.single", 2, 1, 0), - "13: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.single", 14, 8, 6), - "23: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.block", 24, 8, 4), - "25: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.block", 27, 8, 4), - "28: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.block", 31, 8, 4), - "50: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.single", 51, 23, 19), - "51: " + getCheckMessage(CommentsIndentationCheck.class, - "comments.indentation.block", 53, 19, 32), - }; + "13: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 14, 14, 12), + "23: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.block", + 24, 16, 12), + "25: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.block", + 27, 16, 12), + "28: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.block", + 31, 16, 12), + "50: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 51, 27, 23), + "51: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.block", + 53, 23, 36), + "90: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 91, 14, 8), + "98: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 99, 13, 8), + "108: " + getCheckMessage(CommentsIndentationCheck.class, "comments.indentation.single", + 109, 33, 8), + }; final Configuration checkConfig = builder.getCheckConfig("CommentsIndentation"); - final String filePath = builder.getFilePath("CommentsIndentationInput"); + final String filePath = + builder.getFilePath("CommentsIndentationSurroundingCodeInput"); final Integer[] warnList = builder.getLinesWithWarn(filePath); verify(checkConfig, filePath, expected, warnList); diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationCommentIsAtTheEndOfBlockInput.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationCommentIsAtTheEndOfBlockInput.java new file mode 100644 index 000000000..e184f3b82 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationCommentIsAtTheEndOfBlockInput.java @@ -0,0 +1,367 @@ +package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle; + +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.utils.CheckUtils; + +/** + * Contains examples of using comments at the end of the block. + */ +public class CommentsIndentationCommentIsAtTheEndOfBlockInput { + + public void foo1() { + foo2(); + // TODO: missing functionality + } + + public void foo2() { + foo3(); + // warn + } + + public void foo3() { + foo2(); + // refreshDisplay(); + } + + public void foo4() { + foooooooooooooooooooooooooooooooooooooooooo(); + // ^-- some hint + } + + public void foooooooooooooooooooooooooooooooooooooooooo() { } + + /////////////////////////////// warn (a single line border to separate a group of methods) + + public void foo7() { + int a = 0; +// warn + } + + /////////////////////////////// (a single line border to separate a group of methods) + + public void foo8() {} + + public class TestClass { + public void test() { + int a = 0; + // warn + } + // warn + } + + public void foo9() { + this.foo1(); + // warn + } + + // public void foo10() { + // + // } + + public void foo11() { + CheckUtils + .getFirstNode(new DetailAST()) + .getFirstChild() + .getNextSibling(); + // comment + } + + public void foo12() { + CheckUtils + .getFirstNode(new DetailAST()) + .getFirstChild() + .getNextSibling(); + // warn + } + + public void foo13() { + CheckUtils.getFirstNode(new DetailAST()) + .getFirstChild() + .getNextSibling(); + // comment + } + + public void foo14() { + CheckUtils.getFirstNode(new DetailAST()) + .getFirstChild() + .getNextSibling(); + // warn + } + + public void foo15() { + CheckUtils + .getFirstNode(new DetailAST()); + // comment + } + + public void foo16() { + CheckUtils + .getFirstNode(new DetailAST()); + // warn + } + + public void foo17() { + CheckUtils + .getFirstNode(new DetailAST()) + .getFirstChild() + // comment + .getNextSibling(); + } + + public void foo18() { + CheckUtils + .getFirstNode(new DetailAST()) + .getFirstChild() + // warn + .getNextSibling(); + } + + public void foo19() { + (new Thread(new Runnable() { + @Override + public void run() { + + } + })). + run(); + // comment + } + + public void foo20() { + (new Thread(new Runnable() { + @Override + public void run() { + + } + })). + run(); + // warn + } + + public void foo21() { + int[] array = new int[5]; + + java.util.List<String> expected = new java.util.ArrayList<>(); + for (int i = 0; i < 5; i++) { + org.junit.Assert.assertEquals(expected.get(i), array[i]); + } + String s = String.format("The array element " + + "immediately following the end of the collection should be nulled", + array[1]); + // the above example was taken from hibernate-orm and was modified a bit + } + + public void foo22() { + int[] array = new int[5]; + + java.util.List<String> expected = new java.util.ArrayList<>(); + for (int i = 0; i < 5; i++) { + org.junit.Assert.assertEquals(expected.get(i), array[i]); + } + String s = String.format("The array element " + + "immediately following the end of the collection should be nulled", + array[1]); + // warn + } + + public void foo23() { + new Object(); + // comment + } + + public void foo24() { + new Object(); + // warn + } + + public String foo25() { + return String.format("%d", + 1); + // comment + } + + public String foo26() { + return String.format("%d", + 1); + // warn + } + + public void foo27() { + // comment + // block + foo17(); + + // TODO + } + + public String foo28() { + int a = 5; + return String.format("%d", + 1); + // comment + } + + public String foo29() { + int a = 5; + return String.format("%d", + 1); + // warn + } + + public void foo30() { + // comment + int a = 5; +// warn + } + + public void foo31() { + String s = new String ("A" + + "B" + + "C"); + // comment + } + + public void foo32() { + String s = new String ("A" + + "B" + + "C"); + // warn + } + + public void foo33() { + // comment + this.foo22(); +// warn + } + + public void foo34() throws Exception { + throw new Exception("", + new Exception() + ); + // comment + } + + public void foo35() throws Exception { + throw new Exception("", + new Exception() + ); + // warn + } + + public void foo36() throws Exception { + throw new Exception("", + new Exception() + ); +// warn + } + + public void foo37() throws Exception { + throw new Exception("", new Exception()); + // comment + } + + public void foo38() throws Exception { + throw new Exception("", new Exception()); + // warn + } + + public void foo39() throws Exception { + throw new Exception("", + new Exception()); + // warn + } + + public void foo40() throws Exception { + int a = 88; + throw new Exception("", new Exception()); + // warn + } + + public void foo41() throws Exception { + int a = 88; + throw new Exception("", new Exception()); + // comment + } + + public void foo42() { + int a = 5; + if (a == 5) { + int b; + // comment + } else if (a ==6) { + + } + } + + public void foo43() { + try { + int a; + // comment + } catch (Exception e) { + + } + } + + public void foo44() { + int ar = 5; + // comment + ar = 6; + // comment + } + + public void foo45() { + int ar = 5; + // comment + ar = 6; + // warn + } + + public void foo46() { +// comment +// block +// warn + } + + public void foo47() { + int a = 5; + // comment + // block + // comment + } + + public void foo48() { + int a = 5; +// comment +// block +// warn + } + + public void foo49() { + // comment + // block + // ok + } + + public void foo50() { + return; + + // No NPE here! + } + + public String foo51() { + return String + .valueOf("11" + ); + // warn + } + + public String foo52() { + return String + .valueOf("11" + ); + // comment + } + + // We almost reached the end of the class here. +} +// The END of the class. diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInEmptyBlockInput.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInEmptyBlockInput.java new file mode 100644 index 000000000..0706d7d3b --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInEmptyBlockInput.java @@ -0,0 +1,86 @@ +package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle; + +public class CommentsIndentationInEmptyBlockInput { + + private void foo1() { + int a = 5, b = 3, v = 6; + if (a == b + && v == b || ( a ==1 + /// // warn + /* // warn + * one fine day ... */ + && b == 1) ) { + // Cannot clearly detect user intention of explanation target. + } + } + + private void foo2() { + int a = 5, b = 3, v = 6; + if (a == b + && v == b || ( a ==1 + && b == 1) ) { + + + // comment + } + } + + private void foo3() { + int a = 5, b = 3, v = 6; + if (a == b + && v == b || (a == 1 + && b == 1)) { +// warn + } + } + + // Comments here should be ok by Check + @SuppressWarnings("unused") // trailing + private static void foo4() { // trailing + if (true) // trailing comment + { + // some comment + } + if (true) { // trailing comment + + } + /** + * + */ + } + + // Comments here should be ok by Check + @SuppressWarnings("unused") // trailing + private static void foo5() { // trailing + if (true) // trailing comment + { +// warn + } + if (true) { // trailing comment + + } + /** + * + */ + } + + public void foo6() { + try { + + } catch (Exception e) { +// warn + } + } + + public void foo7() { + try { + + } catch (Exception e) { + // TODO: handle exception here + } + } + + private static class MyClass extends Object { + // no members + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInSwitchBlockInput.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInSwitchBlockInput.java new file mode 100644 index 000000000..ee9d6673d --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInSwitchBlockInput.java @@ -0,0 +1,268 @@ +package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle; + +public class CommentsIndentationInSwitchBlockInput { + + private static void fooSwitch() { + switch("") { + case "0": //some comment + case "1": + // my comment + foo1(); + break; + case "2": + // my comment + //comment + foo1(); + // comment + break; + case "3": + /* com */ + foo1(); + /* com */ + break; + case "5": + foo1(); + // warn + case "6": + int k = 7; + // fall through + case "7": + if (true) {} + // warn + case "8": + break; + case "9": + foo1(); + // fall through + case "10": { + if (true) {} + // fall through + } + case "11": { + // fall through + } + case "28": { + // fall through + } + case "12": { + // warn + int i; + } + case "13": { + // some comment in empty case block + } + case "14": { + // warn + } + case "15": { + foo1(); + // warn + } + case "16": { + int a; + } + // fall through + case "17": { + int a; + } + // warn + case "18": { System.out.println(); + } // trailing comment + case "19": + // comment + case "20": + // comment + case "21": + default: + // comment + break; + } + } + + private static void foo1() { + if (true) { + switch(1) { + case 0: + + case 1: + // warn + int b = 10; + default: + // comment + } + + } + } + + public void fooDotInCaseBlock() { + int i = 0; + String s = ""; + + switch (i) { + case -2: + // what + i++; + // no break here + case 0: + // what + s.indexOf("ignore"); + // no break here + case -1: + // what + s.indexOf("no way"); + // warn + case 1: + case 2: + i--; + // no break here + case 3: { } + // fall through + + + } + + String breaks = "" + // warn + + "</table>" + // middle + + "" + // end + ; + } + + public void foo2() { + int a = 1; + switch (a) { + case 1: + default: + // warn + } + } + + public void foo3() { + int a = 1; + switch (a) { + case 1: + default: + + // comment + } + } + + public void foo4() { + int a = 1; + switch (a) { + case 1: + int b; + // warn + default: + } + } + + public void foo5() { + int a = 1; + switch (a) { + case 1: + int b; + // comment + default: + } + } + + public void foo6() { + int a = 1; + switch (a) { + case 1: + int b; + // comment + default: + } + } + + public void foo7() { + int a = 2; + String s = ""; + switch (a) { + // comment + // comment + // comment + case 1: + case 2: + // comment + // comment + foo1(); + // comment + case 3: + // comment + // comment + // comment + case 4: + // warn + case 5: + s.toString().toString().toString(); + // warn + // warn + // warn + default: + } + } + + public void foo8() { + int a = 2; + String s = ""; + switch (a) { + // comment + // comment + // comment + case 1: + case 2: + // comment + // comment + foo1(); + // comment + case 3: + // comment + // comment + s.toString().toString().toString(); + // comment + case 4: + // warn + default: + } + } + + public void foo9() { + int a = 5; + switch (a) { + case 1: + case 2: + // comment + } + } + + public void foo10() { + int a = 5; + switch (a) { + case 1: + default: + // comment + } + } + + public void foo11() { + int a = 5; + switch (a) { + case 1: + case 2: + // comment + } + } + + public void foo12() { + int a = 5; + switch (a) { + // comment + case 1: + } + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInput.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInput.java deleted file mode 100644 index 5bb52290a..000000000 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationInput.java +++ /dev/null @@ -1,133 +0,0 @@ - // warn (some comment) -package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle; - -import java.util.*; - -// ok (comment) -public class CommentsIndentationInput { - - private void foo() { - if (true) { - // ok (here initialize some variables) - int k = 0; // ok (trailing comment) - // warn (initialize b) - int b = 10; - // ok (sss) - } - } - - private void foo1() { - if (true) { - /* ok (some) */ - int k = 0; - /* // warn (some) */ - int b = 10; - /* // warn - * */ - double d; /* ok (trailing comment) */ - /* // warn - * - */ - boolean bb; - /***/ - /* ok (my comment) */ - /* - * - * - * ok (some) - */ - /* - * ok (comment) - */ - boolean x; - } - } - - private void foo3() { - int a = 5, b = 3, v = 6; - if (a == b - && v == b || (a == 1 - /// warn (What about that case ? the same for block comments) - /* // warn - * one fine day ... */ - && b == 1)) { - // ok (code) - } - } - - // ok (Comments here should be ok by Check) - @SuppressWarnings("unused") // ok (trailing) - private static void check() { // ok (trailing) - if (true) // ok (trailing comment) - { - // ok (some comment) - } - if (true) { // ok (trailing comment) - - } - /** ok - * - */ - } - - private static void com() { - /* ok (here's my weird trailing comment) */ - boolean b = true; - } - - - private static void cases() { - switch ("") { - case "0": // some comment - case "1": - // my comment - com(); - break; - case "2": - // my comment - //comment - check(); - // comment - break; - case "3": - /* com */ - check(); - /* com */ - break; - case "5": - check(); - // fall through - case "6": - int k = 7; - // fall through - case "7": - if (true) {} - // fall through - case "8": - break; - default: - // comment - break; - } - } - - private static final String[][] mergeMatrix = { - // TOP ALWAYS NEVER UNKNOWN - /* TOP */{ "", }, - /* ALWAYS */{ "", "", }, - /* NEVER */{ "NEVER", "UNKNOWN", "NEVER", }, - /* UNKNOWN */{ "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN" }, }; - - private void foo4() { - if (!Arrays.equals(new String[]{""}, new String[]{""}) - /* wierd trailing comment */) { - } - } - - /** - * ok (some javadoc) - */ - private static void l() { - } -} // The Check should not throw NPE here! -/* The Check should not throw NPE here! */ diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationSurroundingCodeInput.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationSurroundingCodeInput.java new file mode 100644 index 000000000..cc5525d9e --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4861blockcommentstyle/CommentsIndentationSurroundingCodeInput.java @@ -0,0 +1,127 @@ +// comment +package com.google.checkstyle.test.chapter4formatting.rule4861blockcommentstyle; + +import java.util.Arrays; + +// some +public class CommentsIndentationSurroundingCodeInput +{ + private void foo1() { + if (true) { + // here initialize some variables + int k = 0; // trailing comment + // warn + int b = 10; + // sss + } + } + + private void foo2() { + if (true) { + /* some */ + int k = 0; + /* // warn */ + int b = 10; + /* // warn + * */ + double d; /* trailing comment */ + /* // warn + * + */ + boolean bb; + /***/ + /* my comment*/ + /* + * + * + * some + */ + /* + * comment + */ + boolean x; + } + } + + private void foo3() { + int a = 5, b = 3, v = 6; + if (a == b + && v == b || ( a ==1 + /// // warn + /* // warn + * one fine day ... */ + && b == 1) ) { + } + } + + private static void com() { + /* here's my weird trailing comment */ boolean b = true; + } + + private static final String[][] mergeMatrix = { + // This example of trailing block comments was found in PMD sources. + /* TOP */{ "", }, + /* ALWAYS */{ "", "", }, + /* NEVER */{ "NEVER", "UNKNOWN", "NEVER", }, + /* UNKNOWN */{ "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN" }, }; + + private void foo4() { + if (!Arrays.equals(new String[]{""}, new String[]{""}) + /* wierd trailing comment */) { + } + } + /** + * some javadoc + */ + private static void l() { + } + + public void foid5() { + String s = ""; + s.toString().toString().toString(); + // comment + } + + public void foo6() { + // comment + // ... + // block + // ... + // warn + String someStr = new String(); + } + + public void foo7() { + // comment + // ... + // block + // warn + // comment + String someStr = new String(); + } + + public void foo8() { + String s = new String(); // comment + // ... + // block + // ... + // warn + String someStr = new String(); + } + + public String foo9(String s1, String s2, String s3) { + return ""; + } + + public void foo10() + throws Exception { + + final String pattern = "^foo$"; + + final String[] expected = { + "7:13: " + foo9("", "", ""), + // comment + }; + } +} // The Check should not throw NPE here! +// The Check should not throw NPE here! |