Skip to content

Commit

Permalink
Issue checkstyle#3892: Add TokenTypes.STATIC_IMPORT in NoLineWrapCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
kukreja-vikramaditya authored and GitToasterhub committed Mar 26, 2017
1 parent 9eaee57 commit a002985
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void badLineWrapTest() throws Exception {
final String[] expected = {
"1: " + getCheckMessage(NoLineWrapCheck.class, "no.line.wrap", "package"),
"6: " + getCheckMessage(NoLineWrapCheck.class, "no.line.wrap", "import"),
"10: " + getCheckMessage(NoLineWrapCheck.class, "no.line.wrap", "import"),
};

final Configuration checkConfig = getCheckConfig("NoLineWrap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
AccessibleAttributeSequence;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //ok

import static java.math. //warn
BigInteger.ONE;

public class
InputNoLineWrapBad {

public void
fooMethod() {
final int
Expand All @@ -24,4 +27,3 @@
interface
InterFoo {}


Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.google.checkstyle.test.chapter3filestructure.rule332nolinewrap; //ok

import static java.math.BigInteger.ZERO; //ok

import com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck; //ok

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; //ok
import javax.accessibility.AccessibleAttributeSequence; //ok

public class InputNoLineWrapGood {

public void fooMethod() {
//
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ public class NoLineWrapCheck extends AbstractCheck {

@Override
public int[] getDefaultTokens() {
return new int[] {TokenTypes.PACKAGE_DEF, TokenTypes.IMPORT};
return new int[] {TokenTypes.PACKAGE_DEF, TokenTypes.IMPORT, TokenTypes.STATIC_IMPORT};
}

@Override
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.IMPORT,
TokenTypes.STATIC_IMPORT,
TokenTypes.PACKAGE_DEF,
TokenTypes.CLASS_DEF,
TokenTypes.METHOD_DEF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testDefaultTokensLineWrapping() throws Exception {
final String[] expected = {
"1: " + getCheckMessage(MSG_KEY, "package"),
"6: " + getCheckMessage(MSG_KEY, "import"),
"10: " + getCheckMessage(MSG_KEY, "import"),
};
verify(checkConfig, getPath("InputNoLineWrapBad.java"), expected);
}
Expand All @@ -59,12 +60,14 @@ public void testDefaultTokensLineWrapping() throws Exception {
public void testCustomTokensLineWrapping()
throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(NoLineWrapCheck.class);
checkConfig.addAttribute("tokens", "IMPORT, CLASS_DEF, METHOD_DEF, ENUM_DEF");
checkConfig.addAttribute(
"tokens", "IMPORT, STATIC_IMPORT, CLASS_DEF, METHOD_DEF, ENUM_DEF");
final String[] expected = {
"6: " + getCheckMessage(MSG_KEY, "import"),
"10: " + getCheckMessage(MSG_KEY, "CLASS_DEF"),
"13: " + getCheckMessage(MSG_KEY, "METHOD_DEF"),
"20: " + getCheckMessage(MSG_KEY, "ENUM_DEF"),
"10: " + getCheckMessage(MSG_KEY, "import"),
"13: " + getCheckMessage(MSG_KEY, "CLASS_DEF"),
"16: " + getCheckMessage(MSG_KEY, "METHOD_DEF"),
"23: " + getCheckMessage(MSG_KEY, "ENUM_DEF"),
};
verify(checkConfig, getPath("InputNoLineWrapBad.java"), expected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package com.puppycrawl.tools.
package com.puppycrawl.tools. //violation
checkstyle.checks.whitespace;

import com.puppycrawl.tools.checkstyle.TreeWalker;

import javax.accessibility.
import javax.accessibility. //violation
AccessibleAttributeSequence;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

public class
import static java.math. //violation
BigInteger.ZERO;

public class //violation
InputNoLineWrapBad {

public void
fooMethod() {
final int
foo = 0;
}
}

enum
enum //violation
FooFoo {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import javax.accessibility.AccessibleAttributeSequence;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

import static java.math.BigInteger.ZERO;

public class InputNoLineWrapGood {

public void fooMethod() {
//
}
Expand Down
14 changes: 11 additions & 3 deletions src/xdocs/config_whitespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ sort(list, Comparable::<String>compareTo); // Method reference
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">IMPORT</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_IMPORT">STATIC_IMPORT</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PACKAGE_DEF">PACKAGE_DEF</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>,
Expand All @@ -831,7 +833,9 @@ sort(list, Comparable::&lt;String&gt;compareTo); // Method reference
<td><a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PACKAGE_DEF">PACKAGE_DEF</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">IMPORT</a>.</td>
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">IMPORT</a>,
<a
href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_IMPORT">STATIC_IMPORT</a>.</td>
</tr>
</table>
</subsection>
Expand All @@ -841,11 +845,14 @@ sort(list, Comparable::&lt;String&gt;compareTo); // Method reference
Examples of line-wrapped statements (bad case):
</p>
<source>
package com.puppycrawl.
package com.puppycrawl. //violation
tools.checkstyle.checks;

import com.puppycrawl.tools.
import com.puppycrawl.tools. //violation
checkstyle.api.AbstractCheck;

import static java.math. //violation
BigInteger.ZERO;
</source>
<p>
To configure the check to force no line-wrapping
Expand All @@ -868,6 +875,7 @@ import com.puppycrawl.tools.
</p>
<source>
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import static java.math.BigInteger.ZERO;
</source>
</subsection>

Expand Down

0 comments on commit a002985

Please sign in to comment.