fixes #1465 False Positve UnusedImports with javadoc @link

This commit is contained in:
Andreas Dangel
2016-02-27 19:30:16 +01:00
parent 518f1eff6d
commit 1c08f94691
4 changed files with 47 additions and 2 deletions

View File

@ -49,14 +49,15 @@ public class UnusedImportsRule extends AbstractJavaRule {
* @see package.class#member(param, param) label
* {@linkplain package.class#member(param, param) label}
* {@link package.class#member(param, param) label}
* {@link package.class#field}
* {@value package.class#field}
* @throws package.class label
*/
private static final Pattern SEE_PATTERN = Pattern.compile(
"@see\\s+(\\p{Alpha}\\p{Alnum}*)(?:#\\p{Alnum}*\\(([\\w\\s,]*)\\))?");
"@see\\s+(\\p{Alpha}\\p{Alnum}*)(?:#\\p{Alnum}*(?:\\(([\\w\\s,]*)\\))?)?");
private static final Pattern LINK_PATTERNS = Pattern.compile(
"\\{@link(?:plain)?\\s+(\\p{Alpha}\\p{Alnum}*)(?:#\\p{Alnum}*\\(([.\\w\\s,]*)\\))?[\\s\\}]");
"\\{@link(?:plain)?\\s+(\\p{Alpha}\\p{Alnum}*)(?:#\\p{Alnum}*(?:\\(([.\\w\\s,]*)\\))?)?[\\s\\}]");
private static final Pattern VALUE_PATTERN = Pattern.compile(
"\\{@value\\s+(\\p{Alpha}\\p{Alnum}*)[\\s#\\}]");

View File

@ -290,6 +290,27 @@ public class FooTest {
public static void main(String[] args) {
System.out.println(PI);
}
}
]]></code>
</test-code>
<test-code>
<description>#1465 False Positve UnusedImports with javadoc @link</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import a.b.c.d.AgentState;
import a.b.c.d.OtherState;
public interface Foo {
/**
* Gets all active AgentHandles.
* <p/>
* An agent is active if it has not posted a {@link AgentStateChangeEvent} containing {@link AgentState#TERMINATED}.
*
* @return agent handles.
* @see OtherState#TERMINATED
*/
Iterable<AgentHandle> getAgentHandles();
}
]]></code>
</test-code>

View File

@ -212,6 +212,27 @@ public class FooTest {
public static void main(String[] args) {
System.out.println(PI);
}
}
]]></code>
</test-code>
<test-code>
<description>#1465 False Positve UnusedImports with javadoc @link</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import a.b.c.d.AgentState;
import a.b.c.d.OtherState;
public interface Foo {
/**
* Gets all active AgentHandles.
* <p/>
* An agent is active if it has not posted a {@link AgentStateChangeEvent} containing {@link AgentState#TERMINATED}.
*
* @return agent handles.
* @see OtherState#TERMINATED
*/
Iterable<AgentHandle> getAgentHandles();
}
]]></code>
</test-code>

View File

@ -32,6 +32,8 @@
* [#1449](https://sourceforge.net/p/pmd/bugs/1449/): false positive when casting a variable to short
* java-design/AccessorClassGeneration:
* [#1452](https://sourceforge.net/p/pmd/bugs/1452/): ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule
* java-imports/UnusedImports:
* [#1465](https://sourceforge.net/p/pmd/bugs/1465/): False Positve UnusedImports with javadoc @link
* java-junit/TestClassWithoutTestCases:
* [#1453](https://sourceforge.net/p/pmd/bugs/1453/): Test Class Without Test Cases gives false positive
* java-unusedcode/UnusedFormalParameter: