forked from phoedos/pmd
Merge branch 'master' of https://github.com/pmd/pmd into metrics-apex
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.metrics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
@ -12,14 +13,23 @@ import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer;
|
||||
|
||||
/**
|
||||
* Computes metrics for the Apex framework.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class ApexMetricsComputer extends AbstractMetricsComputer<ASTUserClassOrInterface<?>, ASTMethod> {
|
||||
|
||||
public static final ApexMetricsComputer INSTANCE = new ApexMetricsComputer();
|
||||
static final ApexMetricsComputer INSTANCE = new ApexMetricsComputer();
|
||||
|
||||
|
||||
@Override
|
||||
protected List<ASTMethod> findOperations(ASTUserClassOrInterface<?> node) {
|
||||
return node.findChildrenOfType(ASTMethod.class);
|
||||
List<ASTMethod> candidates = node.findChildrenOfType(ASTMethod.class);
|
||||
List<ASTMethod> result = new ArrayList<>(candidates);
|
||||
for (ASTMethod method : candidates) {
|
||||
if (method.getImage().matches("(<clinit>|<init>|clone)")) {
|
||||
result.remove(method);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import net.sourceforge.pmd.lang.apex.metrics.AbstractApexMetric;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetric;
|
||||
|
||||
/**
|
||||
* Base class for Apex metrics.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public abstract class AbstractApexClassMetric extends AbstractApexMetric implements ApexClassMetric {
|
||||
|
@ -10,10 +10,20 @@ import net.sourceforge.pmd.lang.apex.metrics.AbstractApexMetric;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetric;
|
||||
|
||||
/**
|
||||
* Base class for Apex operation metrics.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public abstract class AbstractApexOperationMetric extends AbstractApexMetric implements ApexOperationMetric {
|
||||
|
||||
/**
|
||||
* Checks if the metric can be computed on the node. For now, we filter out {@literal <clinit>, <init> and clone},
|
||||
* which are present in all apex class nodes even if they're not implemented, which may yield unexpected results.
|
||||
*
|
||||
* @param node The node to check
|
||||
*
|
||||
* @return True if the metric can be computed
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(ASTMethod node) {
|
||||
return !node.getImage().matches("(<clinit>|<init>|clone)")
|
||||
|
@ -29,8 +29,16 @@ public class CycloMetric extends AbstractApexOperationMetric {
|
||||
public double computeFor(ASTMethod node, MetricVersion version) {
|
||||
return ((MutableInt) node.jjtAccept(new StandardCycloVisitor(), new MutableInt(1))).doubleValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Computes the number of control flow paths through that expression, which is the number of {@code ||} and {@code
|
||||
* &&} operators. Used both by Npath and Cyclo.
|
||||
*
|
||||
* @param expression Boolean expression
|
||||
*
|
||||
* @return The complexity of the expression
|
||||
*/
|
||||
public static int booleanExpressionComplexity(ASTStandardCondition expression) {
|
||||
Set<ASTBooleanExpression> subs = new HashSet<>(expression.findDescendantsOfType(ASTBooleanExpression.class));
|
||||
int complexity = 0;
|
||||
|
@ -11,6 +11,8 @@ import net.sourceforge.pmd.lang.metrics.MetricVersion;
|
||||
import net.sourceforge.pmd.lang.metrics.ResultOption;
|
||||
|
||||
/**
|
||||
* See the doc for the Java metric.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class WmcMetric extends AbstractApexClassMetric {
|
||||
|
@ -14,7 +14,6 @@ import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
@ -24,6 +23,7 @@ import net.sourceforge.pmd.lang.apex.metrics.impl.AbstractApexClassMetric;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.impl.AbstractApexOperationMetric;
|
||||
import net.sourceforge.pmd.lang.metrics.Metric.Version;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricMemoizer;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricVersion;
|
||||
|
||||
|
@ -2,13 +2,11 @@
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang;
|
||||
package net.sourceforge.pmd.lang.metrics;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.metrics.Metric;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
|
||||
/**
|
||||
* Holds the key creation method until we move it to the MetricKey interface.
|
@ -12,11 +12,11 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricVersion;
|
||||
import net.sourceforge.pmd.lang.metrics.ParameterizedMetricKey;
|
||||
|
||||
|
@ -14,7 +14,6 @@ import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
||||
@ -24,6 +23,7 @@ import net.sourceforge.pmd.lang.java.metrics.impl.AbstractJavaOperationMetric;
|
||||
import net.sourceforge.pmd.lang.java.metrics.testdata.MetricsVisitorTestData;
|
||||
import net.sourceforge.pmd.lang.metrics.Metric.Version;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricMemoizer;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricVersion;
|
||||
|
||||
|
@ -132,4 +132,5 @@ and include them to such reports.
|
||||
* [#530](https://github.com/pmd/pmd/pull/530): \[java] Fix issue #527: Lombok getter annotation on enum is not recognized correctly - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#535](https://github.com/pmd/pmd/pull/535): \[apex] Fix broken Apex visitor adapter - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#529](https://github.com/pmd/pmd/pull/529): \[java] Abstracted the Java metrics framework - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#542](https://github.com/pmd/pmd/pull/542): \[java] Metrics abstraction - [Clément Fournier](https://github.com/oowekyala)
|
||||
|
||||
|
Reference in New Issue
Block a user