Skip to content

Commit

Permalink
Issue checkstyle#12145: corrected tokens so all are required
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Sep 10, 2022
1 parent b61f11a commit b90ffb0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 40 deletions.
Expand Up @@ -128,14 +128,6 @@
* Type is {@code boolean}.
* Default value is {@code false}.
* </li>
* <li>
* Property {@code tokens} - tokens to check
* Type is {@code java.lang.String[]}.
* Validation type is {@code tokenSet}.
* Default value is:
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_IMPORT">
* STATIC_IMPORT</a>.
* </li>
* </ul>
* <p>
* To configure the check:
Expand Down Expand Up @@ -773,17 +765,17 @@ public void setUseContainerOrderingForStatic(boolean useContainerOrdering) {

@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
return getRequiredTokens();
}

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

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

@Override
Expand Down
Expand Up @@ -91,12 +91,6 @@
<description>control whether to use container
ordering (Eclipse IDE term) for static imports or not.</description>
</property>
<property default-value="STATIC_IMPORT"
name="tokens"
type="java.lang.String[]"
validation-type="tokenSet">
<description>tokens to check</description>
</property>
</properties>
<message-keys>
<message-key key="import.groups.separated.internally"/>
Expand Down
Expand Up @@ -43,6 +43,21 @@ protected String getPackageLocation() {
return "com/puppycrawl/tools/checkstyle/checks/imports/importorder";
}

@Test
public void testGetTokens() {
final ImportOrderCheck checkObj = new ImportOrderCheck();
final int[] expected = {TokenTypes.IMPORT, TokenTypes.STATIC_IMPORT};
assertWithMessage("Default tokens differs from expected")
.that(checkObj.getDefaultTokens())
.isEqualTo(expected);
assertWithMessage("Acceptable tokens differs from expected")
.that(checkObj.getAcceptableTokens())
.isEqualTo(expected);
assertWithMessage("Required tokens differs from expected")
.that(checkObj.getRequiredTokens())
.isEqualTo(expected);
}

/* Additional test for jacoco, since valueOf()
* is generated by javac and jacoco reports that
* valueOf() is uncovered.
Expand Down Expand Up @@ -303,6 +318,8 @@ public void testGetGroupNumber() throws Exception {
@Test
public void testHonorsTokenProperty() throws Exception {
final String[] expected = {
"20:1: " + getCheckMessage(MSG_ORDERING, "java.awt.Button.ABORT"),
"21:1: " + getCheckMessage(MSG_ORDERING, "java.awt.Dialog"),
"22:1: " + getCheckMessage(MSG_ORDERING, "java.awt.Button"),
};

Expand Down
Expand Up @@ -9,17 +9,17 @@
staticGroups = (default)
sortStaticImportsAlphabetically = (default)false
useContainerOrderingForStatic = (default)false
tokens = IMPORT
*/

package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE; // ok
import static java.awt.Button.ABORT; // ok
import java.awt.Dialog; // ok
import java.awt.Button; // violation
import static java.awt.Button.ABORT; // violation 'Wrong order for 'java.awt.Button.ABORT' import.'
import java.awt.Dialog; // violation 'Wrong order for 'java.awt.Dialog' import.'
import java.awt.Button; // violation 'Wrong order for 'java.awt.Button' import.'

public class InputImportOrder_HonorsTokensProperty {
}
19 changes: 0 additions & 19 deletions src/xdocs/config_imports.xml
Expand Up @@ -1927,25 +1927,6 @@ import java.util.stream.IntStream;
<td><code>false</code></td>
<td>7.1</td>
</tr>

<tr>
<td>tokens</td>
<td>tokens to check</td>

<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_IMPORT">
STATIC_IMPORT</a>
.
</td>

<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#STATIC_IMPORT">
STATIC_IMPORT</a>
.
</td>
<td>3.2</td>
</tr>
</table>
</div>
</subsection>
Expand Down

0 comments on commit b90ffb0

Please sign in to comment.