Fixed 1374792. Now we do not need to look for ident before lparen, we just look at char instead.

This commit is contained in:
Oleg Sukhodolsky 2005-12-07 17:23:04 +00:00
parent a81008fd6f
commit 14172dd01a
5 changed files with 50 additions and 62 deletions

View File

@ -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());
}
}
/**

View File

@ -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()
{

View File

@ -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<String> v = new java.util.Vector<String>();
java.util.Vector<String> v1 = new Vector<String>();
}
}

View File

@ -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);
}

View File

@ -28,6 +28,11 @@
<li>Applied patch from Ralf (rakus) to remove javadoc's
complainings. (patch 1352862)
</li>
Fixed StringIndexOutOfBoundsException which MethodParamPad may
throws if someone tries to create object of generic class
(with any params) (bug 1374792).
<li>
</li>
</ul>
</section>