144 lines
4.1 KiB
XML
144 lines
4.1 KiB
XML
<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
|
|
<document xmlns="http://maven.apache.org/XDOC/2.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
|
|
<properties>
|
|
<title>Duplicate code</title>
|
|
<author>Checkstyle Development Team</author>
|
|
</properties>
|
|
<body>
|
|
<section name="Duplicate code">
|
|
<p>
|
|
Duplicate code detection allows you to find
|
|
code that has been generated by Copy/Paste programming. Duplicate code typically
|
|
leads to higher maintenance costs because bugs will need to be fixed twice,
|
|
more code needs to be tested, and so on.
|
|
</p>
|
|
<p>
|
|
There are many trade-offs when writing a duplicate code detection tool.
|
|
Some of the conflicting goals are:
|
|
</p>
|
|
<ul>
|
|
<li>Speed</li>
|
|
<li>Low memory usage</li>
|
|
<li>Avoiding false alarms</li>
|
|
<li>Support for arbitrary programming languages (Java, JSP, C++, ...)</li>
|
|
<li>Support for fuzzy matches (comments, whitespace, linebreaks, variable renaming, etc.)</li>
|
|
</ul>
|
|
|
|
<p>
|
|
The check provided here, StrictDuplicateCode, is fast enough to facilitate checking very large code
|
|
bases in acceptable time (minutes). It consumes very little memory, false
|
|
alarms are impossible. While it supports multiple
|
|
languages, it does not support fuzzy matches (that's why it's called Strict).
|
|
</p>
|
|
<p>
|
|
Note that there are brilliant commercial implementations of duplicate code
|
|
detection tools. One that is particularly noteworthy is
|
|
<a href="http://www.redhillconsulting.com.au/products/simian/">Simian</a>
|
|
from RedHill Consulting, Inc.
|
|
Simian has managed to find a very good balance of the above tradeoffs.
|
|
It is superior to the checks in this package in many respects.
|
|
Simian is reasonably priced (free for noncommercial projects)
|
|
and includes a Checkstyle plugin. We encourage all users of Checkstyle to evaluate Simian as an
|
|
alternative to the Checks we offer in our distribution.
|
|
</p>
|
|
<p>
|
|
The following table summarizes the characteristics of the available
|
|
Checkstyle plugins for duplicate code detection:
|
|
</p>
|
|
|
|
<table>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Speed</th>
|
|
<th>Memory Usage</th>
|
|
<th>False Alarms</th>
|
|
<th>Supported languages</th>
|
|
<th>Fuzzy matches</th>
|
|
</tr>
|
|
<tr>
|
|
<td>StrictDuplicateCode</td>
|
|
<td>High</td>
|
|
<td>Very Low</td>
|
|
<td>Impossible</td>
|
|
<td>any language</td>
|
|
<td>No</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Simian</td>
|
|
<td>Very high</td>
|
|
<td>Low</td>
|
|
<td>Possible but very unlikely</td>
|
|
<td>many languages, including Java and C/C++/C#</td>
|
|
<td>Limited support</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p>
|
|
</p>
|
|
</section>
|
|
<section name="StrictDuplicateCode">
|
|
<p>
|
|
Performs a line-by-line comparison of all code lines and reports
|
|
duplicate code if a sequence of lines differs only in
|
|
indentation. All import statements in Java code are ignored, any
|
|
other line - including javadoc, whitespace lines between methods,
|
|
etc. - is considered (which is why the check is called
|
|
<em>strict</em>).
|
|
</p>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>min</td>
|
|
<td>how many lines must be equal to be considered a duplicate</td>
|
|
<td><a href="property_types.html#integer">int</a></td>
|
|
<td><code>12</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>fileExtensions</td>
|
|
<td>file type extension of files to process</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td><code>{}</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p> To configure the check: </p>
|
|
<source>
|
|
<module name="StrictDuplicateCode"/>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check so that it allows larger equivalent blocks:
|
|
</p>
|
|
<source>
|
|
<module name="StrictDuplicateCode">
|
|
<property name="min" value="15"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>com.puppycrawl.tools.checkstyle.checks.duplicates</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#Checker">Checker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
|
|
</body>
|
|
</document>
|