forked from phoedos/pmd
Corrections from PR review (#908), make the metrics visitors extendable again
This commit is contained in:
@ -195,15 +195,13 @@ public final class Helper {
|
||||
static boolean isSystemLevelClass(ASTUserClass node) {
|
||||
List<TypeRef> interfaces = node.getNode().getDefiningType().getCodeUnitDetails().getInterfaceTypeRefs();
|
||||
|
||||
boolean hasWhitelistedInterfaces = false;
|
||||
for (TypeRef intObject : interfaces) {
|
||||
if (isWhitelisted(intObject.getNames())) {
|
||||
hasWhitelistedInterfaces = true;
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return hasWhitelistedInterfaces;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isWhitelisted(List<Identifier> ids) {
|
||||
|
@ -37,16 +37,9 @@ class BenchmarkResult implements Comparable<BenchmarkResult> {
|
||||
|
||||
@Override
|
||||
public int compareTo(BenchmarkResult benchmarkResult) {
|
||||
int cmp = type.index - benchmarkResult.type.index;
|
||||
int cmp = Integer.compare(type.index, benchmarkResult.type.index);
|
||||
if (cmp == 0) {
|
||||
long delta = this.time - benchmarkResult.time;
|
||||
if (delta > 0) {
|
||||
cmp = 1;
|
||||
} else if (delta < 0) {
|
||||
cmp = -1;
|
||||
} else {
|
||||
cmp = 0;
|
||||
}
|
||||
cmp = Long.compare(this.time, benchmarkResult.time);
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.metrics.impl.visitors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression;
|
||||
@ -15,7 +16,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix;
|
||||
import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Computes Atfd.
|
||||
@ -41,7 +41,7 @@ public class AtfdBaseVisitor extends JavaParserVisitorAdapter {
|
||||
|
||||
String methodOrAttributeName = getMethodOrAttributeName(node);
|
||||
|
||||
return methodOrAttributeName != null && StringUtil.startsWithAny(methodOrAttributeName, "get", "is", "set");
|
||||
return methodOrAttributeName != null && StringUtils.startsWithAny(methodOrAttributeName, "get", "is", "set");
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,15 +25,11 @@ import net.sourceforge.pmd.lang.java.ast.JavaParserControllessVisitorAdapter;
|
||||
* @author Clément Fournier
|
||||
* @see net.sourceforge.pmd.lang.java.metrics.impl.CycloMetric
|
||||
*/
|
||||
public final class CycloBaseVisitor extends JavaParserControllessVisitorAdapter {
|
||||
public class CycloBaseVisitor extends JavaParserControllessVisitorAdapter {
|
||||
|
||||
/** Instance. */
|
||||
public static final CycloBaseVisitor INSTANCE = new CycloBaseVisitor();
|
||||
|
||||
private CycloBaseVisitor() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTSwitchStatement node, Object data) {
|
||||
int childCount = node.jjtGetNumChildren();
|
||||
|
@ -41,16 +41,11 @@ import net.sourceforge.pmd.lang.java.ast.JavaParserControllessVisitorAdapter;
|
||||
* @author Clément Fournier
|
||||
* @see net.sourceforge.pmd.lang.java.metrics.impl.NcssMetric
|
||||
*/
|
||||
public final class NcssBaseVisitor extends JavaParserControllessVisitorAdapter {
|
||||
public class NcssBaseVisitor extends JavaParserControllessVisitorAdapter {
|
||||
|
||||
/** Instance. */
|
||||
public static final NcssBaseVisitor INSTANCE = new NcssBaseVisitor();
|
||||
|
||||
|
||||
private NcssBaseVisitor() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
((MutableInt) data).increment();
|
||||
|
@ -28,14 +28,11 @@ import net.sourceforge.pmd.lang.java.metrics.impl.CycloMetric;
|
||||
* @author Clément Fournier
|
||||
* @author Jason Bennett
|
||||
*/
|
||||
public final class NpathBaseVisitor extends JavaParserVisitorReducedAdapter {
|
||||
public class NpathBaseVisitor extends JavaParserVisitorReducedAdapter {
|
||||
|
||||
/** Instance. */
|
||||
public static final NpathBaseVisitor INSTANCE = new NpathBaseVisitor();
|
||||
|
||||
private NpathBaseVisitor() {
|
||||
}
|
||||
|
||||
/* Multiplies the complexity of the children of this node. */
|
||||
private int multiplyChildrenComplexities(JavaNode node, Object data) {
|
||||
int product = 1;
|
||||
|
@ -397,7 +397,6 @@ public class ForLoopCanBeForeachRule extends AbstractJavaRule {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean onlyCallingNext = true;
|
||||
for (NameOccurrence occ : indexInfo.getValue()) {
|
||||
ScopedNode location = occ.getLocation();
|
||||
boolean isCallingNext = location instanceof ASTName
|
||||
@ -405,11 +404,10 @@ public class ForLoopCanBeForeachRule extends AbstractJavaRule {
|
||||
|| location.hasImageEqualTo(indexName + ".next"));
|
||||
|
||||
if (!isCallingNext) {
|
||||
onlyCallingNext = false;
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return onlyCallingNext;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isIterableModifiedInsideLoop(Entry<VariableNameDeclaration, List<NameOccurrence>> iterableInfo,
|
||||
|
Reference in New Issue
Block a user