diff --git a/src/it/java/com/google/checkstyle/test/base/BaseCheckTestSupport.java b/src/it/java/com/google/checkstyle/test/base/BaseCheckTestSupport.java index 412ce36b56f..ff14bbc24ae 100644 --- a/src/it/java/com/google/checkstyle/test/base/BaseCheckTestSupport.java +++ b/src/it/java/com/google/checkstyle/test/base/BaseCheckTestSupport.java @@ -260,8 +260,7 @@ protected static Configuration getCheckConfig(String checkName) throws Checkstyl result = configs.get(0); } else { - result = configs.get(0); - //throw new IllegalStateException("multiple instances of the same Check is detected"); + throw new IllegalStateException("multiple instances of the same Check is detected"); } return result; } diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule412nonemptyblocks/RightCurlyTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule412nonemptyblocks/RightCurlyTest.java index 16b3d910957..f0dac8e4b71 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule412nonemptyblocks/RightCurlyTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule412nonemptyblocks/RightCurlyTest.java @@ -50,7 +50,7 @@ public void rightCurlyTestAlone() throws Exception { "79:27: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_BREAK_BEFORE, "}", 27), }; - final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault"); + final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame"); final String filePath = getPath("InputRightCurlyOther.java"); final Integer[] warnList = getLinesWithWarn(filePath); @@ -61,7 +61,7 @@ public void rightCurlyTestAlone() throws Exception { public void rightCurlyTestSame() throws Exception { final String[] expected = CommonUtils.EMPTY_STRING_ARRAY; - final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault"); + final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame"); final String filePath = getPath("InputRightCurlySame.java"); final Integer[] warnList = getLinesWithWarn(filePath); @@ -76,7 +76,7 @@ public void testRightCurlySameAndLiteralDoDefault() throws Exception { "83:9: " + getCheckMessage(RightCurlyCheck.class, MSG_KEY_LINE_SAME, "}", 9), }; - final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlyDefault"); + final Configuration checkConfig = getCheckConfig("RightCurly", "RightCurlySame"); final String filePath = getPath("InputRightCurlyDoWhile.java"); final Integer[] warnList = getLinesWithWarn(filePath); diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java index b82e401d132..1294efc341e 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/SeparatorWrapTest.java @@ -37,16 +37,30 @@ protected String getPath(String fileName) throws IOException { } @Test - public void separatorWrapTest() throws Exception { + public void separatorWrapDotTest() throws Exception { final String[] expected = { "28:30: " + getCheckMessage(SeparatorWrapCheck.class, "line.new", "."), }; - final Configuration checkConfig = getCheckConfig("SeparatorWrap"); + final Configuration checkConfig = getCheckConfig("SeparatorWrap", "SeparatorWrapDot"); final String filePath = getPath("InputSeparatorWrap.java"); final Integer[] warnList = getLinesWithWarn(filePath); verify(checkConfig, filePath, expected, warnList); } + + @Test + public void separatorWrapCommaTest() throws Exception { + + final String[] expected = { + "31:17: " + getCheckMessage(SeparatorWrapCheck.class, "line.previous", ","), + }; + + final Configuration checkConfig = getCheckConfig("SeparatorWrap", "SeparatorWrapComma"); + final String filePath = getPath("InputSeparatorWrapComma.java"); + + final Integer[] warnList = getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } } diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java index f7b2a7572db..4fcec4bd1c5 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule485annotations/AnnotationLocationTest.java @@ -41,7 +41,8 @@ public void annotationTest() throws Exception { final Class clazz = AnnotationLocationCheck.class; getCheckMessage(clazz, "annotation.location.alone"); - final Configuration checkConfig = getCheckConfig("AnnotationLocation"); + final Configuration checkConfig = getCheckConfig("AnnotationLocation", + "AnnotationLocationMostCases"); final String msgLocationAlone = "annotation.location.alone"; final String msgLocation = "annotation.location"; @@ -64,4 +65,24 @@ public void annotationTest() throws Exception { final Integer[] warnList = getLinesWithWarn(filePath); verify(checkConfig, filePath, expected, warnList); } + + @Test + public void annotationTestVariables() throws Exception { + + final Class clazz = AnnotationLocationCheck.class; + getCheckMessage(clazz, "annotation.location.alone"); + final Configuration checkConfig = getCheckConfig("AnnotationLocation", + "AnnotationLocationVariables"); + + final String msgLocationAlone = "annotation.location.alone"; + final String msgLocation = "annotation.location"; + final String[] expected = { + "63: " + getCheckMessage(clazz, msgLocation, "MyAnnotation2", "7", "4"), + }; + + final String filePath = getPath("InputAnnotationLocationVariables.java"); + + final Integer[] warnList = getLinesWithWarn(filePath); + verify(checkConfig, filePath, expected, warnList); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapComma.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapComma.java new file mode 100644 index 00000000000..3d6677a1986 --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule451wheretobreak/InputSeparatorWrapComma.java @@ -0,0 +1,45 @@ +package com.google.checkstyle.test.chapter4formatting.rule451wheretobreak; + +public class InputSeparatorWrapComma { + public void goodCase() + { + int i = 0; + String s = "ffffooooString"; + s + .isEmpty(); //ok + s.isEmpty(); + + foo(i, + s); //ok + } + public static void foo(int i, String s) + { + + } +} + +class badCaseComma { + + public void goodCase(int... aFoo) + { + int i = 0; + + String s = "ffffooooString"; + boolean b = s. + isEmpty(); + foo(i + ,s); //warn + int[] j; + } + public static String foo(int i, String s) + { + String maxLength = "123"; + int truncationLength = 1; + CharSequence seq = null; + Object truncationIndicator = null; + return new StringBuilder(maxLength ) + .append(seq, 0, truncationLength ) + .append(truncationIndicator) + .toString(); + } +} diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocation.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocation.java index 78cfb824161..acd1750ecbc 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocation.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocation.java @@ -1,7 +1,7 @@ package com.google.checkstyle.test.chapter4formatting.rule485annotations; @MyAnnotation2 @MyAnnotation1 //warn -class InputCorrectAnnotationIndentation +class InputAnnotationLocation { @MyAnnotation2 @MyAnnotation1 @@ -18,7 +18,7 @@ class InputCorrectAnnotationIndentation @MyAnnotation2 @MyAnnotation1 //warn - public InputCorrectAnnotationIndentation() {} + public InputAnnotationLocation() {} @MyAnnotationWithParam("foo") @MyAnnotation2 void foo1() {} diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocationVariables.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocationVariables.java new file mode 100644 index 00000000000..1175b7dc36d --- /dev/null +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule485annotations/InputAnnotationLocationVariables.java @@ -0,0 +1,103 @@ +package com.google.checkstyle.test.chapter4formatting.rule485annotations; + +@MyAnnotation2 @MyAnnotation1 // ok - in variables config +class InputAnnotationLocationVariables +{ + + @MyAnnotation2 @MyAnnotation1 + public int a; + + @MyAnnotation1 public int b; + + @MyAnnotation2 + @MyAnnotation1 + public int c; + + @MyAnnotation1 + public int d; + + @MyAnnotation2 + @MyAnnotation1 // ok - in variables config + public InputAnnotationLocationVariables() {} + + @MyAnnotationWithParam("foo") + @MyAnnotation2 void foo1() {} + + @MyAnnotation1 + @MyAnnotation2 // ok - in variables config + void foo2() {} + + @MyAnnotation1 + @MyAnnotation2 // ok - in variables config + @MyAnnotation3 // ok - in variables configwarn + @MyAnnotation4 // ok - in variables config + class InnerClass + { + @MyAnnotation2 @MyAnnotation1 + public int a; + + @MyAnnotation1 public int b; + + @MyAnnotation2 + @MyAnnotation1 + public int c; + + @MyAnnotation1 + public int d; + + @MyAnnotation2 + @MyAnnotation1 public InnerClass() + { + // TODO Auto-generated constructor stub + } + @MyAnnotation1 + @MyAnnotation2 // ok - in variables config + void foo1() {} + + @MyAnnotation1 + @MyAnnotation2 // ok - in variables config + void foo2() {} + } + + @MyAnnotation1 + @MyAnnotation2 //warn + InnerClass anon = new InnerClass() + { + @MyAnnotation2 @MyAnnotation1 public int a; + + @MyAnnotation1 public int b; + + @MyAnnotation2 + @MyAnnotation1 + public int c; + + @MyAnnotation1 + public int d; + + @MyAnnotation1 + @MyAnnotation2 void foo1() {} // ok - in variables config + + @MyAnnotation1 + @MyAnnotation2 // ok - in variables config + void foo2() {} + + @MyAnnotation1 void foo42() {} + }; + +} + +@MyAnnotation1 + @MyAnnotation2 // ok - in variables config +class FooVariables {} + +@interface MyAnnotationVariables1 {} + +@interface MyAnnotationVariables2 {} + +@interface MyAnnotationVariables3 {} + +@interface MyAnnotationVariables4 {} + +@interface MyAnnotationWithParamVariables { + + String value();}