Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12145: corrected tokens so all are required #12146

Merged
merged 1 commit into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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