pmd: fix #254 False+ : UnusedImport with Javadoc @throws

This commit is contained in:
Andreas Dangel 2013-04-15 21:33:49 +02:00
parent 3901ad7ddb
commit 7494011999
4 changed files with 29 additions and 2 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.4: ????? ??, 2013 - 5.0.4:
Fixed bug 254: False+ : UnusedImport with Javadoc @throws
Fixed bug 1080: net.sourceforge.pmd.cpd.CPDTest test failing Fixed bug 1080: net.sourceforge.pmd.cpd.CPDTest test failing
Fixed bug 1081: Regression: CPD skipping all files when using relative paths Fixed bug 1081: Regression: CPD skipping all files when using relative paths
Fixed bug 1082: CPD performance issue on larger projects Fixed bug 1082: CPD performance issue on larger projects

View File

@ -50,6 +50,7 @@ public class UnusedImportsRule extends AbstractJavaRule {
* {@linkplain package.class#member label} * {@linkplain package.class#member label}
* {@link package.class#member label} * {@link package.class#member label}
* {@value package.class#field} * {@value package.class#field}
* @throws package.class label
*/ */
private static final Pattern SEE_PATTERN = Pattern.compile( private static final Pattern SEE_PATTERN = Pattern.compile(
"@see\\s+(\\p{Alpha}\\p{Alnum}*)[\\s#]"); "@see\\s+(\\p{Alpha}\\p{Alnum}*)[\\s#]");
@ -60,7 +61,10 @@ public class UnusedImportsRule extends AbstractJavaRule {
private static final Pattern VALUE_PATTERN = Pattern.compile( private static final Pattern VALUE_PATTERN = Pattern.compile(
"\\{@value\\s+(\\p{Alpha}\\p{Alnum}*)[\\s#\\}]"); "\\{@value\\s+(\\p{Alpha}\\p{Alnum}*)[\\s#\\}]");
private static final Pattern[] PATTERNS = { SEE_PATTERN, LINK_PATTERNS, VALUE_PATTERN }; private static final Pattern THROWS_PATTERN = Pattern.compile(
"@throws\\s+(\\p{Alpha}\\p{Alnum}*)");
private static final Pattern[] PATTERNS = { SEE_PATTERN, LINK_PATTERNS, VALUE_PATTERN, THROWS_PATTERN };
private void visitComments(ASTCompilationUnit node) { private void visitComments(ASTCompilationUnit node) {
if (imports.isEmpty()) { if (imports.isEmpty()) {

View File

@ -218,4 +218,23 @@ import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.NonNull;
]]></code> ]]></code>
</test-code> </test-code>
<test-code>
<description>bug #254 False+ : UnusedImport with Javadoc @link</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.ArrayList;
import java.util.Collections;
import java.util.NoSuchElementException;
public class Test {
/**
* {@link ArrayList#add(Object)}
* @see Collections
* @throws NoSuchElementException no such element
*/
String[] getList() { }
}
]]></code>
</test-code>
</test-data> </test-data>

View File

@ -156,7 +156,7 @@ public class Foo {
</test-code> </test-code>
<test-code> <test-code>
<description><![CDATA[ <description><![CDATA[
imports used in javadoc comment imports used in javadoc comment, see also bug #254
]]></description> ]]></description>
<expected-problems>0</expected-problems> <expected-problems>0</expected-problems>
<code><![CDATA[ <code><![CDATA[
@ -164,12 +164,15 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.File; import java.util.File;
import java.util.NoSuchElementException;
public class Foo { public class Foo {
/** /**
* {@linkplain List list} * {@linkplain List list}
* {@link ArrayList arraylist} * {@link ArrayList arraylist}
* {@value Calendar#DATE} * {@value Calendar#DATE}
* @see File * @see File
* @throws NoSuchElementException no such element
*/ */
public void test() {} public void test() {}
} }