Move metric providers back into language handlers
Reverts part of #2231
This commit is contained in:
@ -166,8 +166,10 @@ methods on {% jdoc apex::lang.apex.ast.ApexParserVisitor %} and its implementati
|
||||
following nodes: WhileStatement, DoStatement, ForStatement, IfStatement, AssertStatement, ConditionalExpression.
|
||||
* {% jdoc java::lang.java.ast.ASTYieldStatement %} will not implement {% jdoc java::lang.java.ast.TypeNode %}
|
||||
anymore come 7.0.0. Test the type of the expression nested within it.
|
||||
* {% jdoc core::lang.java.metrics.JavaMetrics %}, {% jdoc core::lang.java.metrics.JavaMetricsComputer %},
|
||||
{% jdoc core::lang.java.metrics.JavaMetricsProvider %}
|
||||
* {% jdoc java::lang.java.metrics.JavaMetrics %}, {% jdoc java::lang.java.metrics.JavaMetricsComputer %}
|
||||
* pmd-apex
|
||||
* {% jdoc java::lang.apex.metrics.ApexMetrics %}, {% jdoc java::lang.java.metrics.JavaMetricsComputer %}
|
||||
|
||||
|
||||
|
||||
### External Contributions
|
||||
|
@ -5,6 +5,8 @@
|
||||
package net.sourceforge.pmd.lang.apex;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
@ -15,11 +17,14 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.DumpFacade;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.ApexMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.ApexMetrics;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.multifile.ApexMultifileVisitorFacade;
|
||||
import net.sourceforge.pmd.lang.apex.rule.ApexRuleViolationFactory;
|
||||
import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler;
|
||||
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
|
||||
|
||||
|
||||
@ -65,4 +70,29 @@ public class ApexHandler extends AbstractLanguageVersionHandler {
|
||||
public LanguageMetricsProvider<ASTUserClassOrInterface<?>, ASTMethod> getLanguageMetricsProvider() {
|
||||
return myMetricsProvider;
|
||||
}
|
||||
|
||||
private static class ApexMetricsProvider extends AbstractLanguageMetricsProvider<ASTUserClassOrInterface<?>, ASTMethod> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ApexMetricsProvider() {
|
||||
// a wild double cast
|
||||
super((Class<ASTUserClassOrInterface<?>>) (Object) ASTUserClassOrInterface.class, ASTMethod.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApexClassMetricKey> getAvailableTypeMetrics() {
|
||||
return Arrays.asList(ApexClassMetricKey.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<ASTMethod> findOps(ASTUserClassOrInterface<?> astUserClassOrInterface) {
|
||||
return ApexMetrics.findOps(astUserClassOrInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApexOperationMetricKey> getAvailableOperationMetrics() {
|
||||
return Arrays.asList(ApexOperationMetricKey.values());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import net.sourceforge.pmd.lang.metrics.ResultOption;
|
||||
*
|
||||
* @author Clément Fournier
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @deprecated Use {@link MetricsUtil}
|
||||
*/
|
||||
@Deprecated
|
||||
@ -138,7 +137,7 @@ public final class ApexMetrics {
|
||||
|
||||
|
||||
@NonNull
|
||||
static List<ASTMethod> findOps(ASTUserClassOrInterface<?> node) {
|
||||
public static List<ASTMethod> findOps(ASTUserClassOrInterface<?> node) {
|
||||
List<ASTMethod> candidates = node.findChildrenOfType(ASTMethod.class);
|
||||
List<ASTMethod> result = new ArrayList<>(candidates);
|
||||
for (ASTMethod method : candidates) {
|
||||
|
@ -10,12 +10,15 @@ import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricsComputer;
|
||||
|
||||
/**
|
||||
* Computes metrics for the Apex framework.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
* @deprecated See {@link MetricsComputer}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ApexMetricsComputer extends AbstractMetricsComputer<ASTUserClassOrInterface<?>, ASTMethod> {
|
||||
|
||||
private static final ApexMetricsComputer INSTANCE = new ApexMetricsComputer();
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.metrics;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider;
|
||||
|
||||
public class ApexMetricsProvider extends AbstractLanguageMetricsProvider<ASTUserClassOrInterface<?>, ASTMethod> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ApexMetricsProvider() {
|
||||
// a wild double cast
|
||||
super((Class<ASTUserClassOrInterface<?>>) (Object) ASTUserClassOrInterface.class, ASTMethod.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApexClassMetricKey> getAvailableTypeMetrics() {
|
||||
return Arrays.asList(ApexClassMetricKey.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<ASTMethod> findOps(ASTUserClassOrInterface<?> astUserClassOrInterface) {
|
||||
return ApexMetrics.findOps(astUserClassOrInterface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ApexOperationMetricKey> getAvailableOperationMetrics() {
|
||||
return Arrays.asList(ApexOperationMetricKey.values());
|
||||
}
|
||||
}
|
@ -13,5 +13,6 @@ import net.sourceforge.pmd.lang.metrics.BasicProjectMemoizer;
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@Deprecated
|
||||
class ApexProjectMemoizer extends BasicProjectMemoizer<ASTUserClassOrInterface<?>, ASTMethod> {
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.java.ast.JavaNode;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
|
||||
import net.sourceforge.pmd.lang.java.dfa.DataFlowFacade;
|
||||
import net.sourceforge.pmd.lang.java.dfa.JavaDFAGraphRule;
|
||||
import net.sourceforge.pmd.lang.java.metrics.JavaMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.java.JavaLanguageHandler.JavaMetricsProvider;
|
||||
import net.sourceforge.pmd.lang.java.multifile.MultifileVisitorFacade;
|
||||
import net.sourceforge.pmd.lang.java.qname.QualifiedNameResolver;
|
||||
import net.sourceforge.pmd.lang.java.rule.JavaRuleViolationFactory;
|
||||
|
@ -4,10 +4,20 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.Parser;
|
||||
import net.sourceforge.pmd.lang.ParserOptions;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
|
||||
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.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider;
|
||||
|
||||
/**
|
||||
* @deprecated This is internal API, use {@link LanguageVersion#getLanguageVersionHandler()}.
|
||||
@ -31,4 +41,27 @@ public class JavaLanguageHandler extends AbstractJavaHandler {
|
||||
public Parser getParser(ParserOptions parserOptions) {
|
||||
return new JavaLanguageParser(jdkVersion, preview, parserOptions);
|
||||
}
|
||||
|
||||
public static class JavaMetricsProvider extends AbstractLanguageMetricsProvider<ASTAnyTypeDeclaration, MethodLikeNode> {
|
||||
|
||||
public JavaMetricsProvider() {
|
||||
super(ASTAnyTypeDeclaration.class, MethodLikeNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<MethodLikeNode> findOps(ASTAnyTypeDeclaration astAnyTypeDeclaration) {
|
||||
return JavaMetrics.findOps(astAnyTypeDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends MetricKey<ASTAnyTypeDeclaration>> getAvailableTypeMetrics() {
|
||||
return Arrays.asList(JavaClassMetricKey.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<? extends MetricKey<MethodLikeNode>> getAvailableOperationMetrics() {
|
||||
return Arrays.asList(JavaOperationMetricKey.values());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ public final class JavaMetrics {
|
||||
return MetricsUtil.computeAggregate(key, findOps(node), options, resultOption);
|
||||
}
|
||||
|
||||
static List<MethodLikeNode> findOps(ASTAnyTypeDeclaration node) {
|
||||
public static List<MethodLikeNode> findOps(ASTAnyTypeDeclaration node) {
|
||||
List<MethodLikeNode> operations = new ArrayList<>();
|
||||
|
||||
for (ASTAnyTypeBodyDeclaration decl : node.getDeclarations()) {
|
||||
|
@ -1,44 +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.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.MethodLikeNode;
|
||||
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.internal.AbstractLanguageMetricsProvider;
|
||||
|
||||
/**
|
||||
* @deprecated This is internal API
|
||||
*/
|
||||
@Deprecated
|
||||
@InternalApi
|
||||
public class JavaMetricsProvider extends AbstractLanguageMetricsProvider<ASTAnyTypeDeclaration, MethodLikeNode> {
|
||||
|
||||
public JavaMetricsProvider() {
|
||||
super(ASTAnyTypeDeclaration.class, MethodLikeNode.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<MethodLikeNode> findOps(ASTAnyTypeDeclaration astAnyTypeDeclaration) {
|
||||
return JavaMetrics.findOps(astAnyTypeDeclaration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends MetricKey<ASTAnyTypeDeclaration>> getAvailableTypeMetrics() {
|
||||
return Arrays.asList(JavaClassMetricKey.values());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<? extends MetricKey<MethodLikeNode>> getAvailableOperationMetrics() {
|
||||
return Arrays.asList(JavaOperationMetricKey.values());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user