diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/VariableDeclarationUsageDistanceTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/DeclaredWhenNeededTest.java similarity index 56% rename from src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/VariableDeclarationUsageDistanceTest.java rename to src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/DeclaredWhenNeededTest.java index 9a7b318d71c..6ae8d14c9c5 100644 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/VariableDeclarationUsageDistanceTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/DeclaredWhenNeededTest.java @@ -22,10 +22,8 @@ import org.junit.jupiter.api.Test; import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; -import com.puppycrawl.tools.checkstyle.api.Configuration; -import com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck; -public class VariableDeclarationUsageDistanceTest extends AbstractGoogleModuleTestSupport { +public class DeclaredWhenNeededTest extends AbstractGoogleModuleTestSupport { @Override protected String getPackageLocation() { @@ -34,24 +32,8 @@ protected String getPackageLocation() { @Test public void testArrayTypeStyle() throws Exception { - final String msgExt = "variable.declaration.usage.distance.extend"; - final Class clazz = - VariableDeclarationUsageDistanceCheck.class; - - final String[] expected = { - "71:9: " + getCheckMessage(clazz, msgExt, "count", 4, 3), - "219:9: " + getCheckMessage(clazz, msgExt, "t", 5, 3), - "483:9: " + getCheckMessage(clazz, msgExt, "myOption", 7, 3), - "495:9: " + getCheckMessage(clazz, msgExt, "myOption", 6, 3), - "508:9: " + getCheckMessage(clazz, msgExt, "count", 4, 3), - }; - - final Configuration checkConfig = - getModuleConfig("VariableDeclarationUsageDistance"); - final String filePath = getPath("InputVariableDeclarationUsageDistanceCheck.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); + final String filePath = getPath("InputDeclaredWhenNeeded.java"); + verifyWithConfigParser(new String[] {"VariableDeclarationUsageDistance"}, filePath); } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputVariableDeclarationUsageDistanceCheck.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputDeclaredWhenNeeded.java similarity index 95% rename from src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputVariableDeclarationUsageDistanceCheck.java rename to src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputDeclaredWhenNeeded.java index b283f38f77b..71d139e5020 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputVariableDeclarationUsageDistanceCheck.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822variabledistance/InputDeclaredWhenNeeded.java @@ -1,6 +1,6 @@ package com.google.checkstyle.test.chapter4formatting.rule4822variabledistance; import java.util.*; -public class InputVariableDeclarationUsageDistanceCheck { +public class InputDeclaredWhenNeeded { private static int test1 = 0; @@ -34,7 +34,7 @@ public class InputVariableDeclarationUsageDistanceCheck { a = b; // DECLARATION OF VARIABLE 'a' SHOULD BE HERE (distance = 2) } - public InputVariableDeclarationUsageDistanceCheck(int test1) { + public InputDeclaredWhenNeeded(int test1) { int temp = -1; this.test1 = test1; temp = test1; // DECLARATION OF VARIABLE 'temp' SHOULD BE HERE (distance = 2) @@ -42,7 +42,7 @@ public InputVariableDeclarationUsageDistanceCheck(int test1) { public boolean testMethod() { int temp = 7; - new InputVariableDeclarationUsageDistanceCheck(2); + new InputDeclaredWhenNeeded(2); String.valueOf(temp); // DECLARATION OF VARIABLE 'temp' SHOULD BE HERE (distance = 2) boolean result = false; String str = ""; @@ -68,7 +68,8 @@ public void testMethod2() { } public void testMethod3() { - int count; //warn + int count; + // violation above 'Distance between variable 'count' .* first usage is 4, but allowed 3.*' int a = 3; int b = 3; a = a + b; @@ -216,7 +217,8 @@ public void testMethod13() { public void testMethod14() { Session s = openSession(); - Transaction t = s.beginTransaction(); //warn + Transaction t = s.beginTransaction(); + // violation above 'Distance between variable 't' .* first usage is 5, but allowed 3.' A a = new A(); E d1 = new E(); C1 c = new C1(); @@ -480,7 +482,8 @@ public void testIssue32_8(Writer w1, Writer w2, Writer w3) { public void testIssue32_9() { Options options = new Options(); - Option myOption = null; //warn + Option myOption = null; + // violation above 'Distance between variable 'myOption' .* usage is 7, but allowed 3.' options.addBindFile(null); options.addBindFile(null); options.addBindFile(null); @@ -492,7 +495,8 @@ public void testIssue32_9() { public void testIssue32_10() { Options options = new Options(); - Option myOption = null; //warn + Option myOption = null; + // violation above 'Distance between variable 'myOption' .* usage is 6, but allowed 3.' options.addBindFile(null); options.addBindFile(null); options.addBindFile(null); @@ -505,7 +509,8 @@ public void testIssue32_10() { public int testIssue32_11(String toDir) throws Exception { - int count = 0; // warn + int count = 0; + // violation above 'Distance between variable 'count' .* first usage is 4, but allowed 3.' String[] files = {}; System.identityHashCode("Data archival started"); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java index 7ef1b85e936..76acf440cc4 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java @@ -239,7 +239,6 @@ public class XdocsPagesTest { "4.5.2 Indent continuation lines at least +4 spaces", "4.6.1 Vertical Whitespace", "4.6.2 Horizontal whitespace", - "4.8.2.2 Declared when needed", "4.8.3.2 No C-style array declarations", "4.8.4.1 Indentation", "4.8.4.3 Presence of the default label", diff --git a/src/xdocs/google_style.xml b/src/xdocs/google_style.xml index 5894208c0a7..769a3985620 100644 --- a/src/xdocs/google_style.xml +++ b/src/xdocs/google_style.xml @@ -1170,7 +1170,7 @@ - + 4.8.2.2 Declared when needed @@ -1185,7 +1185,7 @@ config
- + test