Corrections for PR #523

This commit is contained in:
oowekyala
2017-07-27 22:46:45 +02:00
parent 1ee8cc4e8d
commit 7e5374ea8d
2 changed files with 7 additions and 9 deletions

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.lang.java.metrics.api;
import java.util.Objects;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
import net.sourceforge.pmd.lang.java.metrics.impl.AtfdMetric.AtfdClassMetric;
import net.sourceforge.pmd.lang.java.metrics.impl.CycloMetric.CycloClassMetric;
@ -105,7 +107,9 @@ public enum JavaClassMetricKey implements MetricKey<ASTAnyTypeDeclaration> {
@Override
public boolean equals(Object obj) {
return obj == this;
return obj != null && getClass() == obj.getClass()
&& Objects.equals(name(), getClass().cast(obj).name())
&& Objects.equals(getCalculator(), getClass().cast(obj).getCalculator());
}

View File

@ -4,7 +4,6 @@
package net.sourceforge.pmd.lang.java.metrics.impl.visitors;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression;
@ -73,17 +72,12 @@ public class DefaultNpathVisitor extends JavaParserVisitorReducedAdapter {
public Object visit(ASTIfStatement node, Object data) {
// (npath of if + npath of else (or 1) + bool_comp of if) * npath of next
List<JavaNode> statementChildren = new ArrayList<>();
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
if (node.jjtGetChild(i) instanceof ASTStatement) {
statementChildren.add((JavaNode) node.jjtGetChild(i));
}
}
List<ASTStatement> statementChildren = node.findChildrenOfType(ASTStatement.class);
// add path for not taking if
int complexity = node.hasElse() ? 0 : 1;
for (JavaNode element : statementChildren) {
for (ASTStatement element : statementChildren) {
complexity += (Integer) element.jjtAccept(this, data);
}