diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java index 5879872d60..f9953d7191 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java @@ -4,6 +4,9 @@ package net.sourceforge.pmd.lang.java.internal; +import java.util.Arrays; +import java.util.List; + import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.Parser; @@ -16,7 +19,9 @@ import net.sourceforge.pmd.lang.java.ast.JavaParser; import net.sourceforge.pmd.lang.java.ast.MethodLikeNode; import net.sourceforge.pmd.lang.java.ast.internal.LanguageLevelChecker; import net.sourceforge.pmd.lang.java.ast.internal.ReportingStrategy; -import net.sourceforge.pmd.lang.java.metrics.JavaMetricsProvider; +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; import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleViolationFactory; import net.sourceforge.pmd.lang.java.xpath.GetCommentOnFunction; import net.sourceforge.pmd.lang.java.xpath.JavaFunctions; @@ -25,6 +30,8 @@ import net.sourceforge.pmd.lang.java.xpath.TypeIsExactlyFunction; import net.sourceforge.pmd.lang.java.xpath.TypeIsFunction; import net.sourceforge.pmd.lang.java.xpath.TypeOfFunction; import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider; +import net.sourceforge.pmd.lang.metrics.MetricKey; +import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider; import net.sourceforge.pmd.lang.rule.RuleViolationFactory; import net.sf.saxon.sxpath.IndependentContext; @@ -79,4 +86,28 @@ public class JavaLanguageHandler extends AbstractPmdLanguageVersionHandler { public LanguageMetricsProvider getLanguageMetricsProvider() { return myMetricsProvider; } + + + private static class JavaMetricsProvider extends AbstractLanguageMetricsProvider { + + JavaMetricsProvider() { + super(ASTAnyTypeDeclaration.class, MethodLikeNode.class); + } + + @Override + protected List findOps(ASTAnyTypeDeclaration astAnyTypeDeclaration) { + return JavaMetrics.findOps(astAnyTypeDeclaration); + } + + @Override + public List> getAvailableTypeMetrics() { + return Arrays.asList(JavaClassMetricKey.values()); + } + + + @Override + public List> getAvailableOperationMetrics() { + return Arrays.asList(JavaOperationMetricKey.values()); + } + } }