Skip to content

Commit

Permalink
SeparatorWrapCheck #10
Browse files Browse the repository at this point in the history
  • Loading branch information
maxvetrenko committed Jun 29, 2014
1 parent c3e98e5 commit 6bb86e8
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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)
{

}
}

0 comments on commit 6bb86e8

Please sign in to comment.