To configure the check so that it matches default IntelliJ IDEA formatter
+ * configuration (tested on v14):
+ *
+ *
group of static imports is on the bottom
+ *
groups of non-static imports: all imports except of "javax"
+ * and "java", then "javax" and "java"
+ *
imports will be sorted in the groups
+ *
groups are separated by, at least, one blank line
+ *
+ *
+ *
+ * Note: "separated" option is disabled because IDEA default has blank line
+ * between "java" and static imports, and no blank line between
+ * "javax" and "java"
+ *
policy on the relative order between regular imports and static
+ * imports
{@link ImportOrderOption}
under
+ *
groups
list of imports groups (every group identified either by a common
+ * prefix string, or by a regular expression enclosed in forward slashes (e.g. /regexp/)
+ *
list of strings
empty list
+ *
ordered
whether imports within group should be sorted
+ *
Boolean
true
+ *
separated
whether imports groups should be separated by, at least,
+ * one blank line
Boolean
false
+ *
caseSensitive
whether string comparison should be case sensitive or not.
+ * Case sensitive sorting is in ASCII sort order
Boolean
true
+ *
sortStaticImportsAlphabetically
whether static imports grouped by top or
+ * bottom option are sorted alphabetically or not
Boolean
false
+ *
+ *
*
* Example:
*
+ *
To configure the check so that it matches default Eclipse formatter configuration
+ * (tested on Kepler, Luna and Mars):
+ *
+ *
group of static imports is on the top
+ *
groups of non-static imports: "java" then "javax"
+ * packages first, then "org" and then all other imports
To configure the check so that it matches default IntelliJ IDEA formatter configuration
+ * (tested on v14):
+ *
+ *
group of static imports is on the bottom
+ *
groups of non-static imports: all imports except of "javax" and
+ * "java", then "javax" and "java"
+ *
imports will be sorted in the groups
+ *
groups are separated by, at least, one blank line
+ *
+ *
+ *
+ * Note: "separated" option is disabled because IDEA default has blank line
+ * between "java" and static imports, and no blank line between
+ * "javax" and "java"
+ *
* Check also has on option making it more flexible:
* sortStaticImportsAlphabetically - sets whether static imports grouped by
* top or bottom option should be sorted alphabetically or
diff --git a/src/xdocs/config_imports.xml b/src/xdocs/config_imports.xml
index e9805c86f..f75e258c2 100644
--- a/src/xdocs/config_imports.xml
+++ b/src/xdocs/config_imports.xml
@@ -393,6 +393,10 @@ class FooBar {
regular imports and static imports (see
import orders)
+
+ Examples section contains examples that
+ work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans
+
@@ -453,34 +457,71 @@ class FooBar {
-
-
To configure the check so that it requires that:
+
+
To configure the check so that it matches default Eclipse formatter configuration (tested on Kepler, Luna and Mars):
-
"java" and "javax" packages together first, then "org" and then all other imports
+
group of static imports is on the top
+
groups of non-static imports: "java" then "javax" packages first, then "org" and then all other imports
To configure the check so that it matches default IntelliJ IDEA formatter configuration (tested on v14):
+
+
group of static imports is on the bottom
+
groups of non-static imports: all imports except of "javax" and "java", then "javax" and "java"
+
imports will be sorted in the groups
+
groups are separated by, at least, one blank line
+
+
+
+ Note: "separated" option is disabled because IDEA default has blank line
+ between "java" and static imports, and no blank line between
+ "javax" and "java"
+
To configure the Check allows static imports grouped to the top
being sorted alphabetically:
-<module name="ImportOrder">
- <property name="sortStaticImportsAlphabetically" value="true"/>
- <property name="option" value="top"/>
-</module>
+<module name="ImportOrder">
+ <property name="sortStaticImportsAlphabetically" value="true"/>
+ <property name="option" value="top"/>
+</module>
@@ -572,7 +613,7 @@ public class SomeClass { ... }
<module name="ImportControl">
- <property name="file" value="import-control.xml"/>
+ <property name="file" value="import-control.xml"/>
</module>
@@ -584,9 +625,9 @@ public class SomeClass { ... }
<import-control pkg="com.puppycrawl.tools.checkstyle">
- <allow class="java\.awt\.I.*" regex="true"/>
+ <allow class="java\.awt\.I.*" regex="true"/>
<allow class="java\.io\.(File|InputStream)" local-only="true"
- regex="true"/>
+ regex="true"/>
</import-control>
@@ -617,6 +658,10 @@ public class SomeClass { ... }
by the user. If there is an import but its group is not specified in the
configuration such an import should be placed at the end of the import list.
+
+ Examples section contains examples that
+ work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans
+
@@ -720,7 +765,59 @@ public class SomeClass { ... }
-
+
+
To configure the check so that it matches default Eclipse formatter configuration (tested on Kepler, Luna and Mars):
+
+
group of static imports is on the top
+
groups of non-static imports: "java" and "javax" packages first, then "org" and then all other imports
To configure the check so that it matches default IntelliJ IDEA formatter configuration (tested on v14):
+
+
group of static imports is on the bottom
+
groups of non-static imports: all imports except of "javax" and "java", then "javax" and "java"
+
imports will be sorted in the groups
+
groups are separated by, at least, one blank line
+
+
+
+ Note: "separated" option is disabled because IDEA default has blank line
+ between "java" and static imports, and no blank line between
+ "javax" and "java"
+
To configure the check so that it matches default NetBeans formatter configuration (tested on v8):
+
+
groups of non-static imports are not defined, all imports will be sorted as a one group
+
static imports are not separated, they will be sorted along with other imports
+
+
+
+<module name="CustomImportOrder"/>
+
+
To set RegExps for THIRD_PARTY_PACKAGE and STANDARD_JAVA_PACKAGE groups use
thirdPartyPackageRegExp and standardPackageRegExp options.
@@ -728,7 +825,7 @@ public class SomeClass { ... }
<module name="CustomImportOrder">
<property name="customImportOrderRules"
- value="STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
+ value="STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
<property name="thirdPartyPackageRegExp" value="com|org"/>
<property name="standardPackageRegExp" value="^(java|javax)\."/>
</module>