Skip to content

Commit

Permalink
Issue checkstyle#4981: ImportOrder with order=bottom should disallow …
Browse files Browse the repository at this point in the history
…non-static import after a static import
  • Loading branch information
julianhyde committed Sep 20, 2017
1 parent f804efa commit 0768bce
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ else if (option == ImportOrderOption.BOTTOM) {
}
doVisitToken(ident, isStatic, isLastImportAndNonStatic);

if (isLastImportAndNonStatic) {
log(ident.getLineNo(), MSG_ORDERING, ident.getText());
}

}
else if (option == ImportOrderOption.ABOVE) {
// previous non-static but current is static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ public void testStaticGroupsAlphabeticalOrderBottom() throws Exception {
verify(checkConfig, getPath("InputImportOrderStaticGroupOrderBottom.java"), expected);
}

@Test
public void testStaticGroupsAlphabeticalOrderBottomNegative() throws Exception {
final DefaultConfiguration checkConfig =
createModuleConfig(ImportOrderCheck.class);
checkConfig.addAttribute("option", "bottom");
checkConfig.addAttribute("groups", "org, java");
checkConfig.addAttribute("sortStaticImportsAlphabetically", "true");
final String[] expected = {
"8: " + getCheckMessage(MSG_ORDERING, "java.util.Set"),
};
verify(checkConfig, getPath("InputImportOrderStaticGroupOrderBottom_Negative.java"),
expected);
}

@Test
public void testStaticGroupsOrderBottom() throws Exception {
final DefaultConfiguration checkConfig =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.puppycrawl.tools.checkstyle.checks.imports.importorder;

import org.*;

import static java.lang.Math.PI;
import static org.antlr.v4.runtime.Recognizer.EOF;

import java.util.Set;

public class InputImportOrderStaticGroupOrderBottom_Negative
{

}

0 comments on commit 0768bce

Please sign in to comment.