com.puppycrawl.tools.checkstyle.checks.duplicates
Class StrictDuplicateCodeCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
com.puppycrawl.tools.checkstyle.checks.duplicates.StrictDuplicateCodeCheck
- All Implemented Interfaces:
- Configurable, Contextualizable, FileSetCheck
- public final class StrictDuplicateCodeCheck
- extends AbstractFileSetCheck
Checks for duplicate code.
There are many approaches for detecting duplicate code. Some involve
parsing a file of a programming language and analyzing the source trees
of all files. This is a very powerful approach for a specific programming
language (such as Java), as it can potentially even detect duplicate code
where linebreaks have been changed, variables have been renamed, etc.
This copy and paste detection implementation works differently.
It cannot detect copy and paste code where the author deliberately
tries to hide his copy+paste action. Instead it focusses on the standard
corporate problem of reuse by copy and paste. Usually this leaves linebreaks
and variable names intact. Since we do not need to analyse a parse tree
our tool is not tied to a particular programming language.
Simian
is a very good commercial duplicate code detection tool. It comes with
a Checkstyle module, so we encourage all users to evaluate Simian
as an alternative to this check.
- Author:
- Lars Kühne
Method Summary |
void |
process(java.io.File[] aFiles)
Processes a set of files and fires errors to the MessageDispatcher. |
void |
setBasedir(java.lang.String aBasedir)
|
void |
setMin(int aMin)
Sets the minimum number of lines that must be equivalent
before the check complains. |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck |
destroy, filter, fireErrors, getCharset, getMessageCollector, getMessageDispatcher, log, log, setCharset, setFileExtensions, setMessageDispatcher |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter |
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, setSeverity |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StrictDuplicateCodeCheck
public StrictDuplicateCodeCheck()
- Creates a new instance of this class.
setMin
public void setMin(int aMin)
- Sets the minimum number of lines that must be equivalent
before the check complains.
- Parameters:
aMin
- the number of lines that must be equal before
triggering a 'duplicate code' message.
setBasedir
public void setBasedir(java.lang.String aBasedir)
- Parameters:
aBasedir
- the base directory to strip off in filenames
process
public void process(java.io.File[] aFiles)
- Description copied from interface:
FileSetCheck
- Processes a set of files and fires errors to the MessageDispatcher.
The file set to process might contain files that are not
interesting to the FileSetCheck. Such files should be ignored,
no error message should be fired for them. For example a FileSetCheck
that checks java files should ignore html or properties files.
Once processiong is done, it is highly recommended to call for
the destroy method to close and remove the listeners.
- Parameters:
aFiles
- the files to be audited.- See Also:
FileSetCheck.process(java.io.File[])