Affects PMD Version:
Rule: UnnecessaryImport
Description:
When a derived class refers to a type in a {@link Type#method(ImportedType)}
Javadoc tag and there is a line break after the @link
, the ImportedType
is flagged as being unused.
Code Sample demonstrating the issue:
import java.io.File; import java.io.FileOutputStream; public class Demo { /** {@link * FileOutputStream#FileOutputStream(File)} */ void main() {} }
Running PMD through: doesn't matter
Suggested fix: In UnusedImportsRule.java
, change LINKS_PATTERN
to match the following strings:
"{@link\nType#method(ImportedType)}"
"{@link\n*\tqualified.Type#method(ImportedType)}"
Since this is very similar to #1555 it may be wrong to use regular expressions at all. By using a proper Java comment parser (which must exist somewhere since the Javadoc tool uses it), it should be easier to catch this edge case and probably some more.
Quick and dirty hacks:
\\{@link(?:plain)?\\s+
with \\{@link(?:plain)?[\\s*]+
, which allows asterisks during line breaks.\\p{Alpha}\\w*
with \\p{Alpha}\[\w.]*
, which allows qualified type names.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4