From 14172dd01adff4bc99296f633c4acad32e3d570f Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Wed, 7 Dec 2005 17:23:04 +0000 Subject: [PATCH] Fixed 1374792. Now we do not need to look for ident before lparen, we just look at char instead. --- .../whitespace/MethodParamPadCheck.java | 44 ++++---------- .../tools/checkstyle/InputSimple.java | 2 +- .../whitespace/InputMethodParamPad.java | 4 +- .../whitespace/MethodParamPadCheckTest.java | 57 ++++++++++--------- src/xdocs/releasenotes.xml | 5 ++ 5 files changed, 50 insertions(+), 62 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheck.java index fcf4cc5dd..4b6c73b90 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheck.java @@ -20,6 +20,7 @@ package com.puppycrawl.tools.checkstyle.checks.whitespace; import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.api.Utils; import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck; /** @@ -102,47 +103,26 @@ public class MethodParamPadCheck return; } } - int parenColumnNo = parenAST.getColumnNo(); - final String[] lines = getLines(); - int identLineNo = -1; - int identColumnNo = -1; - final String identText; - final DetailAST identAST; - final DetailAST dotAST = aAST.findFirstToken(TokenTypes.DOT); - if (dotAST != null) { - identAST = dotAST.getLastChild(); - } - else if (aAST.getType() == TokenTypes.SUPER_CTOR_CALL) { - identAST = aAST; + + final String line = getLines()[parenAST.getLineNo() - 1]; + if (Utils.whitespaceBefore(parenAST.getColumnNo(), line)) { + if (!mAllowLineBreaks) { + log(parenAST, "line.previous", parenAST.getText()); + } } else { - identAST = aAST.findFirstToken(TokenTypes.IDENT); - } - identLineNo = identAST.getLineNo(); - identColumnNo = identAST.getColumnNo(); - identText = identAST.getText(); - - if (identLineNo == parenAST.getLineNo()) { - final int after = identColumnNo + identText.length(); - final String line = lines[identLineNo - 1]; + final int before = parenAST.getColumnNo() - 1; if ((PadOption.NOSPACE == getAbstractOption()) - && (Character.isWhitespace(line.charAt(after)))) + && (Character.isWhitespace(line.charAt(before)))) { - log(identLineNo, after, "ws.followed", identText); + log(parenAST , "ws.preceded", parenAST.getText()); } else if ((PadOption.SPACE == getAbstractOption()) - && !Character.isWhitespace(line.charAt(after))) + && !Character.isWhitespace(line.charAt(before))) { - log(identLineNo, after, "ws.notFollowed", identText); + log(parenAST, "ws.notPreceded", parenAST.getText()); } } - else if (!mAllowLineBreaks) { - log( - parenAST.getLineNo(), - parenColumnNo, - "line.previous", - parenAST.getText()); - } } /** diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/InputSimple.java b/src/testinputs/com/puppycrawl/tools/checkstyle/InputSimple.java index 9c29e4ce1..d3aa0242f 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/InputSimple.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/InputSimple.java @@ -144,7 +144,7 @@ final class InputSimple // A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$" // long line that has a tab -> <- and would be OK if tab counted as 1 char // tabs that count as one char because of their position -> <- -> <-, OK - + /** some lines to test the error column after tabs */ void errorColumnAfterTabs() { diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/whitespace/InputMethodParamPad.java b/src/testinputs/com/puppycrawl/tools/checkstyle/whitespace/InputMethodParamPad.java index 2e97338dc..7b9f9804d 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/whitespace/InputMethodParamPad.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/whitespace/InputMethodParamPad.java @@ -1,5 +1,5 @@ package com.puppycrawl.tools.checkstyle.whitespace; - +import java.util.Vector; /** Test input for MethodDefPadCheck */ public class InputMethodParamPad { @@ -66,5 +66,7 @@ public class InputMethodParamPad public void newArray() { int[] a = new int[]{0, 1}; + java.util.Vector v = new java.util.Vector(); + java.util.Vector v1 = new Vector(); } } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java index 67e4af5fc..3630a6000 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/whitespace/MethodParamPadCheckTest.java @@ -16,21 +16,21 @@ public class MethodParamPadCheckTest public void testDefault() throws Exception { final String[] expected = { - "11:31: 'InputMethodParamPad' is followed by whitespace.", - "13:14: 'super' is followed by whitespace.", + "11:32: '(' is preceded with whitespace.", + "13:15: '(' is preceded with whitespace.", "17:9: '(' should be on the previous line.", "20:13: '(' should be on the previous line.", - "27:23: 'method' is followed by whitespace.", + "27:24: '(' is preceded with whitespace.", "32:9: '(' should be on the previous line.", - "36:38: 'InputMethodParamPad' is followed by whitespace.", + "36:39: '(' is preceded with whitespace.", "38:13: '(' should be on the previous line.", - "42:15: 'method' is followed by whitespace.", + "42:16: '(' is preceded with whitespace.", "44:13: '(' should be on the previous line.", - "50:20: 'method' is followed by whitespace.", + "50:21: '(' is preceded with whitespace.", "52:13: '(' should be on the previous line.", - "56:17: 'method' is followed by whitespace.", + "56:18: '(' is preceded with whitespace.", "58:13: '(' should be on the previous line.", - "61:35: 'parseInt' is followed by whitespace.", + "61:36: '(' is preceded with whitespace.", "63:13: '(' should be on the previous line.", }; verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected); @@ -40,14 +40,14 @@ public class MethodParamPadCheckTest { checkConfig.addAttribute("allowLineBreaks", "true"); final String[] expected = { - "11:31: 'InputMethodParamPad' is followed by whitespace.", - "13:14: 'super' is followed by whitespace.", - "27:23: 'method' is followed by whitespace.", - "36:38: 'InputMethodParamPad' is followed by whitespace.", - "42:15: 'method' is followed by whitespace.", - "50:20: 'method' is followed by whitespace.", - "56:17: 'method' is followed by whitespace.", - "61:35: 'parseInt' is followed by whitespace.", + "11:32: '(' is preceded with whitespace.", + "13:15: '(' is preceded with whitespace.", + "27:24: '(' is preceded with whitespace.", + "36:39: '(' is preceded with whitespace.", + "42:16: '(' is preceded with whitespace.", + "50:21: '(' is preceded with whitespace.", + "56:18: '(' is preceded with whitespace.", + "61:36: '(' is preceded with whitespace.", }; verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected); } @@ -56,26 +56,27 @@ public class MethodParamPadCheckTest { checkConfig.addAttribute("option", "space"); final String[] expected = { - "6:31: 'InputMethodParamPad' is not followed by whitespace.", - "8:14: 'super' is not followed by whitespace.", + "6:31: '(' is not preceded with whitespace.", + "8:14: '(' is not preceded with whitespace.", "17:9: '(' should be on the previous line.", "20:13: '(' should be on the previous line.", - "23:23: 'method' is not followed by whitespace.", + "23:23: '(' is not preceded with whitespace.", "32:9: '(' should be on the previous line.", - "35:58: 'InputMethodParamPad' is not followed by whitespace.", + "35:58: '(' is not preceded with whitespace.", "38:13: '(' should be on the previous line.", - "41:15: 'method' is not followed by whitespace.", + "41:15: '(' is not preceded with whitespace.", "44:13: '(' should be on the previous line.", - "47:28: 'dottedCalls' is not followed by whitespace.", - "49:20: 'method' is not followed by whitespace.", + "47:28: '(' is not preceded with whitespace.", + "49:20: '(' is not preceded with whitespace.", "52:13: '(' should be on the previous line.", - "54:56: 'InputMethodParamPad' is not followed by whitespace.", - "55:17: 'method' is not followed by whitespace.", + "54:56: '(' is not preceded with whitespace.", + "55:17: '(' is not preceded with whitespace.", "58:13: '(' should be on the previous line.", - "60:35: 'parseInt' is not followed by whitespace.", + "60:35: '(' is not preceded with whitespace.", "63:13: '(' should be on the previous line.", - "66:25: 'newArray' is not followed by whitespace.", - + "66:25: '(' is not preceded with whitespace.", + "69:66: '(' is not preceded with whitespace.", + "70:57: '(' is not preceded with whitespace.", }; verify(checkConfig, getPath("whitespace/InputMethodParamPad.java"), expected); } diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index 10841b0f8..bcb6749eb 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -28,6 +28,11 @@
  • Applied patch from Ralf (rakus) to remove javadoc's complainings. (patch 1352862)
  • + Fixed StringIndexOutOfBoundsException which MethodParamPad may + throws if someone tries to create object of generic class + (with any params) (bug 1374792). +
  • +