Simplified capability check

This commit is contained in:
Oowekyala
2017-05-05 19:23:53 +02:00
parent 5d308a5312
commit 6a0cd33e28
2 changed files with 19 additions and 16 deletions
@@ -6,25 +6,30 @@ package net.sourceforge.pmd.lang.java.metrics;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
/**
* @author Clément Fournier (clement.fournier@insa-rennes.fr)
* Base class for metrics. Metric objects encapsulate the computational logic required to compute a metric from a PackageStats.
*
* @author Clément Fournier (clement.fournier@insa-rennes.fr)
*/
public abstract class AbstractMetric {
protected static OperationSigMask operationMask;
protected List<String> findAllCalls(ASTMethodDeclaration node) {
protected boolean isAbstractHandler = false;
protected List<String> findAllCalls(ASTMethodOrConstructorDeclaration node) {
List<String> result = new ArrayList<>();
// Find the qualified names of all methods called in that method's block
return result;
}
protected boolean checkMaskIsMatching(ASTMethodDeclaration node) {
OperationSignature sig = OperationSignature.buildFor(node);
return operationMask.covers(sig);
}
protected boolean isNotSupported(ASTMethodOrConstructorDeclaration node) {
if (node instanceof ASTMethodDeclaration) {
return ((ASTMethodDeclaration) node).isAbstract();
} else {
return ((ASTConstructorDeclaration) node).isAbstract();
}
}
}
@@ -8,6 +8,7 @@ import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
import net.sourceforge.pmd.lang.java.metrics.OperationSignature.Role;
import net.sourceforge.pmd.lang.java.metrics.Signature.Visibility;
@@ -17,16 +18,13 @@ import net.sourceforge.pmd.lang.java.metrics.Signature.Visibility;
*/
public class AtfdMetric extends AbstractMetric implements ClassMetric, OperationMetric {
static {
operationMask = new OperationSigMask();
operationMask.setAllVisibility();
operationMask.setAllRoles();
operationMask.remove(Role.CONSTRUCTOR);
public AtfdMetric(){
isAbstractHandler = false;
}
@Override
public double computeFor(ASTMethodDeclaration node, PackageStats holder) {
if (!checkMaskIsMatching(node)) {
public double computeFor(ASTMethodOrConstructorDeclaration node, PackageStats holder) {
if (isNotSupported(node)) {
return Double.NaN;
}