diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/GenericWhitespaceTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/GenericWhitespaceTest.java deleted file mode 100644 index 462e4ccd1f1..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/GenericWhitespaceTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -import java.util.Map; - -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.utils.CommonUtil; - -public class GenericWhitespaceTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testWhitespaceAroundGenerics() throws Exception { - final String msgPreceded = "ws.preceded"; - final String msgFollowed = "ws.followed"; - final Configuration checkConfig = getModuleConfig("GenericWhitespace"); - final Map messages = checkConfig.getMessages(); - - final String[] expected = { - "12:17: " + getCheckMessage(messages, msgFollowed, "<"), - "12:17: " + getCheckMessage(messages, msgPreceded, "<"), - "12:37: " + getCheckMessage(messages, msgFollowed, "<"), - "12:37: " + getCheckMessage(messages, msgPreceded, "<"), - "12:48: " + getCheckMessage(messages, msgFollowed, ">"), - "12:48: " + getCheckMessage(messages, msgPreceded, ">"), - "12:50: " + getCheckMessage(messages, msgPreceded, ">"), - "14:33: " + getCheckMessage(messages, msgFollowed, "<"), - "14:33: " + getCheckMessage(messages, msgPreceded, "<"), - "14:46: " + getCheckMessage(messages, msgPreceded, ">"), - "15:33: " + getCheckMessage(messages, msgFollowed, "<"), - "15:33: " + getCheckMessage(messages, msgPreceded, "<"), - "15:46: " + getCheckMessage(messages, msgFollowed, ">"), - "15:46: " + getCheckMessage(messages, msgPreceded, ">"), - "20:39: " + getCheckMessage(messages, msgFollowed, "<"), - "20:39: " + getCheckMessage(messages, msgPreceded, "<"), - "20:62: " + getCheckMessage(messages, msgPreceded, ">"), - }; - - final String filePath = getPath("InputWhitespaceAroundGenerics.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void testGenericWhitespace() throws Exception { - final String msgPreceded = "ws.preceded"; - final String msgFollowed = "ws.followed"; - final String msgNotPreceded = "ws.notPreceded"; - final String msgIllegalFollow = "ws.illegalFollow"; - final Configuration checkConfig = getModuleConfig("GenericWhitespace"); - final Map messages = checkConfig.getMessages(); - - final String[] expected = { - "16:14: " + getCheckMessage(messages, msgFollowed, "<"), - "16:14: " + getCheckMessage(messages, msgPreceded, "<"), - "16:24: " + getCheckMessage(messages, msgPreceded, ">"), - "16:44: " + getCheckMessage(messages, msgFollowed, "<"), - "16:44: " + getCheckMessage(messages, msgPreceded, "<"), - "16:54: " + getCheckMessage(messages, msgFollowed, ">"), - "16:54: " + getCheckMessage(messages, msgPreceded, ">"), - "17:14: " + getCheckMessage(messages, msgFollowed, "<"), - "17:14: " + getCheckMessage(messages, msgPreceded, "<"), - "17:21: " + getCheckMessage(messages, msgFollowed, "<"), - "17:21: " + getCheckMessage(messages, msgPreceded, "<"), - "17:31: " + getCheckMessage(messages, msgFollowed, ">"), - "17:31: " + getCheckMessage(messages, msgPreceded, ">"), - "17:33: " + getCheckMessage(messages, msgPreceded, ">"), - "17:53: " + getCheckMessage(messages, msgFollowed, "<"), - "17:53: " + getCheckMessage(messages, msgPreceded, "<"), - "17:60: " + getCheckMessage(messages, msgFollowed, "<"), - "17:60: " + getCheckMessage(messages, msgPreceded, "<"), - "17:70: " + getCheckMessage(messages, msgFollowed, ">"), - "17:70: " + getCheckMessage(messages, msgPreceded, ">"), - "17:72: " + getCheckMessage(messages, msgFollowed, ">"), - "17:72: " + getCheckMessage(messages, msgPreceded, ">"), - "30:18: " + getCheckMessage(messages, msgNotPreceded, "<"), - "30:20: " + getCheckMessage(messages, msgIllegalFollow, ">"), - "42:22: " + getCheckMessage(messages, msgPreceded, "<"), - "42:29: " + getCheckMessage(messages, msgFollowed, ">"), - "60:59: " + getCheckMessage(messages, msgNotPreceded, "&"), - "63:59: " + getCheckMessage(messages, msgFollowed, ">"), - }; - - final String filePath = getPath("InputGenericWhitespace.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void genericEndsTheLine() throws Exception { - final Configuration checkConfig = getModuleConfig("GenericWhitespace"); - final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - verify(checkConfig, getPath("InputGenericWhitespaceEndsTheLine.java"), - expected); - } - -} diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/HorizontalWhitespaceTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/HorizontalWhitespaceTest.java new file mode 100644 index 00000000000..20a4b509387 --- /dev/null +++ b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/HorizontalWhitespaceTest.java @@ -0,0 +1,119 @@ +/////////////////////////////////////////////////////////////////////////////////////////////// +// checkstyle: Checks Java source code and other text files for adherence to a set of rules. +// Copyright (C) 2001-2024 the original author or authors. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +/////////////////////////////////////////////////////////////////////////////////////////////// + +package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; + +import org.junit.jupiter.api.Test; + +import com.google.checkstyle.test.base.AbstractGoogleModuleTestSupport; + +public class HorizontalWhitespaceTest extends AbstractGoogleModuleTestSupport { + + private static final String[] MODULES = { + "WhitespaceAround", + "WhitespaceAfter", + "GenericWhitespace", + "MethodParamPad", + "ParenPad", + "NoWhitespaceBefore", + "NoWhitespaceBeforeCaseDefaultColon", + }; + + @Override + protected String getPackageLocation() { + return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; + } + + @Test + public void testWhitespaceAroundBasic() throws Exception { + final String filePath = getPath("InputWhitespaceAroundBasic.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testWhitespaceAroundEmptyTypesCycles() throws Exception { + final String filePath = getPath("InputWhitespaceAroundEmptyTypesAndCycles.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testWhitespaceAfterBad() throws Exception { + final String filePath = getPath("InputWhitespaceAfterBad.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testWhitespaceAfterGood() throws Exception { + final String filePath = getPath("InputWhitespaceAfterGood.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testParenPad() throws Exception { + final String filePath = getPath("InputParenPad.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testNoWhitespaceBeforeEmptyForLoop() throws Exception { + final String filePath = getPath("InputNoWhitespaceBeforeEmptyForLoop.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testNoWhitespaceBeforeColonOfLabel() throws Exception { + final String filePath = getPath("InputNoWhitespaceBeforeColonOfLabel.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testNoWhitespaceBeforeAnnotations() throws Exception { + final String filePath = getPath("InputNoWhitespaceBeforeAnnotations.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testNoWhitespaceBeforeCaseDefaultColon() throws Exception { + final String filePath = getPath("InputNoWhitespaceBeforeCaseDefaultColon.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testMethodParamPad() throws Exception { + final String filePath = getPath("InputMethodParamPad.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testWhitespaceAroundGenerics() throws Exception { + final String filePath = getPath("InputWhitespaceAroundGenerics.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void testGenericWhitespace() throws Exception { + final String filePath = getPath("InputGenericWhitespace.java"); + verifyWithConfigParser(MODULES, filePath); + } + + @Test + public void genericEndsTheLine() throws Exception { + verifyWithConfigParser(MODULES, getPath("InputGenericWhitespaceEndsTheLine.java")); + } +} diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/MethodParamPadTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/MethodParamPadTest.java deleted file mode 100644 index 12a50f59eeb..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/MethodParamPadTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -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.whitespace.MethodParamPadCheck; - -public class MethodParamPadTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testOperatorWrap() throws Exception { - final Class clazz = MethodParamPadCheck.class; - final String messageKeyPreceded = "ws.preceded"; - - final String[] expected = { - "11:32: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "13:15: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "20:24: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "29:39: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "35:16: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "41:21: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "47:18: " + getCheckMessage(clazz, messageKeyPreceded, "("), - "52:36: " + getCheckMessage(clazz, messageKeyPreceded, "("), - }; - final Configuration checkConfig = getModuleConfig("MethodParamPad"); - final String filePath = getPath("InputMethodParamPad.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeCaseDefaultColonTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeCaseDefaultColonTest.java deleted file mode 100644 index 8f99451a218..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeCaseDefaultColonTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -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.whitespace.NoWhitespaceBeforeCheck; - -public class NoWhitespaceBeforeCaseDefaultColonTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void test() throws Exception { - final Class clazz = NoWhitespaceBeforeCheck.class; - final String messageKeyPreceded = "ws.preceded"; - - final String[] expected = { - "6:20: " + getCheckMessage(clazz, messageKeyPreceded, ":"), - "10:21: " + getCheckMessage(clazz, messageKeyPreceded, ":"), - }; - final Configuration checkConfig = getModuleConfig("NoWhitespaceBeforeCaseDefaultColon"); - final String filePath = getPath("InputNoWhitespaceBeforeCaseDefaultColon.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} - diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeTest.java deleted file mode 100644 index 6ef455675a3..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/NoWhitespaceBeforeTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -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.whitespace.NoWhitespaceBeforeCheck; -import com.puppycrawl.tools.checkstyle.utils.CommonUtil; - -public class NoWhitespaceBeforeTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testEmptyForLoop() throws Exception { - final Class clazz = NoWhitespaceBeforeCheck.class; - final String messageKeyPreceded = "ws.preceded"; - - final String[] expected = { - "12:24: " + getCheckMessage(clazz, messageKeyPreceded, ";"), - "18:32: " + getCheckMessage(clazz, messageKeyPreceded, ";"), - }; - final Configuration checkConfig = getModuleConfig("NoWhitespaceBefore"); - final String filePath = getPath("InputNoWhitespaceBeforeEmptyForLoop.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void testColonOfLabel() throws Exception { - final Class clazz = NoWhitespaceBeforeCheck.class; - final String messageKeyPreceded = "ws.preceded"; - - final String[] expected = { - "6:16: " + getCheckMessage(clazz, messageKeyPreceded, ":"), - }; - final Configuration checkConfig = getModuleConfig("NoWhitespaceBefore"); - final String filePath = getPath("InputNoWhitespaceBeforeColonOfLabel.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void testAnnotations() throws Exception { - final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - final Configuration checkConfig = getModuleConfig("NoWhitespaceBefore"); - final String filePath = getPath("InputNoWhitespaceBeforeAnnotations.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} - diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/ParenPadTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/ParenPadTest.java deleted file mode 100644 index f8456de7180..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/ParenPadTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -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.whitespace.ParenPadCheck; - -public class ParenPadTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testMethodParen() throws Exception { - final Class clazz = ParenPadCheck.class; - final String messageKeyPreceded = "ws.preceded"; - final String messageKeyFollowed = "ws.followed"; - - final String[] expected = { - "44:26: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "44:28: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "45:17: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "48:26: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "49:18: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "49:20: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "52:26: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "53:20: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "54:17: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "54:51: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "54:53: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "57:25: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "58:21: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "59:23: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "60:25: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "60:50: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "60:56: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "61:28: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "62:42: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "63:40: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "65:42: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "78:27: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "78:29: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "79:20: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "82:34: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "83:18: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "83:20: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "86:30: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "87:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "88:50: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "88:52: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "88:54: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "90:39: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "91:33: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "92:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "93:31: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "94:61: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "94:63: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "94:70: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "95:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "96:48: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "97:43: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "99:45: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "112:16: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "113:22: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "113:24: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "113:32: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "114:25: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "114:27: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "114:35: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "114:51: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "115:25: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "115:27: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "115:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "115:54: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "115:56: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "119:16: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "119:23: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "123:29: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "123:45: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "126:21: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "126:23: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "130:18: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "130:20: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "139:9: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "139:21: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "145:32: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "145:47: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "153:33: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "154:49: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "155:35: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "155:47: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "159:25: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "159:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "160:12: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "160:28: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "160:49: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "160:51: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "163:31: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "163:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "163:47: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "163:61: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "166:40: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "167:24: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "167:51: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "173:37: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "174:49: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "175:20: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "175:49: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "185:16: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "185:36: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "186:19: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "186:39: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "190:29: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "190:45: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "191:12: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "191:39: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "192:22: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "192:40: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "200:80: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "200:84: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "201:20: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "202:24: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "203:20: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "203:25: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "206:13: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "206:23: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "206:31: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "207:17: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "207:47: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "210:36: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "210:73: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "210:81: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "210:83: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "211:36: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "212:48: " + getCheckMessage(clazz, messageKeyFollowed, "("), - "212:52: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "212:54: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "220:37: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - "221:61: " + getCheckMessage(clazz, messageKeyPreceded, ")"), - }; - final Configuration checkConfig = getModuleConfig("ParenPad"); - final String filePath = getPath("InputParenPad.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java deleted file mode 100644 index f0d15d1e027..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAfterTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -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.whitespace.WhitespaceAfterCheck; -import com.puppycrawl.tools.checkstyle.utils.CommonUtil; - -public class WhitespaceAfterTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testWhitespaceAfterBad() throws Exception { - final Class clazz = WhitespaceAfterCheck.class; - final String message = "ws.notFollowed"; - - final String[] expected = { - "4:29: " + getCheckMessage(clazz, message, ","), - "5:9: " + getCheckMessage(clazz, message, "for"), - "5:20: " + getCheckMessage(clazz, message, ","), - "5:24: " + getCheckMessage(clazz, message, ";"), - "5:28: " + getCheckMessage(clazz, message, ";"), - "5:32: " + getCheckMessage(clazz, message, ","), - "6:9: " + getCheckMessage(clazz, message, "while"), - "7:20: " + getCheckMessage(clazz, message, ","), - "9:9: " + getCheckMessage(clazz, message, "do"), - "11:10: " + getCheckMessage(clazz, message, "while"), - "13:35: " + getCheckMessage(clazz, message, ","), - "14:9: " + getCheckMessage(clazz, message, "if"), - "14:18: " + getCheckMessage(clazz, message, "typecast"), - "17:9: " + getCheckMessage(clazz, message, "else"), - "22:28: " + getCheckMessage(clazz, message, "..."), - "23:26: " + getCheckMessage(clazz, message, "->"), - "24:9: " + getCheckMessage(clazz, message, "switch"), - "31:9: " + getCheckMessage(clazz, message, "try"), - "35:16: " + getCheckMessage(clazz, message, "finally"), - "36:38: " + getCheckMessage(clazz, message, "finally"), - "40:16: " + getCheckMessage(clazz, message, "catch"), - "44:9: " + getCheckMessage(clazz, message, "synchronized"), - "49:9: " + getCheckMessage(clazz, message, "return"), - }; - final Configuration checkConfig = getModuleConfig("WhitespaceAfter"); - final String filePath = getPath("InputWhitespaceAfterBad.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void testWhitespaceAfterGood() throws Exception { - final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - final Configuration checkConfig = getModuleConfig("WhitespaceAfter"); - final String filePath = getPath("InputWhitespaceAfterGood.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} diff --git a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAroundTest.java b/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAroundTest.java deleted file mode 100644 index 596d9828d8d..00000000000 --- a/src/it/java/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/WhitespaceAroundTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////////////////////// -// checkstyle: Checks Java source code and other text files for adherence to a set of rules. -// Copyright (C) 2001-2024 the original author or authors. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -/////////////////////////////////////////////////////////////////////////////////////////////// - -package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; - -import java.util.Map; - -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.utils.CommonUtil; - -public class WhitespaceAroundTest extends AbstractGoogleModuleTestSupport { - - @Override - protected String getPackageLocation() { - return "com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace"; - } - - @Test - public void testWhitespaceAroundBasic() throws Exception { - final Configuration checkConfig = getModuleConfig("WhitespaceAround"); - final String msgPreceded = "ws.notPreceded"; - final String msgFollowed = "ws.notFollowed"; - final Map messages = checkConfig.getMessages(); - - final String[] expected = { - "10:22: " + getCheckMessage(messages, msgPreceded, "="), - "12:23: " + getCheckMessage(messages, msgFollowed, "="), - "20:14: " + getCheckMessage(messages, msgPreceded, "="), - "21:10: " + getCheckMessage(messages, msgPreceded, "="), - "22:11: " + getCheckMessage(messages, msgFollowed, "+="), - "23:11: " + getCheckMessage(messages, msgFollowed, "-="), - "31:9: " + getCheckMessage(messages, msgFollowed, "synchronized"), - "33:13: " + getCheckMessage(messages, msgFollowed, "{"), - "35:36: " + getCheckMessage(messages, msgFollowed, "{"), - "52:9: " + getCheckMessage(messages, msgFollowed, "if"), - "70:13: " + getCheckMessage(messages, msgFollowed, "return"), - "92:24: " + getCheckMessage(messages, msgFollowed, "=="), - "98:22: " + getCheckMessage(messages, msgPreceded, "*"), - "113:18: " + getCheckMessage(messages, msgPreceded, "%"), - "114:19: " + getCheckMessage(messages, msgFollowed, "%"), - "115:18: " + getCheckMessage(messages, msgPreceded, "%"), - "117:18: " + getCheckMessage(messages, msgPreceded, "/"), - "118:19: " + getCheckMessage(messages, msgFollowed, "/"), - "147:9: " + getCheckMessage(messages, msgFollowed, "assert"), - "150:20: " + getCheckMessage(messages, msgPreceded, ":"), - "241:19: " + getCheckMessage(messages, msgFollowed, ":"), - "241:19: " + getCheckMessage(messages, msgPreceded, ":"), - "242:20: " + getCheckMessage(messages, msgFollowed, ":"), - "243:19: " + getCheckMessage(messages, msgPreceded, ":"), - "257:14: " + getCheckMessage(messages, msgPreceded, "->"), - "258:15: " + getCheckMessage(messages, msgFollowed, "->"), - }; - - final String filePath = getPath("InputWhitespaceAroundBasic.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - - @Test - public void testWhitespaceAroundEmptyTypesCycles() throws Exception { - final String[] expected = CommonUtil.EMPTY_STRING_ARRAY; - - final Configuration checkConfig = getModuleConfig("WhitespaceAround"); - final String filePath = getPath("InputWhitespaceAroundEmptyTypesAndCycles.java"); - - final Integer[] warnList = getLinesWithWarn(filePath); - verify(checkConfig, filePath, expected, warnList); - } - -} diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputGenericWhitespace.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputGenericWhitespace.java index 1f58f18f2da..70c205b3aca 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputGenericWhitespace.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputGenericWhitespace.java @@ -13,8 +13,30 @@ void meth() { List x = new ArrayList(); List> y = new ArrayList>(); - List < Integer > a = new ArrayList < Integer > (); // warn - List < List < Integer > > b = new ArrayList < List < Integer > > (); // warn + List < Integer > a = new ArrayList < Integer >(); + // 6 violations above: + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' + List < List < Integer > > b = new ArrayList < List < Integer > >(); + // 14 violations above: + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is followed by whitespace.' + // ''\>' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is followed by whitespace.' + // ''\>' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' } public int compareTo(InputGenericWhitespace aObject) @@ -27,7 +49,10 @@ public static Callable callable(Runnable task, T result) return null; } - public staticCallable callable2(Runnable task, T result) // warn + public staticCallable callable2(Runnable task, T result) + // 2 violations above: + // ''\<' is not preceded with whitespace.' + // ''\>' should followed by whitespace.' { Map, Integer> x = new HashMap, Integer>(); for (final Map.Entry, Integer> entry : x.entrySet()) { @@ -39,7 +64,10 @@ public staticCallable callable2(Runnable task, T result) // warn public int getConstructor(Class... parameterTypes) { Collections.emptySet(); - Collections. emptySet(); // warn + Collections. emptySet(); + // 2 violations above: + // ''\<' is preceded with whitespace.' + // ''\>' is followed by whitespace.' return 666; } @@ -57,9 +85,13 @@ public interface IntEnum { public static class IntEnumValueType & IntEnum> { } - public static class IntEnumValueType2& IntEnum> { // warn + public static class IntEnumValueType2& IntEnum> { + // 2 violations above: + // ''&' is not preceded with whitespace.' + // ''&' is not preceded with whitespace.' } - public static class IntEnumValueType3 & IntEnum> { // warn + public static class IntEnumValueType3 & IntEnum> { + // violation above ''\>' is followed by whitespace.' } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputMethodParamPad.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputMethodParamPad.java index 059314709b5..35f96ff15c0 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputMethodParamPad.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputMethodParamPad.java @@ -8,16 +8,16 @@ public InputMethodParamPad() super(); } - public InputMethodParamPad (int aParam) // warn + public InputMethodParamPad (int aParam) // violation ''(' is preceded with whitespace.' { - super (); // warn + super (); // violation ''(' is preceded with whitespace.' } public void method() { } - public void method (int aParam) // warn + public void method (int aParam) // violation ''(' is preceded with whitespace.' { } @@ -26,30 +26,30 @@ public void method (int aParam) // warn { // invoke constructor InputMethodParamPad pad = new InputMethodParamPad(); - pad = new InputMethodParamPad (); // warn + pad = new InputMethodParamPad (); // violation ''(' is preceded with whitespace.' pad = new InputMethodParamPad(); // call method method(); - method (); // warn + method (); // violation ''(' is preceded with whitespace.' } public void dottedCalls() { this.method(); - this.method (); // warn + this.method (); // violation ''(' is preceded with whitespace.' this. method(); InputMethodParamPad p = new InputMethodParamPad(); p.method(); - p.method (); // warn + p.method (); // violation ''(' is preceded with whitespace.' p. method(); java.lang.Integer.parseInt("0"); - java.lang.Integer.parseInt ("0"); // warn + java.lang.Integer.parseInt ("0"); // violation ''(' is preceded with whitespace.' java.lang.Integer. parseInt("0"); } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeCaseDefaultColon.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeCaseDefaultColon.java index 38c74603473..4290412f498 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeCaseDefaultColon.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeCaseDefaultColon.java @@ -2,12 +2,12 @@ public class InputNoWhitespaceBeforeCaseDefaultColon { { - switch(1) { - case 1 : // warn + switch (1) { + case 1 : // violation '':' is preceded with whitespace.' break; case 2: break; - default : // warn + default : // violation '':' is preceded with whitespace.' break; } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeColonOfLabel.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeColonOfLabel.java index 5443104d86d..d6f493e39df 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeColonOfLabel.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeColonOfLabel.java @@ -3,8 +3,8 @@ public class InputNoWhitespaceBeforeColonOfLabel { { - label1 : // warn - for(int i = 0; i < 10; i++) {} + label1 : // violation '':' is preceded with whitespace.' + for (int i = 0; i < 10; i++) {} } public void foo() { diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeEmptyForLoop.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeEmptyForLoop.java index c6d72ef4e57..a449561e7a0 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeEmptyForLoop.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputNoWhitespaceBeforeEmptyForLoop.java @@ -9,13 +9,13 @@ public static void f() { for (int x = 0; ; ) { // ok break; } - for (int x = 0 ; ; ) { // warning + for (int x = 0 ; ; ) { // violation '';' is preceded with whitespace.' break; } for (int x = 0; x < 10; ) { // ok break; } - for (int x = 0; x < 10 ; ) { // warning + for (int x = 0; x < 10 ; ) { // violation '';' is preceded with whitespace.' break; } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputParenPad.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputParenPad.java index f2ee15f7d1e..49757dc8884 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputParenPad.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputParenPad.java @@ -41,28 +41,42 @@ void method(boolean status) { } class ParenPadSpaceLeft { - ParenPadSpaceLeft( ) { // warning - this( 0); // warning + ParenPadSpaceLeft( ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + this( 0); // violation ''(' is followed by whitespace.' } - ParenPadSpaceLeft( int i) { // warning - super( ); // warning + ParenPadSpaceLeft( int i) { // violation ''(' is followed by whitespace.' + super( ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } - @SuppressWarnings( "") // warning - void method( boolean status) { // warning - try ( Writer writer = new StringWriter( )) { // warning + @SuppressWarnings( "") // violation ''(' is followed by whitespace.' + void method( boolean status) { // violation ''(' is followed by whitespace.' + try ( Writer writer = new StringWriter( )) { + // 3 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' do { writer.append("a"); - } while ( status); // warning - } catch ( IOException e) { // warning - while ( status) { // warning - for ( int i = 0; i < ( long) ( 2 * ( 4 / 2)); i++) { // warning - if ( i > 2) { // warning - synchronized ( this) { // warning - switch ( i) { // warning + } while ( status); // violation ''(' is followed by whitespace.' + } catch ( IOException e) { // violation ''(' is followed by whitespace.' + while ( status) { // violation ''(' is followed by whitespace.' + for ( int i = 0; i < ( long) ( 2 * ( 4 / 2)); i++) { + // 3 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + if ( i > 2) { // violation ''(' is followed by whitespace.' + synchronized ( this) { // violation ''(' is followed by whitespace.' + switch ( i) { // violation ''(' is followed by whitespace.' case 3: - case ( 4): // warning + case ( 4): // violation ''(' is followed by whitespace.' case 5: break; } @@ -75,28 +89,42 @@ void method( boolean status) { // warning } class ParenPadSpaceRight { - ParenPadSpaceRight( ) { // warning - this(0 ); // warning + ParenPadSpaceRight( ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + this(0 ); // violation '')' is preceded with whitespace.' } - ParenPadSpaceRight(int i ) { // warning - super( ); // warning + ParenPadSpaceRight(int i ) { // violation '')' is preceded with whitespace.' + super( ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } - @SuppressWarnings("" ) // warning - void method(boolean status ) { // warning - try (Writer writer = new StringWriter( ) ) { // warning + @SuppressWarnings("" ) // violation '')' is preceded with whitespace.' + void method(boolean status ) { // violation '')' is preceded with whitespace.' + try (Writer writer = new StringWriter( ) ) { + // 3 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' do { - writer.append("a" ); // warning - } while (status ); // warning - } catch (IOException e ) { // warning - while (status ) { // warning - for (int i = 0; i < (long ) (2 * (4 / 2 ) ); i++ ) { // warning - if (i > 2 ) { // warning - synchronized (this ) { // warning - switch (i ) { // warning + writer.append("a" ); // violation '')' is preceded with whitespace.' + } while (status ); // violation '')' is preceded with whitespace.' + } catch (IOException e ) { // violation '')' is preceded with whitespace.' + while (status ) { // violation '')' is preceded with whitespace.' + for (int i = 0; i < (long ) (2 * (4 / 2 ) ); i++ ) { + // 3 violations above: + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' + if (i > 2 ) { // violation '')' is preceded with whitespace.' + synchronized (this ) { // violation '')' is preceded with whitespace.' + switch (i ) { // violation '')' is preceded with whitespace.' case 3: - case (4 ): // warning + case (4 ): // violation '')' is preceded with whitespace.' case 5: break; } @@ -109,25 +137,53 @@ void method(boolean status ) { // warning } String foo() { - return ( (Object // warning - ) bar( ( 1 > 2 ) ? // warning - ( ( 3 < 4 )? false : true ) : // warning - ( ( 1 == 1 ) ? false : true) ) ).toString(); // warning + return ( (Object // violation ''(' is followed by whitespace.' + ) bar( ( 1 > 2 ) ? + // 3 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + ( ( 3 < 4 ) ? false : true ) : + // 4 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' + ( ( 1 == 1 ) ? false : true) ) ).toString(); + // 5 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' } @MyAnnotation public boolean bar(boolean a) { - assert ( true ); // warning + assert ( true ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' return true; } - boolean fooo = this.bar(( true && false ) && true); // warning + boolean fooo = this.bar(( true && false ) && true); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + } @interface MyAnnotation { - String someField( ) default "Hello world"; // warning + String someField( ) default "Hello world"; + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } enum MyEnum { - SOME_CONSTANT( ) { // warning + SOME_CONSTANT( ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' int i = (int) (2 * (4 / 2) ); }; @@ -135,44 +191,72 @@ enum MyEnum { public void myMethod() { String s = "test"; Object o = s; - ((String)o).length(); - ( (String)o ).length(); // warning + ((String) o).length(); + ( (String) o ).length(); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } public void crisRon() { Object leo = "messi"; Object ibra = leo; - ((String)leo).compareTo( (String)ibra ); // warning + ((String) leo).compareTo( (String) ibra ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' Math.random(); } public void intStringConv() { Object a = 5; Object b = "string"; - int w = Integer.parseInt((String)a); - int x = Integer.parseInt( (String)a); // warning - double y = Double.parseDouble((String)a ); // warning - float z = Float.parseFloat( (String)a ); // warning - String d = ((String)b); + int w = Integer.parseInt((String) a); + int x = Integer.parseInt( (String) a); // violation ''(' is followed by whitespace.' + double y = Double.parseDouble((String) a ); // violation '')' is preceded with whitespace.' + float z = Float.parseFloat( (String) a ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + String d = ((String) b); } - public int something( Object o ) { // warning - if ( o == null || !( o instanceof Float ) ) { // warning + public int something( Object o ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + if ( o == null || !( o instanceof Float ) ) { + // 4 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' return -1; } - return Integer.valueOf( 22 ).compareTo( (Integer) o ); // warning + return Integer.valueOf( 22 ).compareTo( (Integer) o ); + // 4 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } - private void launch(Integer number ) { // warning - String myInt = ( number.toString() + '\0' ); // warning + private void launch(Integer number ) { // violation '')' is preceded with whitespace.' + String myInt = ( number.toString() + '\0' ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' boolean result = false; if (number == 123) result = true; } - private static String getterName( Exception t) { // warning - if (t instanceof ClassNotFoundException ) { // warning - return ( (ClassNotFoundException) t ).getMessage(); // warning + private static String getterName( Exception t) { // violation ''(' is followed by whitespace.' + if (t instanceof ClassNotFoundException ) { // violation '')' is preceded with whitespace.' + return ( (ClassNotFoundException) t ).getMessage(); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } else { return "?"; @@ -182,14 +266,29 @@ private static String getterName( Exception t) { // warning private Object exam; public String testing() { - return ( this.exam != null ) // warning - ? ( ( Enum )this.exam ).name() // warning + return ( this.exam != null ) + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + ? ( ( Enum ) this.exam ).name() + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' : null; } - Object stringReturnValue( Object result ) { // warning - if ( result instanceof String ) { // warning - result = ( (String) result ).length(); // warning + Object stringReturnValue( Object result ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + if ( result instanceof String ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + result = ( (String) result ).length(); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' } return result; } @@ -197,27 +296,51 @@ Object stringReturnValue( Object result ) { // warning private void except() { - java.util.ArrayList arrlist = new java.util.ArrayList( 5 ); // warning - arrlist.add( 20); // warning - arrlist.add(15 ); // warning - arrlist.add( 30 ); // warning + java.util.ArrayList arrlist = new java.util.ArrayList( 5 ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + arrlist.add( 20); // violation ''(' is followed by whitespace.' + arrlist.add(15 ); // violation '')' is preceded with whitespace.' + arrlist.add( 30 ); + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' arrlist.add(45); try { - ( arrlist ).remove( 2); // warning - } catch ( IndexOutOfBoundsException x ) { // warning + ( arrlist ).remove( 2); + // 3 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // ''(' is followed by whitespace.' + } catch ( IndexOutOfBoundsException x ) { + // 2 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' x.getMessage(); } - org.junit.Assert.assertThat( "123", org.hamcrest.CoreMatchers.is( "123" ) ); // warning - org.junit.Assert.assertThat( "Help! Integers don't work", // warning - 0, org.hamcrest.CoreMatchers.is( 1 ) ); // warning + org.junit.Assert.assertThat( "123", org.hamcrest.CoreMatchers.is( "123" ) ); + // 4 violations above: + // ''(' is followed by whitespace.' + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' + org.junit.Assert.assertThat( "Help! Integers don't work", + // violation above ''(' is followed by whitespace.' + 0, org.hamcrest.CoreMatchers.is( 1 ) ); + // 3 violations above: + // ''(' is followed by whitespace.' + // '')' is preceded with whitespace.' + // '')' is preceded with whitespace.' } private void tryWithResources() throws Exception { - try (AutoCloseable a = null) {} // ok - try (AutoCloseable a = null; AutoCloseable b = null) {} // ok - try (AutoCloseable a = null; AutoCloseable b = null; ) {} // ok - try (AutoCloseable a = null; AutoCloseable b = null; ) {} // ok - try (AutoCloseable a = null ) {} // warning - try (AutoCloseable a = null; AutoCloseable b = null ) {} // warning + try (AutoCloseable a = null) { } // ok + try (AutoCloseable a = null; AutoCloseable b = null) { } // ok + try (AutoCloseable a = null; AutoCloseable b = null; ) { } // ok + try (AutoCloseable a = null; AutoCloseable b = null; ) { } // ok + try (AutoCloseable a = null ) { } // violation '')' is preceded with whitespace.' + try (AutoCloseable a = null; AutoCloseable b = null ) { } + // violation above '')' is preceded with whitespace.' } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java index 423f3013da0..7f98e650af9 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterBad.java @@ -1,51 +1,102 @@ package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; public class InputWhitespaceAfterBad { - public void check1(int x,int y){ //warn - for(int a=1,b=2;a<5;a++,b--); // warn - while(x==0){ // warn - int a=0,b=1; // warn + public void check1(int x,int y) { // violation '',' is not followed by whitespace.' + for(int a = 1,b = 2;a < 5;a++,b--); + // 6 violations above: + // ''for' is not followed by whitespace.' + // ''for' is not followed by whitespace.' + // '',' is not followed by whitespace.' + // '';' is not followed by whitespace.' + // '';' is not followed by whitespace.' + // '',' is not followed by whitespace.' + while(x == 0) { + // 2 violations above: + // ''while' is not followed by whitespace.' + // ''while' is not followed by whitespace.' + int a = 0,b = 1; // violation '',' is not followed by whitespace.' } - do{ // warn + do{ + // 3 violations above: + // ''do' is not followed by whitespace.' + // ''do' is not followed by whitespace.' + // ''{' is not preceded with whitespace.' System.out.println("Testing"); - }while(x==0||y==2); // warn + } while(x == 0 || y == 2); + // 2 violations above: + // ''while' is not followed by whitespace.' + // ''while' is not followed by whitespace.' } - public void check2(final int a,final int b){ // warn - if((float)a==0.0){ // warn + public void check2(final int a,final int b) { // violation '',' is not followed by whitespace.' + if((float)a == 0.0) { + // 3 violations above: + // ''if' is not followed by whitespace.' + // ''if' is not followed by whitespace.' + // ''typecast' is not followed by whitespace.' System.out.println("true"); } - else{ //warn + else{ + // 3 violations above: + // ''else' is not followed by whitespace.' + // ''else' is not followed by whitespace.' + // ''{' is not preceded with whitespace.' System.out.println("false"); } } - public void check3 (int...a) { // warn - Runnable r2 = () ->String.valueOf("Hello world two!"); // warn - switch(a[0]) { // warn + public void check3(int...a) { // violation ''...' is not followed by whitespace.' + Runnable r2 = () ->String.valueOf("Hello world two!"); + // 2 violations above: + // ''->' is not followed by whitespace.' + // ''->' is not followed by whitespace.' + switch(a[0]) { + // 2 violations above: + // ''switch' is not followed by whitespace.' + // ''switch' is not followed by whitespace.' default: break; } } public void check4() throws java.io.IOException { - try(java.io.InputStream ignored = System.in;) { } // warn + try(java.io.InputStream ignored = System.in;) { } + // 2 violations above: + // ''try' is not followed by whitespace.' + // ''try' is not followed by whitespace.' } public void check5() { - try {} finally{} // warn - try {} catch (Exception e){} finally{} // warn + try { } finally{ } + // 3 violations above: + // ''finally' is not followed by whitespace.' + // ''finally' is not followed by whitespace.' + // ''{' is not preceded with whitespace.' + try { } catch (Exception e) { } finally{ } + // 3 violations above: + // ''finally' is not followed by whitespace.' + // ''finally' is not followed by whitespace.' + // ''{' is not preceded with whitespace.' } public void check6() { - try {} catch(Exception e){} // warn + try { } catch(Exception e) { } + // 2 violations above: + // ''catch' is not followed by whitespace.' + // ''catch' is not followed by whitespace.' } public void check7() { - synchronized(this) { } // warn + synchronized(this) { } + // 2 violations above: + // ''synchronized' is not followed by whitespace.' + // ''synchronized' is not followed by whitespace.' synchronized (this) { } } public String check8() { - return("a" + "b"); // warn + return("a" + "b"); + // 2 violations above: + // ''return' is not followed by whitespace.' + // ''return' is not followed by whitespace.' } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java index be004d42b2e..8967c17e0a9 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAfterGood.java @@ -1,17 +1,22 @@ package com.google.checkstyle.test.chapter4formatting.rule462horizontalwhitespace; public class InputWhitespaceAfterGood { - public void check1(int x, int y){ - for (int a=1, b=2; a<5; a++, b--); - while (x==0){ - int a=0, b=1; + + int xyz; // multiple space between content and double slash. + int abc; // multiple space between double slash and comment's text. + int pqr; // testing both. + + public void check1(int x, int y) { + for (int a = 1, b = 2; a < 5; a++, b--); + while (x == 0) { + int a = 0, b = 1; } do { System.out.println("Testing"); - }while (x==0||y==2); + } while (x == 0 || y == 2); } - public void check2(final int a, final int b){ - if ((float) a==0.0){ + public void check2(final int a, final int b) { + if ((float) a == 0.0) { System.out.println("true"); } else { @@ -28,17 +33,17 @@ public void check3(int... a) { } public void check4() throws java.io.IOException { - try (java.io.InputStream ignored = System.in) {} - try {} catch (Exception e){} + try (java.io.InputStream ignored = System.in) { } + try { } catch (Exception e) { } } public void check5() { - try {} finally {} - try {} catch (Exception e){} finally {} + try { } finally { } + try { } catch (Exception e) { } finally { } } public void check6() { - try {} catch (Exception e){} + try { } catch (Exception e) { } } public void check7() { diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundBasic.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundBasic.java index b89ffaef503..bbca78ddfab 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundBasic.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundBasic.java @@ -6,33 +6,37 @@ **/ class InputWhitespaceAroundBasic { - /** warn **/ - private int mVar1= 1; // warn - /** warn **/ - private int mVar2 =1; // warn + private int mVar1= 1; // violation ''=' is not preceded with whitespace.' + private int mVar2 =1; // violation ''=' is not followed by whitespace.' /** Should be ok **/ private int mVar3 = 1; + int xyz; // multiple space between content and double slash. + int abc; // multiple space between double slash and comment's text. + int pqr; // testing both. /** method **/ void method1() { final int a = 1; - int b= 1; // warn - b= 1; // warn - b +=1; // warn - b -=- 1 + (+ b); // warn - b = b ++ + b --; // ok + int b= 1; // violation ''=' is not preceded with whitespace.' + b= 1; // violation ''=' is not preceded with whitespace.' + b +=1; // violation ''.*' is not followed by whitespace.' + b -=- 1 + (+ b); // violation ''-=' is not followed by whitespace.' + b = b++ + b--; // ok b = ++ b - -- b; // ok } /** method **/ void method2() { - synchronized(this) { //warn + synchronized(this) { + // 2 violations above: + // ''synchronized' is not followed by whitespace.' + // ''synchronized' is not followed by whitespace.' } - try {//warn + try {// violation ''{' is not followed by whitespace.' } - catch (RuntimeException e) {//warn + catch (RuntimeException e) {// violation ''{' is not followed by whitespace.' } } @@ -49,7 +53,10 @@ void method2() private void fastExit() { boolean complicatedStuffNeeded = true; - if( !complicatedStuffNeeded) //warn + if(!complicatedStuffNeeded) + // 2 violations above: + // ''if' is not followed by whitespace.' + // ''if' is not followed by whitespace.' { return; // should not complain about missing WS after return } @@ -65,9 +72,12 @@ private void fastExit() */ private int nonVoid() { - if ( true ) + if (true) { - return(2); // //warn + return(2); + // 2 violations above: + // ''return' is not followed by whitespace.' + // ''return' is not followed by whitespace.' } else { @@ -79,7 +89,7 @@ private int nonVoid() private void testCasts() { Object o = (Object) new Object(); // ok - o = (Object)o; // ok + o = (Object) o; // ok o = ( Object ) o; // ok o = (Object) o; // ok @@ -89,13 +99,13 @@ private void testCasts() private void testQuestions() { - boolean b = (1 ==2) ? false : true; //warn + boolean b = (1 ==2) ? false : true; // violation ''==' is not followed by whitespace.' } /** star test **/ private void starTest() { - int x = 2 * 3* 4; //warn + int x = 2 * 3* 4; // violation ''*' is not preceded with whitespace.' } /** boolean test **/ @@ -110,24 +120,24 @@ private void boolTest() private void divTest() { int a = 4 % 2; - int b = 4% 2;//warn - int c = 4 %2;//warn - int d = 4% 2;//warn + int b = 4% 2; // violation ''%' is not preceded with whitespace.' + int c = 4 %2; // violation ''%' is not followed by whitespace.' + int d = 4% 2; // violation ''%' is not preceded with whitespace.' int e = 4 / 2; - int f = 4/ 2;//warn - int g = 4 /2;//warn + int f = 4/ 2; // violation ''/' is not preceded with whitespace.' + int g = 4 /2; // violation ''/' is not followed by whitespace.' } /** @return dot test **/ - private java .lang. String dotTest() + private java.lang. String dotTest() { Object o = new java.lang.Object(); o. toString(); o .toString(); - o . toString(); + o. toString(); return o.toString(); } @@ -144,10 +154,10 @@ public void assertTest() assert "OK".equals(null) ? false : true : "Whups"; // missing WS around assert - assert(true);//warn + assert(true); // violation ''assert' is not followed by whitespace.' // missing WS around colon - assert true: "Whups";//warn + assert true: "Whups"; // violation '':' is not preceded with whitespace.' } /** another check */ @@ -167,27 +177,21 @@ public void run() { /** rfe 521323, detect whitespace before ';' */ void rfe521323() { - doStuff() ; - // ^ whitespace - for (int i = 0 ; i < 5; i++) { - // ^ whitespace + doStuff(); + for (int i = 0; i < 5; i++) { } } /** bug 806243 (NoWhitespaceBeforeCheck violation for anonymous inner class) */ - private int i ; - // ^ whitespace - private int i1, i2, i3 ; - // ^ whitespace + private int i; private int i4, i5, i6; /** bug 806243 (NoWhitespaceBeforeCheck violation for anonymous inner class) */ void bug806243() { Object o = new InputWhitespaceAroundBasic() { - private int j ; - // ^ whitespace + private int j; }; } @@ -202,8 +206,7 @@ void doStuff() { */ interface IFoo { - void foo() ; - // ^ whitespace + void foo(); } /** @@ -223,7 +226,7 @@ void forIterator() // bug 895072 // avoid conflict between ParenPad(space) and NoWhiteSpace before ';' int i = 0; - for ( ; i < 5; i++ ) { + for ( ; i < 5; i++) { // ^ whitespace } for (int anInt : getSomeInts()) { @@ -232,15 +235,18 @@ void forIterator() } int[] getSomeInts() { - int i = (int) ( 2 / 3 ); + int i = (int) (2 / 3); return null; } void forColon() { int ll[] = new int[10]; - for (int x:ll) {} // warn - for (int x :ll) {} // warn - for (int x: ll) {} // warn + for (int x:ll) {} + // 2 violations above: + // '':' is not followed by whitespace.' + // '':' is not preceded with whitespace.' + for (int x :ll) {} // violation '':' is not followed by whitespace.' + for (int x: ll) {} // violation '':' is not preceded with whitespace.' for (int x : ll) {} // ok } } @@ -254,15 +260,18 @@ class NewGoogleOperators { Runnable l; - l = ()-> { }; //warn - l = () ->{ }; //warn + l = ()-> { }; // violation ''->' is not preceded with whitespace.' + l = () ->{ }; + // 2 violations above: + // ''->' is not followed by whitespace.' + // ''->' is not followed by whitespace.' l = () -> { }; //ok l = () -> {}; //ok - java.util.Arrays.sort(null, String :: compareToIgnoreCase); + java.util.Arrays.sort(null, String:: compareToIgnoreCase); java.util.Arrays.sort(null, String::compareToIgnoreCase); new Object().toString(); - new Object() . toString(); + new Object(). toString(); } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundGenerics.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundGenerics.java index f7c7a8a0fa6..67fe0055ee1 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundGenerics.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule462horizontalwhitespace/InputWhitespaceAroundGenerics.java @@ -9,15 +9,35 @@ public class InputWhitespaceAroundGenerics } //No whitespace after commas -class BadCommas < A,B,C extends Map < A,String > > //warn +class BadCommas < A, B, C extends Map < A, String > > +// 7 violations above: +// ''\<' is followed by whitespace.' +// ''\<' is preceded with whitespace.' +// ''\<' is followed by whitespace.' +// ''\<' is preceded with whitespace.' +// ''\>' is followed by whitespace.' +// ''\>' is preceded with whitespace.' +// ''\>' is preceded with whitespace.' { - private java.util.Hashtable < Integer, D > p = //warn - new java.util.Hashtable < Integer, D > (); //warn + private java.util.Hashtable < Integer, D > p = + // 3 violations above: + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' + new java.util.Hashtable < Integer, D >(); + // 3 violations above: + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' } class Wildcard { - public static void foo(Collection < ? extends Wildcard[] > collection) { //warn + public static void foo(Collection < ? extends Wildcard[] > collection) { + // 3 violations above: + // ''\<' is followed by whitespace.' + // ''\<' is preceded with whitespace.' + // ''\>' is preceded with whitespace.' // A statement is important in this method to flush out any // issues with parsing the wildcard in the signature collection.size(); 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 f6d2ab7a97d..ecc9b0373f2 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/XdocsPagesTest.java @@ -231,7 +231,6 @@ public class XdocsPagesTest { // This list will be removed once all the sections are migrated. // until https://github.com/checkstyle/checkstyle/issues/14937 private static final Set PER_MODULE_TESTS_RULES_LIST = Set.of( - "4.6.2 Horizontal whitespace", "4.8.5 Annotations", "7.3.1 Exception: self-explanatory methods", "7.3.2 Exception: overrides" diff --git a/src/xdocs/google_style.xml b/src/xdocs/google_style.xml index 2818e07ea20..060cb334c8d 100644 --- a/src/xdocs/google_style.xml +++ b/src/xdocs/google_style.xml @@ -948,7 +948,7 @@ - + 4.6.2 Horizontal whitespace @@ -1009,42 +1009,25 @@ config
- - test -
config
- - test -
config
- - test -
config
- - test -
config
- - test -
config
- - test config
- + test