@@ -37,6 +37,7 @@ This is a minor release.
|
||||
* [#920](https://github.com/pmd/pmd/pull/920): \[java] Update valid identifiers in grammar
|
||||
* java-bestpractices
|
||||
* [#784](https://github.com/pmd/pmd/issues/784): \[java] ForLoopCanBeForeach false-positive
|
||||
* [#925](https://github.com/pmd/pmd/issues/925): \[java] UnusedImports false positive for static import
|
||||
* java-design
|
||||
* [#855](https://github.com/pmd/pmd/issues/855): \[java] ImmutableField false-positive with lambdas
|
||||
* java-documentation
|
||||
|
@@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.rule;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -35,6 +36,13 @@ public class ImportWrapper {
|
||||
for (Field f : type.getFields()) {
|
||||
allDemands.add(f.getName());
|
||||
}
|
||||
// also consider static fields, that are not public
|
||||
int requiredMod = Modifier.STATIC;
|
||||
for (Field f : type.getDeclaredFields()) {
|
||||
if ((f.getModifiers() & requiredMod) == requiredMod) {
|
||||
allDemands.add(f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassWithConstants {
|
||||
|
||||
private ClassWithConstants() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
/*package*/ static final List<String> LIST1 = Arrays.asList("A");
|
||||
/*package*/ static final List<String> LIST2 = Arrays.asList("B");
|
||||
}
|
@@ -395,4 +395,21 @@ public class Foo {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#925 [java] UnusedImports false positive for static import</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
package net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports;
|
||||
|
||||
import static net.sourceforge.pmd.lang.java.rule.bestpractices.unusedimports.ClassWithConstants.*;
|
||||
|
||||
public class ClassWithImport {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("List 1: " + LIST1);
|
||||
System.out.println("List 2: " + LIST2);
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user