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 25, 2023
1 parent 9d60b5a commit 439e4f9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
* checks for imports that handle wild-card imports.
* </li>
* <li>
* It is a duplicate of another import. This is when a class is imported more
* than once.
* </li>
* <li>
* The class imported is from the {@code java.lang} package. For example
* importing {@code java.lang.String}.
* </li>
Expand Down Expand Up @@ -111,16 +107,23 @@
* </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 demo.Demo; // violation, Unused import - demo.Demo
*
* import java.lang.String; // violation, Unused import - java.lang.String
*
* 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
* import java.util.Map; // violation, Unused import - java.util.Map
*
* import java.util.List; // OK
*
* &#47;&#42;&#42;
* &#42; @link List
* &#42;&#47;
* class MyClass{
* public static void main(String args[]){
* Stack stack = new Stack();
* }
* }
* </pre>
* <p>
* To configure the check so that it ignores the imports referenced in Javadoc comments:
Expand All @@ -132,16 +135,23 @@
* </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 demo.Demo; // violation, Unused import - demo.Demo
*
* import java.lang.String; // violation, Unused import - java.lang.String
*
* 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
* import java.util.Map; // violation, Unused import - java.util.Map
*
* import java.util.List; // violation, Unused import - java.util.List
*
* &#47;&#42;&#42;
* &#42; @link List
* &#42;&#47;
* class MyClass{
* public static void main(String args[]){
* Stack stack = new Stack();
* }
* }
* </pre>
* <p>
* Parent is {@code com.puppycrawl.tools.checkstyle.TreeWalker}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
checks for imports that handle wild-card imports.
&lt;/li&gt;
&lt;li&gt;
It is a duplicate of another import. This is when a class is imported more
than once.
&lt;/li&gt;
&lt;li&gt;
The class imported is from the {@code java.lang} package. For example
importing {@code java.lang.String}.
&lt;/li&gt;
Expand Down
51 changes: 24 additions & 27 deletions src/xdocs/config_imports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2467,11 +2467,6 @@ public class MyClass{ };
for imports that handle wild-card imports.
</li>

<li>
It is a duplicate of another import. This is when a class is
imported more than once.
</li>

<li>
The class imported is from the <code>java.lang</code>
package. For example importing <code>java.lang.String</code>.
Expand Down Expand Up @@ -2548,22 +2543,23 @@ class FooBar {
</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 demo.Demo; // violation, Unused import - demo.Demo

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

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

Stack stack = new Stack();
import java.util.List; // OK

&#64;link List // violation
&#64;link java.util.List // OK
&#47;&#42;&#42;
&#42; @link List
&#42;&#47;
class MyClass{
public static void main(String args[]){
Stack stack = new Stack();
}
}
</source>
<p>
To configure the check so that it ignores the imports referenced in Javadoc comments:
Expand All @@ -2575,22 +2571,23 @@ Stack stack = new Stack();
</source>
<p>Example:</p>
<source>
package com.example;

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

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.lang.String; // violation, Unused import - java.lang.String

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

Stack stack = new Stack();
import java.util.List; // violation, Unused import - java.util.List

&#64;link List // OK
&#64;link java.util.List // OK
&#47;&#42;&#42;
&#42; @link List
&#42;&#47;
class MyClass{
public static void main(String args[]){
Stack stack = new Stack();
}
}
</source>
</subsection>

Expand Down

0 comments on commit 439e4f9

Please sign in to comment.