[java] LooseCoupling - use rule chain
While there is no fixed false negative, this is more correct and in PMD 7, rule chain is already used.
This commit is contained in:
@ -29,6 +29,10 @@ public class LooseCouplingRule extends AbstractJavaRule {
|
||||
// "java.util.TreeMap", "java.util.Vector"
|
||||
// });
|
||||
|
||||
public LooseCouplingRule() {
|
||||
addRuleChainVisit(ASTClassOrInterfaceType.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceType node, Object data) {
|
||||
if (methodHasOverride(node)) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
<test-code>
|
||||
<description>returning a HashSet, bad</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<expected-linenumbers>3</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
import java.util.HashSet;
|
||||
public class Foo {
|
||||
@ -135,6 +136,33 @@ import java.util.LinkedHashMap;
|
||||
public class Test {
|
||||
@Override
|
||||
public LinkedHashMap findGetters() {}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Verify with nested (local) classes</description>
|
||||
<expected-problems>3</expected-problems>
|
||||
<expected-linenumbers>6,11,15</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
import java.util.HashSet;
|
||||
public class Foo {
|
||||
void firstMethod() { }
|
||||
void myMethod() {
|
||||
class Inner {
|
||||
HashSet foo() {
|
||||
return new HashSet();
|
||||
}
|
||||
}
|
||||
Object o = new Object() {
|
||||
HashSet foo() { return new HashSet(); }
|
||||
};
|
||||
}
|
||||
class Nested {
|
||||
HashSet foo() {
|
||||
return new HashSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user