Skip to content

Commit

Permalink
Issue checkstyle#13007: Update doc for UnusedImports
Browse files Browse the repository at this point in the history
  • Loading branch information
TanayMorakhia committed Apr 23, 2023
1 parent 820dc26 commit 9d60b5a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,40 @@
* <pre>
* &lt;module name="UnusedImports"/&gt;
* </pre>
* <p>Example:</p>
* <pre>
* package com.example;
* import com.example.Demo; // violation, class from the same package should not be imported
* import java.util.Scanner; // OK
* import java.util.Scanner; // violation, class should not be imported more than once
* import java.lang.String; // violation, imported from "java.lang" package
* import java.util.Stack; // OK
* import java.util.Map; // violation, this class is not referenced
* Stack stack = new Stack();
* &#64;link List // violation
* &#64;link java.util.List // OK
* </pre>
* <p>
* To configure the check so that it ignores the imports referenced in Javadoc comments:
* </p>
* <pre>
* &lt;module name=&quot;UnusedImports&quot;&gt;
* &lt;property name=&quot;processJavadoc&quot; value=&quot;false&quot;/&gt;
* &lt;/module&gt;
* </pre>
* <p>Example:</p>
* <pre>
* package com.example;
* import com.example.Demo; // violation, class from the same package should not be imported
* import java.util.Scanner; // OK
* import java.util.Scanner; // violation, class should not be imported more than once
* import java.lang.String; // violation, imported from "java.lang" package
* import java.util.Stack; // OK
* import java.util.Map; // violation, this class is not referenced
* Stack stack = new Stack();
* &#64;link List // OK
* &#64;link java.util.List // OK
* </pre>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
* </p>
Expand Down
46 changes: 46 additions & 0 deletions src/xdocs/config_imports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,52 @@ class FooBar {
<source>
&lt;module name=&quot;UnusedImports&quot;/&gt;
</source>
<p>Example:</p>
<source>
package com.example;

import com.example.Demo; // violation, class from the same package should not be imported

import java.util.Scanner; // OK
import java.util.Scanner; // violation, class should not be imported more than once

import java.lang.String; // violation, imported from "java.lang" package

import java.util.Stack; // OK
import java.util.Map; // violation, this class is not referenced

Stack stack = new Stack();

&#64;link List // violation
&#64;link java.util.List // OK
</source>
<p>
To configure the check so that it ignores the imports referenced in Javadoc comments:
</p>
<source>
&lt;module name=&quot;UnusedImports&quot;&gt;
&lt;property name=&quot;processJavadoc&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
<p>Example:</p>
<source>
package com.example;

import com.example.Demo; // violation, class from the same package should not be imported

import java.util.Scanner; // OK
import java.util.Scanner; // violation, class should not be imported more than once

import java.lang.String; // violation, imported from "java.lang" package

import java.util.Stack; // OK
import java.util.Map; // violation, this class is not referenced

Stack stack = new Stack();

&#64;link List // OK
&#64;link java.util.List // OK
</source>
</subsection>

<subsection name="Example of Usage" id="UnusedImports_Example_of_Usage">
Expand Down

0 comments on commit 9d60b5a

Please sign in to comment.