diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricKeyUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricKeyUtil.java index d5391b3ae0..4388489784 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricKeyUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/metrics/MetricKeyUtil.java @@ -22,7 +22,7 @@ public class MetricKeyUtil { /** - * Creates a new metric key holding a metric which can be computed on a class. + * Creates a new metric key from its metric and name. * * @param name The name of the metric * @param metric The metric to use diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetrics.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetrics.java index 607703b590..dd1134bcd2 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetrics.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaMetrics.java @@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.java.metrics; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.MetricKey; import net.sourceforge.pmd.lang.metrics.MetricOptions; import net.sourceforge.pmd.lang.metrics.ResultOption; @@ -79,7 +79,7 @@ public final class JavaMetrics { * * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed */ - public static double get(MetricKey key, ASTMethodOrConstructorDeclaration node) { + public static double get(MetricKey key, MethodLike node) { return FACADE.computeForOperation(key, node, MetricOptions.emptyOptions()); } @@ -93,8 +93,7 @@ public final class JavaMetrics { * * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed */ - public static double get(MetricKey key, ASTMethodOrConstructorDeclaration node, - MetricOptions options) { + public static double get(MetricKey key, MethodLike node, MetricOptions options) { return FACADE.computeForOperation(key, node, options); } @@ -107,10 +106,9 @@ public final class JavaMetrics { * @param node The node on which to compute the metric * @param resultOption The result option to use * - * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed or {@code option} is - * {@code null} + * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed */ - public static double get(MetricKey key, ASTAnyTypeDeclaration node, ResultOption resultOption) { + public static double get(MetricKey key, ASTAnyTypeDeclaration node, ResultOption resultOption) { return FACADE.computeWithResultOption(key, node, MetricOptions.emptyOptions(), resultOption); } @@ -124,10 +122,9 @@ public final class JavaMetrics { * @param resultOption The result option to use * @param options The version of the metric * - * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed or {@code option} is - * {@code null} + * @return The value of the metric, or {@code Double.NaN} if the value couldn't be computed */ - public static double get(MetricKey key, ASTAnyTypeDeclaration node, + public static double get(MetricKey key, ASTAnyTypeDeclaration node, MetricOptions options, ResultOption resultOption) { return FACADE.computeWithResultOption(key, node, options, resultOption); } 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 63287a7d8a..2c989762b7 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,6 +10,7 @@ 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.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer; /** @@ -17,7 +18,7 @@ import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer; * * @author Clément Fournier */ -public class JavaMetricsComputer extends AbstractMetricsComputer { +public class JavaMetricsComputer extends AbstractMetricsComputer { static final JavaMetricsComputer INSTANCE = new JavaMetricsComputer(); @@ -26,11 +27,11 @@ public class JavaMetricsComputer extends AbstractMetricsComputer findOperations(ASTAnyTypeDeclaration node) { + protected List findOperations(ASTAnyTypeDeclaration node) { - List operations = new ArrayList<>(); + List operations = new ArrayList<>(); for (ASTAnyTypeBodyDeclaration decl : node.getDeclarations()) { if (decl.jjtGetNumChildren() > 0 && decl.jjtGetChild(0) instanceof ASTMethodOrConstructorDeclaration) { 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 26cf94d683..129d7b3840 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 @@ -5,7 +5,7 @@ package net.sourceforge.pmd.lang.java.metrics; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.AbstractMetricsFacade; import net.sourceforge.pmd.lang.metrics.MetricsComputer; @@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.metrics.MetricsComputer; * * @author Clément Fournier */ -class JavaMetricsFacade extends AbstractMetricsFacade { +class JavaMetricsFacade extends AbstractMetricsFacade { private final JavaProjectMemoizer memoizer = new JavaProjectMemoizer(); @@ -32,7 +32,7 @@ class JavaMetricsFacade extends AbstractMetricsFacade getLanguageSpecificComputer() { + protected MetricsComputer getLanguageSpecificComputer() { return JavaMetricsComputer.INSTANCE; } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaProjectMemoizer.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaProjectMemoizer.java index c85c1a2f92..f7159e1d65 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaProjectMemoizer.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/JavaProjectMemoizer.java @@ -5,7 +5,7 @@ package net.sourceforge.pmd.lang.java.metrics; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.BasicProjectMemoizer; /** @@ -13,6 +13,6 @@ import net.sourceforge.pmd.lang.metrics.BasicProjectMemoizer; * * @author Clément Fournier */ -class JavaProjectMemoizer extends BasicProjectMemoizer { +class JavaProjectMemoizer extends BasicProjectMemoizer { } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetric.java index 2026085579..e52e22e70f 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetric.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.java.metrics.api; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.Metric; /** @@ -12,7 +12,7 @@ import net.sourceforge.pmd.lang.metrics.Metric; * * @author Clément Fournier */ -public interface JavaOperationMetric extends Metric { +public interface JavaOperationMetric extends Metric { } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetricKey.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetricKey.java index 152a3bf4d9..aa61895551 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetricKey.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/api/JavaOperationMetricKey.java @@ -4,7 +4,7 @@ package net.sourceforge.pmd.lang.java.metrics.api; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.impl.AtfdMetric.AtfdOperationMetric; import net.sourceforge.pmd.lang.java.metrics.impl.CycloMetric; import net.sourceforge.pmd.lang.java.metrics.impl.LocMetric.LocOperationMetric; @@ -12,10 +12,11 @@ import net.sourceforge.pmd.lang.java.metrics.impl.NcssMetric.NcssOperationMetric import net.sourceforge.pmd.lang.java.metrics.impl.NpathMetric; import net.sourceforge.pmd.lang.metrics.MetricKey; + /** * Keys identifying standard operation metrics. */ -public enum JavaOperationMetricKey implements MetricKey { +public enum JavaOperationMetricKey implements MetricKey { /** * Access to Foreign Data. @@ -69,9 +70,7 @@ public enum JavaOperationMetricKey implements MetricKey - implements JavaOperationMetric { +public abstract class AbstractJavaOperationMetric extends AbstractJavaMetric + implements JavaOperationMetric { /** * Returns true if the metric can be computed on this operation. By default, abstract operations are filtered out. @@ -23,7 +25,7 @@ public abstract class AbstractJavaOperationMetric extends AbstractJavaMetric opts = options.getOptions(); JavaParserDecoratedVisitor visitor = new JavaParserDecoratedVisitor(CycloBaseVisitor.INSTANCE); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/LocMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/LocMetric.java index 79324a9ed9..f39ab4d426 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/LocMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/LocMetric.java @@ -5,7 +5,7 @@ package net.sourceforge.pmd.lang.java.metrics.impl; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.metrics.MetricOptions; /** @@ -21,13 +21,13 @@ public final class LocMetric { public static final class LocOperationMetric extends AbstractJavaOperationMetric { @Override - public boolean supports(ASTMethodOrConstructorDeclaration node) { + public boolean supports(MethodLike node) { return true; } @Override - public double computeFor(ASTMethodOrConstructorDeclaration node, MetricOptions options) { + public double computeFor(MethodLike node, MetricOptions options) { return 1 + node.getEndLine() - node.getBeginLine(); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NcssMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NcssMetric.java index 841a4e0c1d..cb141bb8f5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NcssMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NcssMetric.java @@ -9,8 +9,8 @@ import java.util.Set; import org.apache.commons.lang3.mutable.MutableInt; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaParserDecoratedVisitor; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.impl.visitors.NcssBaseVisitor; import net.sourceforge.pmd.lang.java.metrics.impl.visitors.NcssCountImportsDecorator; import net.sourceforge.pmd.lang.metrics.MetricOption; @@ -73,13 +73,13 @@ public final class NcssMetric { public static final class NcssOperationMetric extends AbstractJavaOperationMetric { @Override - public boolean supports(ASTMethodOrConstructorDeclaration node) { + public boolean supports(MethodLike node) { return true; } @Override - public double computeFor(ASTMethodOrConstructorDeclaration node, MetricOptions version) { + public double computeFor(MethodLike node, MetricOptions version) { Set options = version.getOptions(); JavaParserDecoratedVisitor visitor = new JavaParserDecoratedVisitor(NcssBaseVisitor.INSTANCE); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NpathMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NpathMetric.java index 634fcc6e26..7a21477337 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NpathMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/metrics/impl/NpathMetric.java @@ -5,7 +5,7 @@ package net.sourceforge.pmd.lang.java.metrics.impl; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.impl.visitors.NpathBaseVisitor; import net.sourceforge.pmd.lang.metrics.MetricOptions; @@ -18,7 +18,7 @@ import net.sourceforge.pmd.lang.metrics.MetricOptions; public class NpathMetric extends AbstractJavaOperationMetric { @Override - public double computeFor(ASTMethodOrConstructorDeclaration node, MetricOptions options) { + public double computeFor(MethodLike node, MetricOptions options) { return (Integer) node.jjtAccept(NpathBaseVisitor.INSTANCE, null); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaMetricsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaMetricsRule.java index 45c84d2241..7ff5166c71 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaMetricsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractJavaMetricsRule.java @@ -9,9 +9,12 @@ import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTLambdaExpression; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaNode; +import net.sourceforge.pmd.lang.java.ast.MethodLike; + /** * Java Rule with convenient visit methods to e.g. treat contructors and methods the same. @@ -54,10 +57,19 @@ public abstract class AbstractJavaMetricsRule extends AbstractJavaRule { return visit((ASTMethodOrConstructorDeclaration) node, data); } - - public Object visit(ASTMethodOrConstructorDeclaration node, Object data) { - return visit((JavaNode) node, data); + @Override + public final Object visit(ASTLambdaExpression node, Object data) { + return visit((MethodLike) node, data); } + public Object visit(ASTMethodOrConstructorDeclaration node, Object data) { + return visit((MethodLike) node, data); + } + + + public Object visit(MethodLike node, Object data) { + return visit((JavaNode) node, data); + } + } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/MetricFunction.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/MetricFunction.java index d53d88bb87..ffc12e888c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/MetricFunction.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/xpath/MetricFunction.java @@ -10,18 +10,23 @@ import java.util.Map; import org.apache.commons.lang3.EnumUtils; import org.jaxen.Context; import org.jaxen.Function; -import org.jaxen.FunctionCallException; import org.jaxen.SimpleFunctionContext; import org.jaxen.XPathFunctionContext; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.JavaMetrics; import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey; import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey; + /** + * Implements the {@code metric()} XPath function. Takes the + * string name of a metric and the context node and returns + * the result if the metric can be computed, otherwise returns + * {@link Double#NaN}. + * * @author Clément Fournier * @since 6.0.0 */ @@ -33,9 +38,7 @@ public class MetricFunction implements Function { @Override - public Object call(Context context, List args) throws FunctionCallException { - - String metricKeyName = null; + public Object call(Context context, List args) { if (args.size() == 0) { throw new IllegalArgumentException(badMetricKeyArgMessage()); @@ -45,9 +48,9 @@ public class MetricFunction implements Function { throw new IllegalArgumentException(badMetricKeyArgMessage()); } - metricKeyName = (String) args.get(0); - + String metricKeyName = (String) args.get(0); Node n = (Node) context.getNodeSet().get(0); + return getMetric(n, metricKeyName); } @@ -75,8 +78,8 @@ public class MetricFunction implements Function { public static double getMetric(Node n, String metricKeyName) { if (n instanceof ASTAnyTypeDeclaration) { return getClassMetric((ASTAnyTypeDeclaration) n, getClassMetricKey(metricKeyName)); - } else if (n instanceof ASTMethodOrConstructorDeclaration) { - return getOpMetric((ASTMethodOrConstructorDeclaration) n, getOperationMetricKey(metricKeyName)); + } else if (n instanceof MethodLike) { + return getOpMetric((MethodLike) n, getOperationMetricKey(metricKeyName)); } else { throw new IllegalStateException(genericBadNodeMessage()); } @@ -101,7 +104,7 @@ public class MetricFunction implements Function { } - private static double getOpMetric(ASTMethodOrConstructorDeclaration node, JavaOperationMetricKey key) { + private static double getOpMetric(MethodLike node, JavaOperationMetricKey key) { return JavaMetrics.get(key, node); } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/ProjectMemoizerTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/ProjectMemoizerTest.java index 49a0a41267..c005465b36 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/ProjectMemoizerTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/ProjectMemoizerTest.java @@ -19,6 +19,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorReducedAdapter; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.impl.AbstractJavaClassMetric; import net.sourceforge.pmd.lang.java.metrics.impl.AbstractJavaOperationMetric; import net.sourceforge.pmd.lang.java.metrics.testdata.MetricsVisitorTestData; @@ -33,7 +34,7 @@ import net.sourceforge.pmd.lang.metrics.MetricOptions; public class ProjectMemoizerTest { private MetricKey classMetricKey = MetricKeyUtil.of(null, new RandomClassMetric()); - private MetricKey opMetricKey = MetricKeyUtil.of(null, new RandomOperationMetric()); + private MetricKey opMetricKey = MetricKeyUtil.of(null, new RandomOperationMetric()); @Test @@ -72,7 +73,7 @@ public class ProjectMemoizerTest { acu.jjtAccept(new JavaParserVisitorReducedAdapter() { @Override public Object visit(ASTMethodOrConstructorDeclaration node, Object data) { - MetricMemoizer op = toplevel.getOperationMemoizer(node.getQualifiedName()); + MetricMemoizer op = toplevel.getOperationMemoizer(node.getQualifiedName()); result.add((int) JavaMetricsComputer.INSTANCE.computeForOperation(opMetricKey, node, force, MetricOptions.emptyOptions(), op)); return super.visit(node, data); @@ -98,7 +99,7 @@ public class ProjectMemoizerTest { @Override - public double computeFor(ASTMethodOrConstructorDeclaration node, MetricOptions options) { + public double computeFor(MethodLike node, MetricOptions options) { return random.nextInt(); } } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/impl/AbstractMetricTestRule.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/impl/AbstractMetricTestRule.java index 083297d419..8d9ecb4090 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/impl/AbstractMetricTestRule.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/metrics/impl/AbstractMetricTestRule.java @@ -11,7 +11,7 @@ import java.util.Map; import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; -import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration; +import net.sourceforge.pmd.lang.java.ast.MethodLike; import net.sourceforge.pmd.lang.java.metrics.JavaMetrics; import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey; import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey; @@ -157,7 +157,7 @@ public abstract class AbstractMetricTestRule extends AbstractJavaMetricsRule { @Override - public Object visit(ASTMethodOrConstructorDeclaration node, Object data) { + public Object visit(MethodLike node, Object data) { if (opKey != null && reportMethods && opKey.supports(node)) { double methodValue = JavaMetrics.get(opKey, node, metricOptions); if (methodValue >= reportLevel) {