[java] Fix false positive in UnusedImport

- When referencing static inner members of imports, false positives
would be reported.
 - Fixes #348
This commit is contained in:
Juan Martín Sotuyo Dodero
2017-06-19 11:07:12 -03:00
parent 5aa72289ce
commit 2f0e12da6c
2 changed files with 23 additions and 1 deletions

View File

@ -86,7 +86,14 @@ public class UnusedImportsRule extends AbstractJavaRule {
if (s != null) {
String[] params = s.split("\\s*,\\s*");
for (String param : params) {
imports.remove(new ImportWrapper(param, param, new DummyJavaNode(-1)));
final int firstDot = param.indexOf('.');
final String expectedImportName;
if (firstDot == -1) {
expectedImportName = param;
} else {
expectedImportName = param.substring(0, firstDot);
}
imports.remove(new ImportWrapper(param, expectedImportName, new DummyJavaNode(-1)));
}
}
}

View File

@ -261,6 +261,21 @@ public interface Interface {
*/
void doSomething();
}
]]></code>
</test-code>
<test-code>
<description>#348 False Positive UnusedImports with javadoc for public static inner classes of imports</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import javax.swing.GroupLayout;
public class Foo {
/**
* {@link Bar#doSomething(GroupLayout.Group)}
*/
void doSomething();
}
]]></code>
</test-code>