UnnecessaryFullyQualifiedName can detect conflicts

- Fixes https://sourceforge.net/p/pmd/bugs/1546/
This commit is contained in:
Juan Martín Sotuyo Dodero
2016-11-15 03:12:56 -03:00
committed by Andreas Dangel
parent 1b5135f360
commit 7e3546c130
3 changed files with 242 additions and 176 deletions

View File

@ -40,4 +40,20 @@ public class ImportsRulesTest extends SimpleAggregatorTst {
public enum ENUM2 {
C, D;
}
// Do not delete these two classes - it is needed for a test case
// see: /pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/imports/xml/UnnecessaryFullyQualifiedName.xml
// #1546 part 1 UnnecessaryFullyQualifiedName doesn't take into consideration conflict resolution
// #1546 part 2 UnnecessaryFullyQualifiedName doesn't take into consideration conflict resolution
public static class PhonyMockito {
public static <T> T mock(Class<T> clazz) {
return null;
}
}
public static class PhonyPowerMockito {
public static <T> T mock(Class<T> clazz) {
return null;
}
}
}

View File

@ -323,14 +323,44 @@ public class InitialPageComponent extends BaseExecutionCourseComponent {
<description>#1436 UnnecessaryFullyQualifiedName false positive on clashing static imports with enums</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.ENUM2;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.ENUM1.*;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.ENUM2.*;
public class UnnecessaryFullyQualifiedName {
public static void main(String[] args) {
System.out.println(ENUM1.values());
System.out.println(A);
System.out.println(D);
System.out.println(ENUM2.values());
}
}
]]></code>
</test-code>
<test-code>
<description>#1546 part 1 UnnecessaryFullyQualifiedName doesn't take into consideration conflict resolution</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyMockito;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyMockito.*;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyPowerMockito.*;
public class Foo {
private Bar bar = Mockito.mock(Bar.class); // doing simply mock(Bar.class) is ambiguous (compile error)
}
]]></code>
</test-code>
<test-code>
<description>#1546 part 2 UnnecessaryFullyQualifiedName doesn't take into consideration conflict resolution</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyMockito;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyMockito.*;
import static net.sourceforge.pmd.lang.java.rule.imports.ImportsRulesTest.PhonyPowerMockito.mock;
public class Foo {
private Bar bar = Mockito.mock(Bar.class); // doing simply mock(Bar.class) would use a differen method than intended
}
]]></code>
</test-code>