updated Xdoc and Javadoc for ImportOrder and CustomImportOrder #1464

This commit is contained in:
Aleksandr Ivanov 2015-07-25 23:53:59 +03:00 committed by Roman Ivanov
parent c3f9d975a8
commit d91c50c1ae
3 changed files with 272 additions and 33 deletions

View File

@ -93,9 +93,93 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
* </p>
*
* <pre>
* Properties:
* </pre>
* <table summary="Properties" border="1">
* <tr><th>name</th><th>Description</th><th>type</th><th>default value</th></tr>
* <tr><td>customImportOrderRules</td><td>List of order declaration customizing by user.</td>
* <td>string</td><td>null</td></tr>
* <tr><td>standardPackageRegExp</td><td>RegExp for STANDARD_JAVA_PACKAGE group imports.</td>
* <td>regular expression</td><td>^(java|javax)\.</td></tr>
* <tr><td>thirdPartyPackageRegExp</td><td>RegExp for THIRDPARTY_PACKAGE group imports.</td>
* <td>regular expression</td><td>.*</td></tr>
* <tr><td>specialImportsRegExp</td><td>RegExp for SPECIAL_IMPORTS group imports.</td>
* <td>regular expression</td><td>^$</td></tr>
* <tr><td>samePackageMatchingDepth</td><td>Number of first domains for SAME_PACKAGE group.
* </td><td>Integer</td><td>2</td></tr>
* <tr><td>separateLineBetweenGroups</td><td>Force empty line separator between import groups.
* </td><td>boolean</td><td>true</td></tr>
* <tr><td>sortImportsInGroupAlphabetically</td><td>Force grouping alphabetically,
* in ASCII sort order.</td><td>boolean</td><td>false</td></tr>
* </table>
*
* <pre>
* For example:
* </pre>
* <p>To configure the check so that it matches default Eclipse formatter configuration
* (tested on Kepler, Luna and Mars):</p>
* <ul>
* <li>group of static imports is on the top</li>
* <li>groups of non-static imports: &quot;java&quot; and &quot;javax&quot; packages
* first, then &quot;org&quot; and then all other imports</li>
* <li>imports will be sorted in the groups</li>
* <li>groups are separated by, at least, one blank line</li>
* </ul>
* <pre>
* <code>
* &lt;module name=&quot;CustomImportOrder&quot;&gt;
* &lt;property name=&quot;customImportOrderRules&quot;
* value=&quot;STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS&quot;/&gt;
* &lt;property name=&quot;specialImportsRegExp&quot; value=&quot;org&quot;/&gt;
* &lt;property name=&quot;sortImportsInGroupAlphabetically&quot; value=&quot;true&quot;/&gt;
* &lt;property name=&quot;separateLineBetweenGroups&quot; value=&quot;true&quot;/&gt;
* &lt;/module&gt;
* </code>
* </pre>
*
* <p>To configure the check so that it matches default IntelliJ IDEA formatter
* configuration (tested on v14):</p>
* <ul>
* <li>group of static imports is on the bottom</li>
* <li>groups of non-static imports: all imports except of &quot;javax&quot;
* and &quot;java&quot;, then &quot;javax&quot; and &quot;java&quot;</li>
* <li>imports will be sorted in the groups</li>
* <li>groups are separated by, at least, one blank line</li>
* </ul>
*
* <p>
* Note: &quot;separated&quot; option is disabled because IDEA default has blank line
* between &quot;java&quot; and static imports, and no blank line between
* &quot;javax&quot; and &quot;java&quot;
* </p>
*
* <pre>
* <code>
* &lt;module name=&quot;CustomImportOrder&quot;&gt;
* &lt;property name=&quot;customImportOrderRules&quot;
* value=&quot;THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE
* ###STATIC&quot;/&gt;
* &lt;property name=&quot;specialImportsRegExp&quot; value=&quot;^javax\.&quot;/&gt;
* &lt;property name=&quot;standardPackageRegExp&quot; value=&quot;^java\.&quot;/&gt;
* &lt;property name=&quot;sortImportsInGroupAlphabetically&quot; value=&quot;true&quot;/&gt;
* &lt;property name=&quot;separateLineBetweenGroups&quot; value=&quot;false&quot;/&gt;
*&lt;/module&gt;
* </code>
* </pre>
*
* <p>To configure the check so that it matches default NetBeans formatter
* configuration (tested on v8):</p>
* <ul>
* <li>groups of non-static imports are not defined, all imports will be sorted as a one
* group</li>
* <li>static imports are not separated, they will be sorted along with other imports</li>
* </ul>
*
* <code>
*&lt;module name=&quot;CustomImportOrder&quot;/&gt;
* </code>
* <p>To set RegExps for THIRD_PARTY_PACKAGE and STANDARD_JAVA_PACKAGE groups use
* thirdPartyPackageRegExp and standardPackageRegExp options.</p>
* <pre>
* <code>
* &lt;module name=&quot;CustomImportOrder&quot;&gt;

