From 95d36da2e0f93e423e567b902e6d17105fa28a63 Mon Sep 17 00:00:00 2001 From: Shashwat Jaiswal Date: Thu, 19 Aug 2021 12:14:13 +0530 Subject: [PATCH] Issue #10548: Migrate to Inline Config Parser in Tests --- pom.xml | 2 - ...MultipleVariableDeclarationsCheckTest.java | 2 +- .../coding/PackageDeclarationCheckTest.java | 24 ++++--- .../checks/coding/RequireThisCheckTest.java | 68 ++++++++++++------- .../InputMultipleVariableDeclarations.java | 2 +- ...InputRequireThisAllowLambdaParameters.java | 2 +- .../InputRequireThisAllowLocalVars.java | 12 ++-- .../InputRequireThisAnonymousEmpty.java | 4 +- ...putRequireThisEnumInnerClassesAndBugs.java | 26 +++---- ...utRequireThisEnumInnerClassesAndBugs2.java | 6 +- ...utRequireThisEnumInnerClassesAndBugs3.java | 18 ++--- ...InputRequireThisFinalInstanceVariable.java | 4 +- .../requirethis/InputRequireThisFor.java | 2 +- .../requirethis/InputRequireThisSimple.java | 2 +- ...quireThisValidateOnlyOverlappingFalse.java | 12 ++-- ...equireThisValidateOnlyOverlappingTrue.java | 2 +- 16 files changed, 103 insertions(+), 85 deletions(-) diff --git a/pom.xml b/pom.xml index 5764daff5c0..a338300f8ec 100644 --- a/pom.xml +++ b/pom.xml @@ -1783,7 +1783,6 @@ **/ThrowsCountCheckTest.class - **/RequireThisCheckTest.class **/FileLengthCheckTest.class @@ -1862,7 +1861,6 @@ **/RecordComponentNameCheckTest.class - **/MultipleVariableDeclarationsCheckTest.class **/TypeUseAnnotationsOnQualifiedTypesTest.class diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.java index b952ce09c5a..57e3e2603f0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/MultipleVariableDeclarationsCheckTest.java @@ -52,7 +52,7 @@ public void testIt() throws Exception { "42:44: " + getCheckMessage(MSG_MULTIPLE), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputMultipleVariableDeclarations.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java index 921b70ea388..73a58dc6252 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/PackageDeclarationCheckTest.java @@ -44,7 +44,8 @@ public void testDefaultNoPackage() throws Exception { "8:1: " + getCheckMessage(MSG_KEY_MISSING), }; - verify(checkConfig, getPath("InputPackageDeclarationNoPackage.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputPackageDeclarationNoPackage.java"), expected); } @Test @@ -53,7 +54,8 @@ public void testDefaultWithPackage() throws Exception { final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputPackageDeclarationPlain.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputPackageDeclarationPlain.java"), expected); } @Test @@ -62,7 +64,8 @@ public void testOnFileWithCommentOnly() throws Exception { final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputPackageDeclarationWithCommentOnly.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputPackageDeclarationWithCommentOnly.java"), expected); } @Test @@ -73,7 +76,7 @@ public void testFileForDiffDirectoryMismatch() throws Exception { "8:1: " + getCheckMessage(MSG_KEY_MISMATCH), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectory.java"), expected); } @@ -85,7 +88,7 @@ public void testFileForDirectoryMismatchAtParent() throws Exception { "8:1: " + getCheckMessage(MSG_KEY_MISMATCH), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtParent.java"), expected); } @@ -98,7 +101,7 @@ public void testFileForDirectoryMismatchAtSubpackage() throws Exception { "8:1: " + getCheckMessage(MSG_KEY_MISMATCH), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtSubpackage.java"), expected); } @@ -109,7 +112,8 @@ public void testFileIgnoreDiffDirectoryMismatch() throws Exception { checkConfig.addProperty("matchDirectoryStructure", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectory2.java"), + verifyWithInlineConfigParser(checkConfig, + getNonCompilablePath("InputPackageDeclarationDiffDirectory2.java"), expected); } @@ -119,7 +123,7 @@ public void testFileIgnoreDirectoryMismatchAtParent() throws Exception { checkConfig.addProperty("matchDirectoryStructure", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtParent2.java"), expected); } @@ -130,7 +134,7 @@ public void testFileIgnoreDirectoryMismatchAtSubpackage() throws Exception { checkConfig.addProperty("matchDirectoryStructure", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationDiffDirectoryAtSubpackage2.java"), expected); } @@ -142,7 +146,7 @@ public void testNoPackage() throws Exception { "9:1: " + getCheckMessage(MSG_KEY_MISSING), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputPackageDeclarationNoPackage.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java index 154cc35644f..50fcef3fa30 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/RequireThisCheckTest.java @@ -76,7 +76,7 @@ public void testIt() throws Exception { "183:20: " + getCheckMessage(MSG_VARIABLE, "b", ""), "183:24: " + getCheckMessage(MSG_VARIABLE, "b", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisEnumInnerClassesAndBugs.java"), expected); } @@ -93,7 +93,7 @@ public void testMethodsOnly() throws Exception { "130:13: " + getCheckMessage(MSG_METHOD, "instanceMethod", "Issue22402."), "143:9: " + getCheckMessage(MSG_METHOD, "foo", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisEnumInnerClassesAndBugs2.java"), expected); } @@ -120,7 +120,7 @@ public void testFieldsOnly() throws Exception { "185:20: " + getCheckMessage(MSG_VARIABLE, "b", ""), "185:24: " + getCheckMessage(MSG_VARIABLE, "b", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisEnumInnerClassesAndBugs3.java"), expected); } @@ -152,7 +152,7 @@ public void testFieldsInExpressions() throws Exception { "35:31: " + getCheckMessage(MSG_VARIABLE, "b", ""), "36:32: " + getCheckMessage(MSG_VARIABLE, "b", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisExpressions.java"), expected); } @@ -163,7 +163,8 @@ public void testGenerics() throws Exception { createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThis15Extensions.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThis15Extensions.java"), expected); } @Test @@ -175,7 +176,7 @@ public void testGithubIssue41() throws Exception { "16:19: " + getCheckMessage(MSG_VARIABLE, "number", ""), "17:16: " + getCheckMessage(MSG_METHOD, "other", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisSimple.java"), expected); } @@ -197,7 +198,7 @@ public void testWithAnonymousClass() throws Exception { "32:24: " + getCheckMessage(MSG_VARIABLE, "bar", "InputRequireThisAnonymousEmpty."), "55:17: " + getCheckMessage(MSG_VARIABLE, "foobar", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getPath("InputRequireThisAnonymousEmpty.java"), expected); } @@ -266,7 +267,8 @@ public void testValidateOnlyOverlappingFalse() throws Exception { "393:16: " + getCheckMessage(MSG_METHOD, "processAction", ""), "499:22: " + getCheckMessage(MSG_VARIABLE, "add", ""), }; - verify(checkConfig, getPath("InputRequireThisValidateOnlyOverlappingFalse.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisValidateOnlyOverlappingFalse.java"), expected); } @Test @@ -286,14 +288,16 @@ public void testValidateOnlyOverlappingTrue() throws Exception { "310:9: " + getCheckMessage(MSG_VARIABLE, "field1", ""), "348:9: " + getCheckMessage(MSG_VARIABLE, "field1", ""), }; - verify(checkConfig, getPath("InputRequireThisValidateOnlyOverlappingTrue.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisValidateOnlyOverlappingTrue.java"), expected); } @Test public void testReceiverParameter() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisReceiver.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisReceiver.java"), expected); } @Test @@ -301,7 +305,8 @@ public void testBraceAlone() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisBraceAlone.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisBraceAlone.java"), expected); } @Test @@ -309,7 +314,8 @@ public void testStatic() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisStatic.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisStatic.java"), expected); } @Test @@ -318,7 +324,8 @@ public void testMethodReferences() throws Exception { final String[] expected = { "24:9: " + getCheckMessage(MSG_VARIABLE, "tags", ""), }; - verify(checkConfig, getPath("InputRequireThisMethodReferences.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisMethodReferences.java"), expected); } @Test @@ -334,7 +341,8 @@ public void testAllowLocalVars() throws Exception { "50:9: " + getCheckMessage(MSG_VARIABLE, "s2", ""), "51:16: " + getCheckMessage(MSG_VARIABLE, "s1", ""), }; - verify(checkConfig, getPath("InputRequireThisAllowLocalVars.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisAllowLocalVars.java"), expected); } @Test @@ -348,7 +356,8 @@ public void testAllowLambdaParameters() throws Exception { "71:29: " + getCheckMessage(MSG_VARIABLE, "a", ""), "71:34: " + getCheckMessage(MSG_VARIABLE, "b", ""), }; - verify(checkConfig, getPath("InputRequireThisAllowLambdaParameters.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisAllowLambdaParameters.java"), expected); } @Test @@ -358,7 +367,8 @@ public void testCatchVariables() throws Exception { final String[] expected = { "38:21: " + getCheckMessage(MSG_VARIABLE, "ex", ""), }; - verify(checkConfig, getPath("InputRequireThisCatchVariables.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisCatchVariables.java"), expected); } @Test @@ -366,7 +376,8 @@ public void testEnumConstant() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisEnumConstant.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisEnumConstant.java"), expected); } @Test @@ -374,7 +385,8 @@ public void testAnnotationInterface() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisAnnotationInterface.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisAnnotationInterface.java"), expected); } @Test @@ -385,7 +397,8 @@ public void testFor() throws Exception { "22:13: " + getCheckMessage(MSG_VARIABLE, "bottom", ""), "30:34: " + getCheckMessage(MSG_VARIABLE, "name", ""), }; - verify(checkConfig, getPath("InputRequireThisFor.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisFor.java"), expected); } @Test @@ -395,14 +408,16 @@ public void testFinalInstanceVariable() throws Exception { "18:9: " + getCheckMessage(MSG_VARIABLE, "y", ""), "19:9: " + getCheckMessage(MSG_VARIABLE, "z", ""), }; - verify(checkConfig, getPath("InputRequireThisFinalInstanceVariable.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisFinalInstanceVariable.java"), expected); } @Test public void test() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisCaseGroup.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisCaseGroup.java"), expected); } @Test @@ -410,7 +425,8 @@ public void testExtendedMethod() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputRequireThisExtendedMethod.java"), expected); + verifyWithInlineConfigParser(checkConfig, + getPath("InputRequireThisExtendedMethod.java"), expected); } @Test @@ -428,7 +444,7 @@ public void testRecordsAndCompactCtors() throws Exception { "58:13: " + getCheckMessage(MSG_METHOD, "method3", ""), "68:13: " + getCheckMessage(MSG_METHOD, "method1", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputRequireThisRecordsAndCompactCtors.java"), expected); } @@ -438,7 +454,7 @@ public void testRecordCompactCtors() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(RequireThisCheck.class); checkConfig.addProperty("validateOnlyOverlapping", "false"); final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputRequireThisRecordCompactCtors.java"), expected); } @@ -457,7 +473,7 @@ public void testRecordsAsTopLevel() throws Exception { "38:17: " + getCheckMessage(MSG_VARIABLE, "y", ""), "45:9: " + getCheckMessage(MSG_METHOD, "method1", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputRequireThisRecordAsTopLevel.java"), expected); } @@ -468,7 +484,7 @@ public void testRecordsDefault() throws Exception { final String[] expected = { "26:9: " + getCheckMessage(MSG_VARIABLE, "x", ""), }; - verify(checkConfig, + verifyWithInlineConfigParser(checkConfig, getNonCompilablePath("InputRequireThisRecordDefault.java"), expected); } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java index a8327cace13..e67ab773e3b 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations/InputMultipleVariableDeclarations.java @@ -39,7 +39,7 @@ void method2() { } void method3() { - java.lang.Object obj; Object obj1; Object obj2; Object obj3; // violation + java.lang.Object obj; Object obj1; Object obj2; Object obj3; // 3 violations for (String s : new String[] {}) {} } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLambdaParameters.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLambdaParameters.java index c92aecebabe..53ff833b9bb 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLambdaParameters.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLambdaParameters.java @@ -43,7 +43,7 @@ void methodInFirstLevel(int x) { new String("y = " + y); // NO violation; y is a lambda parameter new String("InputRequireThisAllowLambdaParameters.this.x = " + InputRequireThisAllowLambdaParameters.this.x); - y=x+z++; // 1 violation for z; NO violation for y; y is a lambda parameter + y=x+z++; // 1 violation for z; NO violation for y; y is a lambda // violation }; myConsumer.accept(x); } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLocalVars.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLocalVars.java index 5db635b1e56..87bdfd91b8c 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLocalVars.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAllowLocalVars.java @@ -15,7 +15,7 @@ class InputRequireThisAllowLocalVars { // ok String s2 = "foo2"; InputRequireThisAllowLocalVars() { - s1 = "bar1"; // Violation. Requires "this". + s1 = "bar1"; // violation String s2; s2 = "bar2"; // No violation. Local var allowed. } @@ -23,7 +23,7 @@ class InputRequireThisAllowLocalVars { // ok public int getS1() { String s1 = null; s1 = "bar"; // No violation - s1 = s1; // Violation. "this" required here to resolve any confusion due to overlapping. + s1 = s1; // violation return 1; } @@ -36,18 +36,18 @@ public String getS1(String param) { String getS2() { String s2 = null; - s2+=s2; // Violation. "this" required here to resolve any confusion due to overlapping. + s2+=s2; // violation return "return"; } String getS2(String s2) { - s2 = null; // Violation. Requires "this". s2 is a param not a local var. + s2 = null; // violation return s2; // No violation. param is returned. } String getS2(int a) { String s2 = " "; - s2 += s2; // Violation. "this" required here to resolve any confusion due to overlapping. - return s1; // Violation. Requires "this". + s2 += s2; // violation + return s1; // violation } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java index aecc759b970..5183f94345e 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisAnonymousEmpty.java @@ -29,7 +29,7 @@ public void fooEmpty() { } public int doSideEffect() { - return bar; + return bar; // violation } }; @@ -52,7 +52,7 @@ public void fooEmpty() { int foobar = 1; @Override public void fooEmpty() { - foobar++; + foobar++; // violation } }; } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java index 5a34a5fd50e..808a30ec4b8 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs.java @@ -23,7 +23,7 @@ void method1() { void method2(int i) { i++; this.i = i; - method1(); + method1(); // violation try { this.method1(); } @@ -37,7 +37,7 @@ void method2(int i) { void method3() { - i = 3; + i = 3; // violation } void method4() { @@ -55,14 +55,14 @@ enum MyEnum { void doSomething() { - z = 1; + z = 1; // violation } }; int z; private MyEnum() { - z = 0; + z = 0; // violation } } @@ -119,16 +119,16 @@ public void foo() { class Issue2240 { int i; void foo() { - i++; - i++; int i = 1; i++; - instanceMethod(); + i++; // violation + i++; int i = 1; i++; // violation + instanceMethod(); // violation } void instanceMethod() {}; class Nested { void bar() { - instanceMethod(); - i++; + instanceMethod(); // violation + i++; // violation } } } @@ -140,7 +140,7 @@ void foo() {} void bar() { foo(1); - foo(); + foo(); // violation } } class NestedRechange { @@ -148,7 +148,7 @@ class NestedRechange { NestedRechange() { String s = "t"; - s = s.substring(0); + s = s.substring(0); // violation } private static class NestedStatic { @@ -174,13 +174,13 @@ public int oneReturnInMethod2() { } } } - return a + a * a; + return a + a * a; // 3 violations } public int oneReturnInMethod3() { for (int b = 0; b < 10; b++) { } - return b + b * b; + return b + b * b; // 3 violations } final NestedFrames NestedFrames = new NestedFrames(); } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs2.java index 7a8d7b797e7..a0c39ac60e6 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs2.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs2.java @@ -121,13 +121,13 @@ class Issue22402 { void foo() { i++; i++; int i = 1; i++; - instanceMethod(); + instanceMethod(); // violation } void instanceMethod() {}; class Nested { void bar() { - instanceMethod(); + instanceMethod(); // violation i++; } } @@ -140,7 +140,7 @@ void foo() {} void bar() { foo(1); - foo(); + foo(); // violation } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs3.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs3.java index 768f9e8c09b..a745078a8e1 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs3.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisEnumInnerClassesAndBugs3.java @@ -36,7 +36,7 @@ void method2(int i) { void method3() { - i = 3; + i = 3; // violation } void method4() { @@ -55,14 +55,14 @@ enum MyEnum3 { void doSomething() { - z = 1; + z = 1; // violation } }; int z; private MyEnum3() { - z = 0; + z = 0; // violation } } @@ -119,8 +119,8 @@ public void foo() { class Issue22403 { int i; void foo() { - i++; - i++; int i = 1; i++; + i++; // violation + i++; int i = 1; i++; // violation instanceMethod(); } void instanceMethod() {}; @@ -128,7 +128,7 @@ void foo() { class Nested { void bar() { instanceMethod(); - i++; + i++; // violation } } } @@ -149,7 +149,7 @@ class NestedRechange3 { NestedRechange3() { String s = "t"; - s = s.substring(0); + s = s.substring(0); // violation } private static class NestedStatic { @@ -176,13 +176,13 @@ public int oneReturnInMethod2() { } } } - return a + a * a; + return a + a * a; // 3 violations } public int oneReturnInMethod3() { for (int b = 0; b < 10; b++) { } - return b + b * b; + return b + b * b; // 3 violations } final NestedFrames NestedFrames = new NestedFrames(); } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFinalInstanceVariable.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFinalInstanceVariable.java index ffe8b45ac78..95c0a45ef49 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFinalInstanceVariable.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFinalInstanceVariable.java @@ -15,8 +15,8 @@ public class InputRequireThisFinalInstanceVariable { final int z; public InputRequireThisFinalInstanceVariable(int y, int z) { - y = y; // violation until #8973 is fixed - z = z; // violation until #8973 is fixed + y = y; // violation until #8973 is fixed // violation + z = z; // violation until #8973 is fixed // violation } { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java index 793844b1613..9c845bc5cce 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisFor.java @@ -27,6 +27,6 @@ public void method2() { for (String name : new String[]{}) { } - Path jarfile = Paths.get(name + ".jar"); + Path jarfile = Paths.get(name + ".jar"); // violation } } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisSimple.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisSimple.java index a49b042bd33..ba9fa43bf10 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisSimple.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisSimple.java @@ -14,7 +14,7 @@ public class InputRequireThisSimple { public int check() { int sum = number; // violation - sum += other(); + sum += other(); // violation return sum; } diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingFalse.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingFalse.java index 99b42c42167..432b5bc3a49 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingFalse.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingFalse.java @@ -223,7 +223,7 @@ void foo24() { String field1 = "Hello"; field1 = "Java"; // No violation. Local var allowed this.booleanField = true; - this.booleanField = booleanField; + this.booleanField = booleanField; // violation } void foo25() { @@ -276,12 +276,12 @@ void foo31(String field1) { } String foo32(String field1) { - field1 = addSuf2F(field1); // no violation! modification of parameter which is returned + field1 = addSuf2F(field1); // violation return field1; } String foo33(String field1 ) { - field1 = addSuf2F(field1); // violation (no return, variable 'stringField' will not be saved + field1 = addSuf2F(field1); // 2 violations return "New String"; } @@ -380,9 +380,9 @@ public String getAction() { } public String foo45() { - String action = getAction(); // violation (Method call to 'getaction' needs "this.".) + String action = getAction(); // violation if (true) { - return processAction("action"); //violation(Method call to 'processAction' need "this.") + return processAction("action"); // violation } else if (action.endsWith("/")) { if (action.startsWith("/")) { @@ -390,7 +390,7 @@ else if (action.endsWith("/")) { } } action = "action"; // No violation. Local var allowed - return processAction(action); // violation (Method call to 'processAction' needs "this.".) + return processAction(action); // violation } private String processAction(String action) { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingTrue.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingTrue.java index 505cc8bf7f3..130fb40a197 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingTrue.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/requirethis/InputRequireThisValidateOnlyOverlappingTrue.java @@ -281,7 +281,7 @@ String foo32(String field1) { } String foo33(String field1) { - field1 = addSuf2F(field1); //violation (no return, variable 'stringField' will not be saved) + field1 = addSuf2F(field1); // violation return "New String"; }