checkstyle/docs/config_import.html

296 lines
9.5 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Checks for imports</title>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
</head>
<body>
<!-- The header -->
<table border="0" width="100%" summary="header layout">
<tr>
<td><h1>Checks for imports</h1></td>
<td align="right"><img src="logo.png" alt="Checkstyle Logo"/></td>
</tr>
</table>
<!-- content -->
<table border="0" width="100%" cellpadding="5" summary="body layout">
<tr>
<!--Left menu-->
<td class="menu" valign="top">
<ul>
<li>
<a href="#AvoidStarImport">AvoidStarImport</a>
</li>
<li>
<a href="#ImportOrder">ImportOrder</a>
</li>
<li>
<a href="#IllegalImport">IllegalImport</a>
</li>
<li>
<a href="#RedundantImport">RedundantImport</a>
</li>
<li>
<a href="#UnusedImports">UnusedImports</a>
</li>
</ul>
</td>
<!--Content-->
<td class="content" valign="top" align="left">
<a name="AvoidStarImport"></a> <h2>AvoidStarImport</h2>
<h4>Description</h4>
<p class="body">
Checks that there are no import statements that use the * notation.
</p>
<p class="body">
Rationale: Importing all classes from a package leads to tight coupling
between packages and might lead to problems when a new version of a library
introduces name clashes.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>excludes</td>
<td>packages where star imports are allowed. Note that this
property is not recursive, subpackages of excluded packages are not
automatically excluded.</td>
<td><a href="property_types.html#stringSet">list of strings</a></td>
<td><span class="default">empty list</span></td>
</tr>
</table>
<h4>Example</h4>
<p class="body">
An example how to configure the check so that star imports
from java.io and java.net are allowed:
</p>
<pre class="body">
&lt;module name="AvoidStarImport"&gt;
&lt;property name="excludes" value="java.io,java.net"/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.imports
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<a name="IllegalImport"></a> <h2>IllegalImport</h2>
<h4>Description</h4>
<p class="body">
Checks for imports from a set of illegal packages. By default, the check rejects
all <span class="code">sun.*</span> packages since programs that contain direct
calls to the <span class="code">sun.*</span> packages are <a href="http://java.sun.com/products/jdk/faq/faq-sun-packages.html">not
100% Pure Java</a>. To reject other packages, set property <span class="code">
illegalPkgs</span> to a list of the illegal packages.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>illegalPkgs</td>
<td>packages to reject</td>
<td><a href="property_types.html#stringSet">list of strings</a></td>
<td><span class="default">sun</span></td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;IllegalImport&quot;/&gt;
</pre>
<p class="body">
To configure the check so that it rejects packages <span class="code">java.io.*</span>
and <span class="code">java.sql.*</span>:
</p>
<pre class="body">
&lt;module name=&quot;IllegalImport&quot;&gt;
&lt;property name=&quot;illegalPkgs&quot; value=&quot;java.io, java.sql&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.imports
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<a name="RedundantImport"></a> <h2>RedundantImport</h2> <h4>Description</h4>
<p class="body">
Checks for redundant import statements. An import statement is considered
redundant if:
</p>
<ul class="body">
<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 <span class="code">java.lang</span> package, e.g.
importing <span class="code">java.lang.String</span>.
</li>
<li>
The class imported is from the same package.
</li>
</ul>
<h4>Example</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;RedundantImport&quot;/&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.imports
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<a name="UnusedImports"></a> <h2>UnusedImports</h2> <h4>Description</h4>
<p class="body">
Checks for unused import statements. Checkstyle uses a simple but very reliable
algorithm to report on unused import statements. An import statement is
considered unused if:
</p>
<ul class="body">
<li>
It is not referenced in the file. The algorithm does not support wild-card
imports like <span class="code">import java.io.*;</span>. Most IDE's provide
very sophisticated 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 <span class="code">java.lang</span> package. For
example importing <span class="code">java.lang.String</span>.
</li>
<li>
The class imported is from the same package.
</li>
</ul>
<h4>Example</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;UnusedImports&quot;/&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.imports
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<a name="ImportOrder"></a> <h2>ImportOrder</h2> <h4>Description</h4>
<p class="body">Checks the ordering/grouping of imports.
Ensures that groups of imports come in a specific order (e.g.,
java. comes first, javax. comes first, then everything else) and
imports within each group are in lexicographic order.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>groups</td>
<td>list of imports groups (every group identified by string
it's started)</td>
<td><a href="property_types.html#stringSet">list of strings</a></td>
<td><span class="default">empty list</span></td>
</tr>
<tr>
<td>ordered</td>
<td>whether imports within group should be sorted</td>
<td><a href="property_types.html#Boolean">Boolean</a></td>
<td>true</td>
</tr>
<tr>
<td>separated</td>
<td>whether imports groups should be separated by, at least,
one blank line</td>
<td><a href="property_types.html#Boolean">Boolean</a></td>
<td>false</td>
</tr>
<tr>
<td>caseSensitive</td>
<td>whether strings comprision should be case sensitive or not</td>
<td><a href="property_types.html#Boolean">Boolean</a></td>
<td>true</td>
</tr>
</table>
<h4>Example</h4>
<p class="body">
To configure the check so that it requires &quot;java&quot;
packages first, than &quot;javax&quot; and than all other
imports, imports will be sorted in the groups and groups are
separated by, at least, on blank line:
</p>
<pre class="body">
&lt;module name=&quot;ImportOrder&quot;>
&lt;property name=&quot;groups&quot; value=&quot;java,javax&quot;/>
&lt;property name=&quot;ordered&quot; value=&quot;true&quot;/>
&lt;property name=&quot;separated&quot; value=&quot;true&quot;/>
&lt;/module>
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks.imports
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
</td>
</tr>
</table>
<hr />
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
<p class="copyright">
Copyright &copy; 2002-2004 Oliver Burn. All rights Reserved.
</p>
</body>
</html>