View File

@ -43,17 +43,87 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck;
* like non static imports (@see {@link ImportOrderOption}</li>
* </ul>
*
* <pre>
* Properties:
* </pre>
* <table summary="Properties" border="1">
* <tr><th>name</th><th>Description</th><th>type</th><th>default value</th></tr>
* <tr><td>option</td><td>policy on the relative order between regular imports and static
* imports</td><td>{@link ImportOrderOption}</td><td>under</td></tr>
* <tr><td>groups</td><td>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/)</td>
* <td>list of strings</td><td>empty list</td></tr>
* <tr><td>ordered</td><td>whether imports within group should be sorted</td>
* <td>Boolean</td><td>true</td></tr>
* <tr><td>separated</td><td>whether imports groups should be separated by, at least,
* one blank line</td><td>Boolean</td><td>false</td></tr>
* <tr><td>caseSensitive</td><td>whether string comparison should be case sensitive or not.
* Case sensitive sorting is in ASCII sort order</td><td>Boolean</td><td>true</td></tr>
* <tr><td>sortStaticImportsAlphabetically</td><td>whether static imports grouped by top or
* bottom option are sorted alphabetically or not</td><td>Boolean</td><td>false</td></tr>
* </table>
*
* <p>
* Example:
* </p>
* <p>To configure the check so that it matches default Eclipse formatter configuration
* (tested on Kepler, Luna and Mars):</p>
* <ul>
* <li>group of static imports is on the top</li>
* <li>groups of non-static imports: &quot;java&quot; then &quot;javax&quot;
* packages first, then &quot;org&quot; and then all other imports</li>
* <li>imports will be sorted in the groups</li>
* <li>groups are separated by, at least, one blank line</li>
* </ul>
*
* <pre>
* &lt;module name=&quot;ImportOrder&quot;&gt;
* &lt;property name=&quot;groups&quot; value=&quot;java,javax&quot;/&gt;
* &lt;module name=&quot;ImportOrder&quot;&gt;
* &lt;property name=&quot;groups&quot; value=&quot;/^javax?\./,org&quot;/&gt;
* &lt;property name=&quot;ordered&quot; value=&quot;true&quot;/&gt;
* &lt;property name=&quot;caseSensitive&quot; value=&quot;false&quot;/&gt;
* &lt;property name=&quot;separated&quot; value=&quot;true&quot;/&gt;
* &lt;property name=&quot;option&quot; value=&quot;above&quot;/&gt;
* &lt;/module&gt;
* &lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/&gt;
* &lt;/module&gt;
* </pre>
*
* <p>To configure the check so that it matches default IntelliJ IDEA formatter configuration
* (tested on v14):</p>
* <ul>
* <li>group of static imports is on the bottom</li>
* <li>groups of non-static imports: all imports except of &quot;javax&quot; and
* &quot;java&quot;, then &quot;javax&quot; and &quot;java&quot;</li>
* <li>imports will be sorted in the groups</li>
* <li>groups are separated by, at least, one blank line</li>
* </ul>
*
* <p>
* Note: &quot;separated&quot; option is disabled because IDEA default has blank line
* between &quot;java&quot; and static imports, and no blank line between
* &quot;javax&quot; and &quot;java&quot;
* </p>
*
* <pre>
* &lt;module name=&quot;ImportOrder&quot;&gt;
* &lt;property name=&quot;groups&quot; value=&quot;*,javax,java&quot;/&gt;
* &lt;property name=&quot;ordered&quot; value=&quot;true&quot;/&gt;
* &lt;property name=&quot;separated&quot; value=&quot;false&quot;/&gt;
* &lt;property name=&quot;option&quot; value=&quot;bottom&quot;/&gt;
* &lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/&gt;
* &lt;/module&gt;
* </pre>
*
* <p>To configure the check so that it matches default NetBeans formatter configuration
* (tested on v8):</p>
* <ul>
* <li>groups of non-static imports are not defined, all imports will be sorted
* as a one group</li>
* <li>static imports are not separated, they will be sorted along with other imports</li>
* </ul>
*
* <pre>
* &lt;module name=&quot;ImportOrder&quot;&gt;
* &lt;property name=&quot;option&quot; value=&quot;inflow&quot;/&gt;
* &lt;/module&gt;
* </pre>
*
* <p>
@ -72,18 +142,6 @@ import com.puppycrawl.tools.checkstyle.checks.AbstractOptionCheck;
* </p>
*
* <p>
* Defaults:
* </p>
* <ul>
* <li>import groups: none</li>
* <li>separation: false</li>
* <li>ordered: true</li>
* <li>case sensitive: true</li>
* <li>static import: under</li>
* <li>sort static imports alphabetically: false</li>
* </ul>
*
* <p>
* Check also has on option making it more flexible:
* <b>sortStaticImportsAlphabetically</b> - sets whether static imports grouped by
* <b>top</b> or <b>bottom</b> option should be sorted alphabetically or

