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 30, 2023
1 parent 15f8367 commit 7058a25
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

/**
* <p>
* Checks for unused import statements. Checkstyle uses a simple but very
* reliable algorithm to report on unused import statements. An import statement
* Checks for unused import statements. An import statement
* is considered unused if:
* </p>
* <ul>
Expand Down Expand Up @@ -78,20 +77,6 @@
* There are two or more static imports with the same method name.
* </li>
* </ul>
* <p>
* For example, in the following case all imports will not be flagged as unused:
* </p>
* <pre>
* import java.awt.Component;
* import static AstTreeStringPrinter.printFileAst;
* import static DetailNodeTreeStringPrinter.printFileAst;
* class FooBar {
* private Object Component; // a bad practice in my opinion
* void method() {
* printFileAst(file); // two imports with the same name
* }
* }
* </pre>
* <ul>
* <li>
* Property {@code processJavadoc} - Control whether to process Javadoc comments.
Expand All @@ -107,6 +92,12 @@
* </pre>
* <p>Example:</p>
* <pre>
* import java.awt.Component; // limitation as it match field name in code
*
* // no ability to recognize what import is not used
* import static AstTreeStringPrinter.printFileAst;
* import static DetailNodeTreeStringPrinter.printFileAst;
*
* import java.lang.String; // violation
*
* import java.util.Stack; // OK
Expand All @@ -119,6 +110,7 @@
* &#42;&#47;
* class MyClass{
* Stack stack = new Stack();
* private Object Component;
* }
* </pre>
* <p>
Expand All @@ -131,6 +123,12 @@
* </pre>
* <p>Example:</p>
* <pre>
* import java.awt.Component; // limitation as it match field name in code
*
* // no ability to recognize what import is not used
* import static AstTreeStringPrinter.printFileAst;
* import static DetailNodeTreeStringPrinter.printFileAst;
*
* import java.lang.String; // violation
*
* import java.util.Stack; // OK
Expand All @@ -143,6 +141,7 @@
* &#42;&#47;
* class MyClass{
* Stack stack = new Stack();
* private Object Component;
* }
* </pre>
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
name="UnusedImports"
parent="com.puppycrawl.tools.checkstyle.TreeWalker">
<description>&lt;p&gt;
Checks for unused import statements. Checkstyle uses a simple but very
reliable algorithm to report on unused import statements. An import statement
Checks for unused import statements. An import statement
is considered unused if:
&lt;/p&gt;
&lt;ul&gt;
Expand Down Expand Up @@ -41,21 +40,7 @@
&lt;li&gt;
There are two or more static imports with the same method name.
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For example, in the following case all imports will not be flagged as unused:
&lt;/p&gt;
&lt;pre&gt;
import java.awt.Component;
import static AstTreeStringPrinter.printFileAst;
import static DetailNodeTreeStringPrinter.printFileAst;
class FooBar {
private Object Component; // a bad practice in my opinion
void method() {
printFileAst(file); // two imports with the same name
}
}
&lt;/pre&gt;</description>
&lt;/ul&gt;</description>
<properties>
<property default-value="true" name="processJavadoc" type="boolean">
<description>Control whether to process Javadoc comments.</description>
Expand Down
30 changes: 14 additions & 16 deletions src/xdocs/config_imports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2454,8 +2454,7 @@ public class MyClass{ };
<p>Since Checkstyle 3.0</p>
<subsection name="Description" id="UnusedImports_Description">
<p>
Checks for unused import statements. Checkstyle uses a simple but
very reliable algorithm to report on unused import statements. An
Checks for unused import statements. An
import statement is considered unused if:
</p>

Expand Down Expand Up @@ -2497,20 +2496,6 @@ public class MyClass{ };
There are two or more static imports with the same method name.
</li>
</ul>
<p>
For example, in the following case all imports will not be flagged as unused:
</p>
<source>
import java.awt.Component;
import static AstTreeStringPrinter.printFileAst;
import static DetailNodeTreeStringPrinter.printFileAst;
class FooBar {
private Object Component; // a bad practice in my opinion
void method() {
printFileAst(file); // two imports with the same name
}
}
</source>
</subsection>

<subsection name="Properties" id="UnusedImports_Properties">
Expand Down Expand Up @@ -2543,6 +2528,12 @@ class FooBar {
</source>
<p>Example:</p>
<source>
import java.awt.Component; // limitation as it match field name in code

// no ability to recognize what import is not used
import static AstTreeStringPrinter.printFileAst;
import static DetailNodeTreeStringPrinter.printFileAst;

import java.lang.String; // violation

import java.util.Stack; // OK
Expand All @@ -2555,6 +2546,7 @@ import java.util.List; // OK
&#42;&#47;
class MyClass{
Stack stack = new Stack();
private Object Component;
}
</source>
<p>
Expand All @@ -2567,6 +2559,11 @@ class MyClass{
</source>
<p>Example:</p>
<source>
import java.awt.Component; // limitation as it match field name in code

// no ability to recognize what import is not used
import static AstTreeStringPrinter.printFileAst;
import static DetailNodeTreeStringPrinter.printFileAst;
import java.lang.String; // violation

import java.util.Stack; // OK
Expand All @@ -2579,6 +2576,7 @@ import java.util.List; // violation
&#42;&#47;
class MyClass{
Stack stack = new Stack();
private Object Component;
}
</source>
</subsection>
Expand Down

0 comments on commit 7058a25

Please sign in to comment.