diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/AbstractMetricsComputer.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/AbstractMetricsComputer.java new file mode 100644 index 0000000000..a0165f984a --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/AbstractMetricsComputer.java @@ -0,0 +1,157 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.metrics; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.pmd.lang.ast.QualifiableNode; +import net.sourceforge.pmd.lang.ast.SignedNode; +import net.sourceforge.pmd.lang.metrics.api.MetricKey; +import net.sourceforge.pmd.lang.metrics.api.MetricVersion; +import net.sourceforge.pmd.lang.metrics.api.ResultOption; + +/** + * Base class for metrics computers. These objects compute a metric and memoize it. + * + * @param Type of type declaration nodes of the language + * @param Type of operation declaration nodes of the language + * + * @author Clément Fournier + */ +public abstract class AbstractMetricsComputer & QualifiableNode> { + + /** + * Computes the value of a metric for a class and stores the result in the ClassStats object. + * + * @param key The class metric to compute + * @param node The AST node of the class + * @param force Force the recomputation; if unset, we'll first check for a memoized result + * @param version The version of the metric to compute + * @param memoizer The object memoizing the results + * + * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed + */ + public double computeForType(MetricKey key, T node, boolean force, + MetricVersion version, MetricMemoizer memoizer) { + + ParameterizedMetricKey paramKey = ParameterizedMetricKey.getInstance(key, version); + // if memo.get(key) == null then the metric has never been computed. NaN is a valid value. + Double prev = memoizer.getMemo(paramKey); + if (!force && prev != null) { + return prev; + } + + double val = key.getCalculator().computeFor(node, version); + memoizer.memoize(paramKey, val); + + return val; + } + + + /** + * Computes the value of a metric for an operation and stores the result in the OperationStats object. + * + * @param key The operation metric to compute + * @param node The AST node of the operation + * @param force Force the recomputation; if unset, we'll first check for a memoized result + * @param version The version of the metric to compute + * @param memoizer The object memoizing the results + * + * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed + */ + public double computeForOperation(MetricKey key, O node, boolean force, + MetricVersion version, MetricMemoizer memoizer) { + + ParameterizedMetricKey paramKey = ParameterizedMetricKey.getInstance(key, version); + Double prev = memoizer.getMemo(paramKey); + if (!force && prev != null) { + return prev; + } + + double val = key.getCalculator().computeFor(node, version); + memoizer.memoize(paramKey, val); + return val; + } + + + /** + * Computes an aggregate result using a ResultOption. + * + * @param key The class metric to compute + * @param node The AST node of the class + * @param force Force the recomputation; if unset, we'll first check for a memoized result + * @param version The version of the metric + * @param option The type of result to compute + * @param stats The ClassStats storing info about the class + * + * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed + */ + public double computeWithResultOption(MetricKey key, T node, boolean force, MetricVersion version, + ResultOption option, ProjectMirror stats) { + + List ops = findOperations(node); + + List values = new ArrayList<>(); + for (O op : ops) { + if (key.supports(op)) { + MetricMemoizer opStats = stats.getOperationStats(op.getQualifiedName()); + double val = this.computeForOperation(key, op, force, version, opStats); + if (val != Double.NaN) { + values.add(val); + } + } + } + + // FUTURE use streams to do that when we upgrade the compiler to 1.8 + switch (option) { + case SUM: + return sum(values); + case HIGHEST: + return highest(values); + case AVERAGE: + return average(values); + default: + return Double.NaN; + } + } + + + /** + * Finds the declaration nodes of all methods or constructors that are declared inside a class. + * + * @param node The class in which to look for. + * + * @return The list of all operations declared inside the specified class. + */ + protected abstract List findOperations(T node); // TODO:cf this one is computed every time + + + private static double sum(List values) { + double sum = 0; + for (double val : values) { + sum += val; + } + return sum; + } + + + private static double highest(List values) { + double highest = Double.NEGATIVE_INFINITY; + for (double val : values) { + if (val > highest) { + highest = val; + } + } + return highest == Double.NEGATIVE_INFINITY ? 0 : highest; + } + + + private static double average(List values) { + return sum(values) / values.size(); + } + + +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricMemoizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricMemoizer.java new file mode 100644 index 0000000000..7005accb68 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricMemoizer.java @@ -0,0 +1,34 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.metrics; + +import java.util.HashMap; +import java.util.Map; + +import net.sourceforge.pmd.lang.ast.Node; + +/** + * Base class for metric memoizers. These objects memoize metrics of a specific type, see eg ClassStats in the Java + * framework. + * + * @param Type of node on which the memoized metric can be computed + * + * @author Clément Fournier + */ +public abstract class MetricMemoizer { + + + private final Map memo = new HashMap<>(); + + + Double getMemo(ParameterizedMetricKey key) { + return memo.get(key); + } + + + void memoize(ParameterizedMetricKey key, double value) { + memo.put(key, value); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ParameterizedMetricKey.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ParameterizedMetricKey.java index 077f660fe2..8ceeea41fb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ParameterizedMetricKey.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ParameterizedMetricKey.java @@ -16,18 +16,18 @@ import net.sourceforge.pmd.lang.metrics.api.MetricVersion; * * @author Clément Fournier */ -public final class ParameterizedMetricKey { +public final class ParameterizedMetricKey { - private static final Map POOL = new HashMap<>(); + private static final Map> POOL = new HashMap<>(); /** The metric key. */ - public final MetricKey key; + public final MetricKey key; /** The version of the metric. */ public final MetricVersion version; /** Used internally by the pooler. */ - private ParameterizedMetricKey(MetricKey key, MetricVersion version) { + private ParameterizedMetricKey(MetricKey key, MetricVersion version) { this.key = key; this.version = version; } @@ -57,13 +57,22 @@ public final class ParameterizedMetricKey { } - /** Builds a parameterized metric key. */ - public static ParameterizedMetricKey getInstance(MetricKey key, MetricVersion version) { + /** + * Builds a parameterized metric key. + * + * @param key The key + * @param version The version + * @param The type of node of the metrickey + * + * @return An instance of parameterized metric key corresponding to the parameters + */ + @SuppressWarnings("unchecked") + public static ParameterizedMetricKey getInstance(MetricKey key, MetricVersion version) { int code = code(key, version); - ParameterizedMetricKey paramKey = POOL.get(code); - if (paramKey == null) { - POOL.put(code, new ParameterizedMetricKey(key, version)); + if (!POOL.containsKey(code)) { + POOL.put(code, new ParameterizedMetricKey<>(key, version)); } - return POOL.get(code); + + return (ParameterizedMetricKey) POOL.get(code); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ProjectMirror.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ProjectMirror.java new file mode 100644 index 0000000000..bcbaff7d3f --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/ProjectMirror.java @@ -0,0 +1,48 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.metrics; + +import net.sourceforge.pmd.lang.ast.QualifiableNode; +import net.sourceforge.pmd.lang.ast.QualifiedName; +import net.sourceforge.pmd.lang.ast.SignedNode; + +/** + * Object storing the statistics and memoizers of the analysed project, like PackageStats for Java. These are the entry + * point for signature matching requests. If retrieving eg an operation stats is expensive, consider implementing a + * cache. + * + *

While classes and operations are widespread and vary little in form across (class based at least) object-oriented + * languages, the structure of a project is very language specific. For example, while an intuitive way to represent a + * Java project is with a package tree, Apex has no package system. We consider here that there's no point providing + * base implementations, so we use an interface. You could even implement it with a bunch of maps, which may yield good + * results! + * + * @param Type of type declaration nodes of the language + * @param Type of operation declaration nodes of the language + * + * @author Clément Fournier + */ +public interface ProjectMirror & QualifiableNode> { + + /** + * Gets the operation metric memoizer corresponding to the qualified name. + * + * @param qname The qualified name of the operation to fetch + * + * @return The correct memoizer, or null if it wasn't found + */ + MetricMemoizer getOperationStats(QualifiedName qname); + + + /** + * Gets the class metric memoizer corresponding to the qualified name. + * + * @param qname The qualified name of the class to fetch + * + * @return The correct memoizer, or null if it wasn't found + */ + MetricMemoizer getClassStats(QualifiedName qname); + +} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/ClassStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/ClassStats.java index abe791669d..10818f31eb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/ClassStats.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/ClassStats.java @@ -9,11 +9,13 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName; import net.sourceforge.pmd.lang.java.metrics.signature.FieldSigMask; import net.sourceforge.pmd.lang.java.metrics.signature.JavaFieldSignature; import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature; import net.sourceforge.pmd.lang.java.metrics.signature.OperationSigMask; +import net.sourceforge.pmd.lang.metrics.MetricMemoizer; /** * Statistics about a class, enum, interface, or annotation. Stores information about the contained members and their @@ -26,7 +28,7 @@ import net.sourceforge.pmd.lang.java.metrics.signature.OperationSigMask; * * @author Clément Fournier */ -/* default */ class ClassStats extends Memoizer { +/* default */ class ClassStats extends MetricMemoizer { private Map> operations = new HashMap<>(); private Map> fields = new HashMap<>(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsComputer.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsComputer.java index 6bcfbafa33..cb0830bcff 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsComputer.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsComputer.java @@ -10,131 +10,25 @@ import java.util.List; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeBodyDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; -import net.sourceforge.pmd.lang.metrics.ParameterizedMetricKey; -import net.sourceforge.pmd.lang.metrics.api.MetricKey; -import net.sourceforge.pmd.lang.metrics.api.MetricVersion; -import net.sourceforge.pmd.lang.metrics.api.ResultOption; +import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer; /** * Computes a metric. This relieves ClassStats and OperationStats from that responsibility. * * @author Clément Fournier */ -public class JavaMetricsComputer { +public class JavaMetricsComputer extends AbstractMetricsComputer { static final JavaMetricsComputer INSTANCE = new JavaMetricsComputer(); + private JavaMetricsComputer() { } - /** - * Computes the value of a metric for a class and stores the result in the ClassStats object. - * - * @param key The class metric to compute - * @param node The AST node of the class - * @param force Force the recomputation; if unset, we'll first check for a memoized result - * @param version The version of the metric to compute - * @param memoizer The object memoizing the results - * - * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed - */ - /* default */ double compute(MetricKey key, ASTAnyTypeDeclaration node, boolean force, - MetricVersion version, ClassStats memoizer) { - ParameterizedMetricKey paramKey = ParameterizedMetricKey.getInstance(key, version); - // if memo.get(key) == null then the metric has never been computed. NaN is a valid value. - Double prev = memoizer.getMemo(paramKey); - if (!force && prev != null) { - return prev; - } - - double val = key.getCalculator().computeFor(node, version); - memoizer.memoize(paramKey, val); - - return val; - } - - - /** - * Computes the value of a metric for an operation and stores the result in the OperationStats object. - * - * @param key The operation metric to compute - * @param node The AST node of the operation - * @param force Force the recomputation; if unset, we'll first check for a memoized result - * @param version The version of the metric to compute - * @param memoizer The object memoizing the results - * - * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed - */ - /* default */ double compute(MetricKey key, ASTMethodOrConstructorDeclaration node, - boolean force, MetricVersion version, OperationStats memoizer) { - - ParameterizedMetricKey paramKey = ParameterizedMetricKey.getInstance(key, version); - Double prev = memoizer.getMemo(paramKey); - if (!force && prev != null) { - return prev; - } - - double val = key.getCalculator().computeFor(node, version); - memoizer.memoize(paramKey, val); - return val; - } - - - /** - * Computes an aggregate result using a ResultOption. - * - * @param key The class metric to compute - * @param node The AST node of the class - * @param force Force the recomputation; if unset, we'll first check for a memoized result - * @param version The version of the metric - * @param option The type of result to compute - * @param stats The ClassStats storing info about the class - * - * @return The result of the computation, or {@code Double.NaN} if it couldn't be performed - */ - /* default */ double computeWithResultOption(MetricKey key, ASTAnyTypeDeclaration node, - boolean force, MetricVersion version, ResultOption option, ClassStats stats) { - - List ops = findOperations(node); - - List values = new ArrayList<>(); - for (ASTMethodOrConstructorDeclaration op : ops) { - if (key.supports(op)) { - OperationStats opStats = stats.getOperationStats(op.getQualifiedName().getOperation(), - op.getSignature()); - double val = this.compute(key, op, force, version, opStats); - if (val != Double.NaN) { - values.add(val); - } - } - } - - // FUTURE use streams to do that when we upgrade the compiler to 1.8 - switch (option) { - case SUM: - return sum(values); - case HIGHEST: - return highest(values); - case AVERAGE: - return average(values); - default: - return Double.NaN; - } - } - - - /** - * Finds the declaration nodes of all methods or constructors that are declared inside a class. - * - * @param node The class in which to look for. - * - * @return The list of all operations declared inside the specified class. - * - * TODO:cf this one is computed every time - */ - private static List findOperations(ASTAnyTypeDeclaration node) { + @Override + protected List findOperations(ASTAnyTypeDeclaration node) { List operations = new ArrayList<>(); @@ -146,30 +40,4 @@ public class JavaMetricsComputer { return operations; } - - private static double sum(List values) { - double sum = 0; - for (double val : values) { - sum += val; - } - return sum; - } - - - private static double highest(List values) { - double highest = Double.NEGATIVE_INFINITY; - for (double val : values) { - if (val > highest) { - highest = val; - } - } - return highest == Double.NEGATIVE_INFINITY ? 0 : highest; - } - - - private static double average(List values) { - return sum(values) / values.size(); - } - - } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsFacade.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsFacade.java index f63f3e8eed..faa893e6c4 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsFacade.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetricsFacade.java @@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.metrics.api.MetricVersion; import net.sourceforge.pmd.lang.metrics.api.ResultOption; /** - * Facade of the Java metrics framework. + * Inner façade of the Java metrics framework. The static façade delegates to an instance of this class. * * @author Clément Fournier */ @@ -48,7 +48,9 @@ class JavaMetricsFacade { * * @return The value of the metric, or {@code Double.NaN} if the value couln't be computed */ - public double computeForType(MetricKey key, ASTAnyTypeDeclaration node, MetricVersion version) { + double computeForType(MetricKey key, ASTAnyTypeDeclaration node, MetricVersion version) { + + checkKeyNotNull(key); if (!key.supports(node)) { return Double.NaN; @@ -58,7 +60,7 @@ class JavaMetricsFacade { ClassStats memoizer = topLevelPackageStats.getClassStats(node.getQualifiedName(), false); return memoizer == null ? Double.NaN - : JavaMetricsComputer.INSTANCE.compute(key, node, false, safeVersion, memoizer); + : JavaMetricsComputer.INSTANCE.computeForType(key, node, false, safeVersion, memoizer); } @@ -71,8 +73,10 @@ class JavaMetricsFacade { * * @return The value of the metric, or {@code Double.NaN} if the value couln't be computed */ - public double computeForOperation(MetricKey key, ASTMethodOrConstructorDeclaration node, - MetricVersion version) { + double computeForOperation(MetricKey key, ASTMethodOrConstructorDeclaration node, + MetricVersion version) { + + checkKeyNotNull(key); if (!key.supports(node)) { return Double.NaN; @@ -86,7 +90,8 @@ class JavaMetricsFacade { : container.getOperationStats(qname.getOperation(), node.getSignature()); return memoizer == null ? Double.NaN - : JavaMetricsComputer.INSTANCE.compute(key, node, false, safeVersion, memoizer); + : JavaMetricsComputer.INSTANCE.computeForOperation(key, node, false, safeVersion, + memoizer); } @@ -103,18 +108,25 @@ class JavaMetricsFacade { * @return The value of the metric, or {@code Double.NaN} if the value couln't be computed or {@code option} is * {@code null} */ - public double computeWithResultOption(MetricKey key, ASTAnyTypeDeclaration node, - MetricVersion version, ResultOption option) { + double computeWithResultOption(MetricKey key, ASTAnyTypeDeclaration node, + MetricVersion version, ResultOption option) { + + checkKeyNotNull(key); if (option == null) { throw new IllegalArgumentException("The result option may not be null"); } MetricVersion safeVersion = (version == null) ? Version.STANDARD : version; - ClassStats memoizer = topLevelPackageStats.getClassStats(node.getQualifiedName(), false); - return memoizer == null ? Double.NaN - : JavaMetricsComputer.INSTANCE.computeWithResultOption(key, node, false, safeVersion, - option, memoizer); + return JavaMetricsComputer.INSTANCE.computeWithResultOption(key, node, false, safeVersion, + option, topLevelPackageStats); + } + + + private void checkKeyNotNull(MetricKey key) { + if (key == null) { + throw new IllegalArgumentException("The metric key may not be null"); + } } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/Memoizer.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/Memoizer.java deleted file mode 100644 index 548974aa3f..0000000000 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/Memoizer.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.java.metrics; - -import java.util.HashMap; -import java.util.Map; - -import net.sourceforge.pmd.lang.metrics.ParameterizedMetricKey; - -/** - * @author Clément Fournier - */ -public abstract class Memoizer { - - - private final Map memo = new HashMap<>(); - - - Double getMemo(ParameterizedMetricKey key) { - return memo.get(key); - } - - - void memoize(ParameterizedMetricKey key, double value) { - memo.put(key, value); - } -} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/OperationStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/OperationStats.java index 96410dc748..97a45f8de4 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/OperationStats.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/OperationStats.java @@ -4,12 +4,15 @@ package net.sourceforge.pmd.lang.java.metrics; +import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.metrics.MetricMemoizer; + /** * Statistics for an operation. Keeps a map of all memoized metrics results. * * @author Clément Fournier */ -class OperationStats extends Memoizer { +class OperationStats extends MetricMemoizer { private final String name; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/PackageStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/PackageStats.java index 42afcabcac..206f466984 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/PackageStats.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/PackageStats.java @@ -7,10 +7,15 @@ package net.sourceforge.pmd.lang.java.metrics; import java.util.HashMap; import java.util.Map; +import net.sourceforge.pmd.lang.ast.QualifiedName; +import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName; import net.sourceforge.pmd.lang.java.metrics.signature.FieldSigMask; import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature; import net.sourceforge.pmd.lang.java.metrics.signature.OperationSigMask; +import net.sourceforge.pmd.lang.metrics.MetricMemoizer; +import net.sourceforge.pmd.lang.metrics.ProjectMirror; /** @@ -20,12 +25,13 @@ import net.sourceforge.pmd.lang.java.metrics.signature.OperationSigMask; * @author Clément Fournier * @see ClassStats */ -public final class PackageStats { +public final class PackageStats implements ProjectMirror { private final Map subPackages = new HashMap<>(); private final Map classes = new HashMap<>(); + /** * Default constructor. */ @@ -138,6 +144,7 @@ public final class PackageStats { return next; } + /** * Returns true if the signature of the operation designated by the qualified name is covered by the mask. * @@ -152,6 +159,7 @@ public final class PackageStats { return clazz != null && clazz.hasMatchingSig(qname.getOperation(), sigMask); } + /** * Returns true if the signature of the field designated by its name and the qualified name of its class is covered * by the mask. @@ -167,4 +175,16 @@ public final class PackageStats { return clazz != null && clazz.hasMatchingSig(fieldName, sigMask); } + + + @Override + public MetricMemoizer getOperationStats(QualifiedName qname) { + return getOperationStats((JavaQualifiedName) qname, null, false); + } + + + @Override + public MetricMemoizer getClassStats(QualifiedName qname) { + return getClassStats((JavaQualifiedName) qname, false); + } } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/DataStructureTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/DataStructureTest.java index 786683ef46..51d342b73b 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/DataStructureTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/DataStructureTest.java @@ -143,7 +143,7 @@ public class DataStructureTest extends ParserTst { @Override public Object visit(ASTMethodOrConstructorDeclaration node, Object data) { OperationStats op = toplevel.getOperationStats(node.getQualifiedName(), node.getSignature(), false); - result.add((int) JavaMetricsComputer.INSTANCE.compute(opMetricKey, node, force, Version.STANDARD, op)); + result.add((int) JavaMetricsComputer.INSTANCE.computeForOperation(opMetricKey, node, force, Version.STANDARD, op)); return super.visit(node, data); } @@ -151,7 +151,7 @@ public class DataStructureTest extends ParserTst { @Override public Object visit(ASTAnyTypeDeclaration node, Object data) { ClassStats clazz = toplevel.getClassStats(node.getQualifiedName(), false); - result.add((int) JavaMetricsComputer.INSTANCE.compute(classMetricKey, node, force, Version.STANDARD, clazz)); + result.add((int) JavaMetricsComputer.INSTANCE.computeForType(classMetricKey, node, force, Version.STANDARD, clazz)); return super.visit(node, data); } }, null);