View File

@ -393,6 +393,10 @@ class FooBar {
regular imports and static imports (see
<a href="property_types.html#importOrder">import orders</a>)</li>
</ul>
<p>
<a href="#ImportOrder_Example">Examples section</a> contains examples that
work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans
</p>
</subsection>
<subsection name="Properties">
@ -453,34 +457,71 @@ class FooBar {
</table>
</subsection>
<subsection name="Example">
<p>To configure the check so that it requires that:</p>
<subsection name="Example" id="ImportOrder_Example">
<p>To configure the check so that it matches default Eclipse formatter configuration (tested on Kepler, Luna and Mars):</p>
<ul>
<li>&quot;java&quot; and &quot;javax&quot; packages together first, then &quot;org&quot; and then all other imports</li>
<li>group of static imports is on the top</li>
<li>groups of non-static imports: &quot;java&quot; then &quot;javax&quot; packages first, then &quot;org&quot; and then all other imports</li>
<li>imports will be sorted in the groups</li>
<li>groups are separated by, at least, one blank line</li>
<li>static imports are above each local groups</li>
</ul>
<source>
&lt;module name=&quot;ImportOrder&quot;>
&lt;property name=&quot;groups&quot; value=&quot;/^javax?\./,org&quot;/>
&lt;property name=&quot;ordered&quot; value=&quot;true&quot;/>
&lt;property name=&quot;separated&quot; value=&quot;true&quot;/>
&lt;property name=&quot;option&quot; value=&quot;above&quot;/>
&lt;property name=&quot;groups&quot; value=&quot;/^javax?\./,org&quot;/&gt;
&lt;property name=&quot;ordered&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;separated&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;option&quot; value=&quot;above&quot;/&gt;
&lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/&gt;
&lt;/module>
</source>
<p>To configure the check so that it matches default IntelliJ IDEA formatter configuration (tested on v14):</p>
<ul>
<li>group of static imports is on the bottom</li>
<li>groups of non-static imports: all imports except of &quot;javax&quot; and &quot;java&quot;, then &quot;javax&quot; and &quot;java&quot;</li>
<li>imports will be sorted in the groups</li>
<li>groups are separated by, at least, one blank line</li>
</ul>
<p>
Note: &quot;separated&quot; option is disabled because IDEA default has blank line
between &quot;java&quot; and static imports, and no blank line between
&quot;javax&quot; and &quot;java&quot;
</p>
<source>
&lt;module name=&quot;ImportOrder&quot;&gt;
&lt;property name=&quot;groups&quot; value=&quot;*,javax,java&quot;/&gt;
&lt;property name=&quot;ordered&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;separated&quot; value=&quot;false&quot;/&gt;
&lt;property name=&quot;option&quot; value=&quot;bottom&quot;/&gt;
&lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>To configure the check so that it matches default NetBeans formatter configuration (tested on v8):</p>
<ul>
<li>groups of non-static imports are not defined, all imports will be sorted as a one group</li>
<li>static imports are not separated, they will be sorted along with other imports</li>
</ul>
<source>
&lt;module name=&quot;ImportOrder&quot;&gt;
&lt;property name=&quot;option&quot; value=&quot;inflow&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the Check allows static imports grouped to the <b>top</b>
being sorted alphabetically:
</p>
<source>
&lt;module name=&quot;ImportOrder&quot;>
&lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/>
&lt;property name=&quot;option&quot; value=&quot;top&quot;/>
&lt;/module>
&lt;module name=&quot;ImportOrder&quot;&gt;
&lt;property name=&quot;sortStaticImportsAlphabetically&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;option&quot; value=&quot;top&quot;/&gt;
&lt;/module&gt;
</source>
<source>
@ -572,7 +613,7 @@ public class SomeClass { ... }
<source>
&lt;module name=&quot;ImportControl&quot;>
&lt;property name=&quot;file&quot; value=&quot;import-control.xml&quot;/>
&lt;property name=&quot;file&quot; value=&quot;import-control.xml&quot;/&gt;
&lt;/module>
</source>
@ -584,9 +625,9 @@ public class SomeClass { ... }
<source>
&lt;import-control pkg=&quot;com.puppycrawl.tools.checkstyle&quot;>
&lt;allow class=&quot;java\.awt\.I.*&quot; regex=&quot;true&quot;/>
&lt;allow class=&quot;java\.awt\.I.*&quot; regex=&quot;true&quot;/&gt;
&lt;allow class=&quot;java\.io\.(File|InputStream)&quot; local-only=&quot;true&quot;
regex=&quot;true&quot;/>
regex=&quot;true&quot;/&gt;
&lt;/import-control>
</source>
@ -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.
</p>
<p>
<a href="#CustomImportOrder_Example">Examples section</a> contains examples that
work with default formatter configurations of Eclipse, IntelliJ IDEA and NetBeans
</p>
</subsection>
<subsection name="RuleDescription">
@ -720,7 +765,59 @@ public class SomeClass { ... }
</table>
</subsection>
<subsection name="Examples">
<subsection name="Examples" id="CustomImportOrder_Example">
<p>To configure the check so that it matches default Eclipse formatter configuration (tested on Kepler, Luna and Mars):</p>
<ul>
<li>group of static imports is on the top</li>
<li>groups of non-static imports: &quot;java&quot; and &quot;javax&quot; packages first, then &quot;org&quot; and then all other imports</li>
<li>imports will be sorted in the groups</li>
<li>groups are separated by, at least, one blank line</li>
</ul>
<source>
&lt;module name=&quot;CustomImportOrder&quot;&gt;
&lt;property name=&quot;customImportOrderRules&quot;
value=&quot;STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS&quot;/&gt;
&lt;property name=&quot;specialImportsRegExp&quot; value=&quot;org&quot;/&gt;
&lt;property name=&quot;sortImportsInGroupAlphabetically&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;separateLineBetweenGroups&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</source>
<p>To configure the check so that it matches default IntelliJ IDEA formatter configuration (tested on v14):</p>
<ul>
<li>group of static imports is on the bottom</li>
<li>groups of non-static imports: all imports except of &quot;javax&quot; and &quot;java&quot;, then &quot;javax&quot; and &quot;java&quot;</li>
<li>imports will be sorted in the groups</li>
<li>groups are separated by, at least, one blank line</li>
</ul>
<p>
Note: &quot;separated&quot; option is disabled because IDEA default has blank line
between &quot;java&quot; and static imports, and no blank line between
&quot;javax&quot; and &quot;java&quot;
</p>
<source>
&lt;module name=&quot;CustomImportOrder&quot;&gt;
&lt;property name=&quot;customImportOrderRules&quot;
value=&quot;THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC&quot;/&gt;
&lt;property name=&quot;specialImportsRegExp&quot; value=&quot;^javax\.&quot;/&gt;
&lt;property name=&quot;standardPackageRegExp&quot; value=&quot;^java\.&quot;/&gt;
&lt;property name=&quot;sortImportsInGroupAlphabetically&quot; value=&quot;true&quot;/&gt;
&lt;property name=&quot;separateLineBetweenGroups&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
<p>To configure the check so that it matches default NetBeans formatter configuration (tested on v8):</p>
<ul>
<li>groups of non-static imports are not defined, all imports will be sorted as a one group</li>
<li>static imports are not separated, they will be sorted along with other imports</li>
</ul>
<source>
&lt;module name=&quot;CustomImportOrder&quot;/&gt;
</source>
<p>
To set RegExps for THIRD_PARTY_PACKAGE and STANDARD_JAVA_PACKAGE groups use
thirdPartyPackageRegExp and standardPackageRegExp options.
@ -728,7 +825,7 @@ public class SomeClass { ... }
<source>
&lt;module name=&quot;CustomImportOrder&quot;&gt;
&lt;property name=&quot;customImportOrderRules&quot;
value=&quot;STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE&quot;/&gt;
value=&quot;STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE&quot;/&gt;
&lt;property name=&quot;thirdPartyPackageRegExp&quot; value=&quot;com|org&quot;/&gt;
&lt;property name=&quot;standardPackageRegExp&quot; value=&quot;^(java|javax)\.&quot;/&gt;
&lt;/module&gt;