forked from checkstyle/checkstyle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3e98e5
commit 6bb86e8
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code for adherence to a set of rules. | ||
// Copyright (C) 2001-2014 Oliver Burn | ||
// | ||
// 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.puppycrawl.tools.checkstyle.checks.whitespace; | ||
|
||
import com.puppycrawl.tools.checkstyle.api.Check; | ||
import com.puppycrawl.tools.checkstyle.api.DetailAST; | ||
import com.puppycrawl.tools.checkstyle.api.TokenTypes; | ||
import com.puppycrawl.tools.checkstyle.api.Utils; | ||
|
||
public class SeparatorWrapCheck extends Check | ||
{ | ||
|
||
@Override | ||
public int[] getDefaultTokens() | ||
{ | ||
return new int[] { | ||
TokenTypes.TYPE_EXTENSION_AND, | ||
TokenTypes.DOT, | ||
TokenTypes.COMMA, | ||
}; | ||
} | ||
|
||
@Override | ||
public void visitToken(DetailAST aAST) | ||
{ | ||
final String text = aAST.getText(); | ||
final int colNo = aAST.getColumnNo(); | ||
final int lineNo = aAST.getLineNo(); | ||
final String currentLine = getLines()[lineNo-1]; | ||
|
||
if ( !text.equals(currentLine.trim()) && | ||
(currentLine.substring(colNo + text.length()). | ||
trim().length() != 0) && | ||
Utils.whitespaceBefore(colNo - 1, currentLine)) | ||
{ | ||
log(lineNo, colNo, "line.previous", text); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/com/puppycrawl/tools/checkstyle/checks/whitespace/SeparatorWrapCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// checkstyle: Checks Java source code for adherence to a set of rules. | ||
// Copyright (C) 2001-2014 Oliver Burn | ||
// | ||
// 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.puppycrawl.tools.checkstyle.checks.whitespace; | ||
|
||
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; | ||
import com.puppycrawl.tools.checkstyle.DefaultConfiguration; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class SeparatorWrapCheckTest | ||
extends BaseCheckTestSupport | ||
{ | ||
private DefaultConfiguration checkConfig; | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
checkConfig = createCheckConfig(SeparatorWrapCheck.class); | ||
} | ||
|
||
@Test | ||
public void testDefault() | ||
throws Exception | ||
{ | ||
final String[] expected = { | ||
"25:11: '&' should be on the previous line.", | ||
"30:9: '.' should be on the previous line.", | ||
"37:25: ',' should be on the previous line.", | ||
}; | ||
verify(checkConfig, getPath("whitespace/InputSeparatorWrap.java"), expected); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/resources/com/puppycrawl/tools/checkstyle/whitespace/InputSeparatorWrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.puppycrawl.tools.checkstyle.whitespace; | ||
|
||
public class InputSeparatorWrap<T extends Foo & | ||
Bar> { | ||
public void goodCase() | ||
{ | ||
int i = 0; | ||
String s = "ffffooooString"; | ||
s. | ||
isEmpty(); | ||
try { | ||
|
||
} catch (FooException | | ||
BarException e) {} | ||
foo(i, | ||
s); | ||
} | ||
public static void foo(int i, String s) | ||
{ | ||
|
||
} | ||
} | ||
|
||
class badCase<T extends Foo | ||
& Bar> { | ||
public void goodCase() | ||
{ | ||
String s = "ffffooooString"; | ||
s | ||
.isEmpty(); | ||
try { | ||
|
||
} catch (FooException | ||
| BarException e) {} | ||
|
||
foo(i | ||
, s); | ||
} | ||
public static void foo(int i, String s) | ||
{ | ||
|
||
} | ||
} |