diff --git a/src/it/java/com/google/checkstyle/test/chapter5naming/rule51identifiernames/CatchParameterNameTest.java b/src/it/java/com/google/checkstyle/test/chapter5naming/rule51identifiernames/CatchParameterNameTest.java index 2b8ce4078..a182c2ba1 100644 --- a/src/it/java/com/google/checkstyle/test/chapter5naming/rule51identifiernames/CatchParameterNameTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter5naming/rule51identifiernames/CatchParameterNameTest.java @@ -22,29 +22,40 @@ package com.google.checkstyle.test.chapter5naming.rule51identifiernames; import java.io.File; import java.io.IOException; +import org.junit.BeforeClass; import org.junit.Test; import com.google.checkstyle.test.base.BaseCheckTestSupport; +import com.puppycrawl.tools.checkstyle.api.CheckstyleException; import com.puppycrawl.tools.checkstyle.api.Configuration; public class CatchParameterNameTest extends BaseCheckTestSupport { + private static Configuration checkConfig; + private static String format; + @Override protected String getPath(String fileName) throws IOException { return super.getPath("chapter5naming" + File.separator + "rule51identifiernames" + File.separator + fileName); } + @BeforeClass + public static void setConfigurationBuilder() throws CheckstyleException { + checkConfig = getCheckConfig("CatchParameterName"); + format = checkConfig.getAttribute("format"); + } + @Test public void catchParameterNameTest() throws Exception { - final Configuration checkConfig = getCheckConfig("CatchParameterName"); final String msgKey = "name.invalidPattern"; - final String format = "^[a-z][a-z0-9][a-zA-Z0-9]*$"; final String[] expected = { - "6:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "e", format), - "24:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "t", format), "47:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "iException", format), - "50:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "x", format), + "50:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "ex_1", format), + "53:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "eX", format), + "56:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "eXX", format), + "59:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "x_y_z", format), + "62:28: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Ex", format), }; final String filePath = getPath("InputCatchParameterName.java"); diff --git a/src/it/java/com/google/checkstyle/test/chapter5naming/rule526parameternames/ParameterNameTest.java b/src/it/java/com/google/checkstyle/test/chapter5naming/rule526parameternames/ParameterNameTest.java index 3e38402b8..eb288b244 100644 --- a/src/it/java/com/google/checkstyle/test/chapter5naming/rule526parameternames/ParameterNameTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter5naming/rule526parameternames/ParameterNameTest.java @@ -34,10 +34,8 @@ import com.puppycrawl.tools.checkstyle.api.Configuration; public class ParameterNameTest extends BaseCheckTestSupport { private static final String MSG_KEY = "name.invalidPattern"; - private static String genealFormat; - private static String pubFormat; - private static Configuration generalConfig; - private static Configuration pubConfig; + private static String format; + private static Configuration config; @Override protected String getPath(String fileName) throws IOException { @@ -49,63 +47,34 @@ public class ParameterNameTest extends BaseCheckTestSupport { public static void setConfigurationBuilder() throws CheckstyleException { final List configs = getCheckConfigs("ParameterName"); - Assert.assertEquals(configs.size(), 2); + Assert.assertEquals(configs.size(), 1); - generalConfig = configs.get(0); - Assert.assertEquals(generalConfig.getAttribute("accessModifiers"), - "protected, package, private"); - genealFormat = generalConfig.getAttribute("format"); - - pubConfig = configs.get(1); - Assert.assertEquals(pubConfig.getAttribute("accessModifiers"), "public"); - pubFormat = pubConfig.getAttribute("format"); + config = configs.get(0); + format = config.getAttribute("format"); } @Test public void generalParameterNameTest() throws Exception { final String[] expected = { - "8:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "$arg1", genealFormat), - "9:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "ar$g2", genealFormat), - "10:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "arg3$", genealFormat), - "11:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "a_rg4", genealFormat), - "12:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "_arg5", genealFormat), - "13:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "arg6_", genealFormat), - "14:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "aArg7", genealFormat), - "15:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "aArg8", genealFormat), - "16:21: " - + getCheckMessage(generalConfig.getMessages(), MSG_KEY, "aar_g", genealFormat), + "10:21: " + getCheckMessage(config.getMessages(), MSG_KEY, "bB", format), + "33:22: " + getCheckMessage(config.getMessages(), MSG_KEY, "llll_llll", format), + "34:21: " + getCheckMessage(config.getMessages(), MSG_KEY, "bB", format), + "64:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "$arg1", format), + "65:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "ar$g2", format), + "66:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "arg3$", format), + "67:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "a_rg4", format), + "68:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "_arg5", format), + "69:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "arg6_", format), + "70:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "aArg7", format), + "71:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "aArg8", format), + "72:13: " + getCheckMessage(config.getMessages(), MSG_KEY, "aar_g", format), }; - final String filePath = getPath("InputParameterNameSimpleGeneral.java"); + final String filePath = getPath("InputParameterName.java"); final Integer[] warnList = getLinesWithWarn(filePath); - verify(generalConfig, filePath, expected, warnList); + verify(config, filePath, expected, warnList); } - @Test - public void pubParameterNameTest() throws Exception { - - final String[] expected = { - "10:21: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "bB", pubFormat), - "33:22: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "llll_llll", pubFormat), - "34:21: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "bB", pubFormat), - "44:23: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "p", pubFormat), - "53:31: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "p", pubFormat), - "58:44: " + getCheckMessage(pubConfig.getMessages(), MSG_KEY, "p", pubFormat), - }; - - final String filePath = getPath("InputParameterNameSimplePub.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(pubConfig, filePath, expected, warnList); - } } diff --git a/src/it/java/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/LocalVariableNameTest.java b/src/it/java/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/LocalVariableNameTest.java index 838cd5646..dd6c265cb 100644 --- a/src/it/java/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/LocalVariableNameTest.java +++ b/src/it/java/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/LocalVariableNameTest.java @@ -51,7 +51,6 @@ public class LocalVariableNameTest extends BaseCheckTestSupport { public void localVariableNameTest() throws Exception { final String[] expected = { - "26:13: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "a", format), "27:13: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "aA", format), "28:13: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "a1_a", format), "29:13: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "A_A", format), @@ -74,7 +73,6 @@ public class LocalVariableNameTest extends BaseCheckTestSupport { public void oneCharTest() throws Exception { final String[] expected = { - "15:13: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "i", format), "21:17: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "I_ndex", format), "45:17: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "i_ndex", format), "49:17: " + getCheckMessage(checkConfig.getMessages(), MSG_KEY, "ii_i1", format), diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule51identifiernames/InputCatchParameterName.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule51identifiernames/InputCatchParameterName.java index acb175a8e..42133bf8f 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule51identifiernames/InputCatchParameterName.java +++ b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule51identifiernames/InputCatchParameterName.java @@ -3,7 +3,7 @@ package com.google.checkstyle.test.chapter5naming.rule51identifiernames; public class InputCatchParameterName { { try { - } catch (Exception e) { // warn + } catch (Exception e) { // ok } try { } catch (Exception ex) { // ok @@ -21,7 +21,7 @@ public class InputCatchParameterName { } catch (Exception noWorries) { // ok } try { - } catch (Throwable t) { // warn + } catch (Throwable t) { // ok } try { throw new InterruptedException("interruptedException"); @@ -47,7 +47,19 @@ public class InputCatchParameterName { } catch (Exception iException) { // warn } try { - } catch (Exception x) { // warn + } catch (Exception ex_1) { // warn + } + try { + } catch (Exception eX) { // warn + } + try { + } catch (Exception eXX) { // warn + } + try { + } catch (Exception x_y_z) { // warn + } + try { + } catch (Exception Ex) { // warn } } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimplePub.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterName.java similarity index 75% rename from src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimplePub.java rename to src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterName.java index 0f39b7904..40fdf9250 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimplePub.java +++ b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterName.java @@ -2,7 +2,7 @@ package com.google.checkstyle.test.chapter5naming.rule526parameternames; import java.io.*; -class InputSimple2 +class InputParameterName { /** Some more Javadoc. */ @@ -41,7 +41,7 @@ class InputParameterNameSimplePub public void a(int par, int parA) {} /** Invalid: public and one char long */ - public void b(int p) {} //warn + public void b(int p) {} /** Valid: private and one char long. */ private void c(int p) {} @@ -50,13 +50,26 @@ class InputParameterNameSimplePub private void d(int param) { new Object() { /** Invalid: public and one char long. */ - public void e(int p) { } //warn + public void e(int p) { } }; } /** Invalid: public constructor and one char long */ - public InputParameterNameSimplePub(int p) { } // warn + public InputParameterNameSimplePub(int p) { } /** Valid: private constructor and one char long */ private InputParameterNameSimplePub(float p) { } + + void toManyArgs( + int $arg1, //warn + int ar$g2, //warn + int arg3$, //warn + int a_rg4, //warn + int _arg5, //warn + int arg6_, //warn + int aArg7, //warn + int aArg8, //warn + int aar_g) //warn + + {} } diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimpleGeneral.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimpleGeneral.java deleted file mode 100644 index dced1c36a..000000000 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule526parameternames/InputParameterNameSimpleGeneral.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.google.checkstyle.test.chapter5naming.rule526parameternames; - -import java.io.*; - -final class InputSimple -{ - void toManyArgs( - int $arg1, //warn - int ar$g2, //warn - int arg3$, //warn - int a_rg4, //warn - int _arg5, //warn - int arg6_, //warn - int aArg7, //warn - int aArg8, //warn - int aar_g) //warn - - {} -} diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameOneCharVarName.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameOneCharVarName.java index 462a5f76f..a3e2d4eb0 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameOneCharVarName.java +++ b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameOneCharVarName.java @@ -12,7 +12,7 @@ class InputOneCharInitVarName //some code } - int i = 0; //warn + int i = 0; // ok for(int index = 1; index < 10; index++) { //ok //some code diff --git a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameSimple.java b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameSimple.java index 3a3764d14..8a6012392 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameSimple.java +++ b/src/it/resources/com/google/checkstyle/test/chapter5naming/rule527localvariablenames/InputLocalVariableNameSimple.java @@ -23,7 +23,7 @@ final class InputSimple private void localVariables() { //bad examples - int a; //warn + int a; int aA; //warn int a1_a; //warn int A_A; //warn diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index 21465861c..d3fe68e5f 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -108,28 +108,18 @@ value="Member name ''{0}'' must match pattern ''{1}''."/> - - - - - - - - - + - - +