forked from phoedos/pmd
Merge branch 'pr-580'
This commit is contained in:
@ -242,4 +242,5 @@ All existing rules have been updated to reflect these changes. If you have custo
|
|||||||
* [#573](https://github.com/pmd/pmd/pull/573): \[java] Data class rule - [Clément Fournier](https://github.com/oowekyala)
|
* [#573](https://github.com/pmd/pmd/pull/573): \[java] Data class rule - [Clément Fournier](https://github.com/oowekyala)
|
||||||
* [#576](https://github.com/pmd/pmd/pull/576): \[doc]\[java] Add hint for Guava users in InefficientEmptyStringCheck - [mmoehring](https://github.com/mmoehring)
|
* [#576](https://github.com/pmd/pmd/pull/576): \[doc]\[java] Add hint for Guava users in InefficientEmptyStringCheck - [mmoehring](https://github.com/mmoehring)
|
||||||
* [#578](https://github.com/pmd/pmd/pull/578): \[java] Refactored god class rule - [Clément Fournier](https://github.com/oowekyala)
|
* [#578](https://github.com/pmd/pmd/pull/578): \[java] Refactored god class rule - [Clément Fournier](https://github.com/oowekyala)
|
||||||
|
* [#580](https://github.com/pmd/pmd/pull/580): \[core] Add AbstractMetric to topple the class hierarchy of metrics - [Clément Fournier](https://github.com/oowekyala)
|
||||||
* [#581](https://github.com/pmd/pmd/pull/581): \[java] Relax AbstractClassWithoutAnyMethod when class is annotated by @AutoValue - [Niklas Baudy](https://github.com/vanniktech)
|
* [#581](https://github.com/pmd/pmd/pull/581): \[java] Relax AbstractClassWithoutAnyMethod when class is annotated by @AutoValue - [Niklas Baudy](https://github.com/vanniktech)
|
||||||
|
@ -4,12 +4,16 @@
|
|||||||
|
|
||||||
package net.sourceforge.pmd.lang.apex.metrics;
|
package net.sourceforge.pmd.lang.apex.metrics;
|
||||||
|
|
||||||
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
|
import net.sourceforge.pmd.lang.metrics.AbstractMetric;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all Apex metrics.
|
* Base class for all Apex metrics.
|
||||||
*
|
*
|
||||||
* @author Clément Fournier
|
* @author Clément Fournier
|
||||||
*/
|
*/
|
||||||
public class AbstractApexMetric {
|
public abstract class AbstractApexMetric<N extends Node> extends AbstractMetric<N> {
|
||||||
|
|
||||||
|
|
||||||
protected ApexSignatureMatcher getSignatureMatcher() {
|
protected ApexSignatureMatcher getSignatureMatcher() {
|
||||||
return ApexMetrics.getFacade().getProjectMirror();
|
return ApexMetrics.getFacade().getProjectMirror();
|
||||||
|
@ -14,7 +14,8 @@ import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetric;
|
|||||||
*
|
*
|
||||||
* @author Clément Fournier
|
* @author Clément Fournier
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractApexClassMetric extends AbstractApexMetric implements ApexClassMetric {
|
public abstract class AbstractApexClassMetric extends AbstractApexMetric<ASTUserClassOrInterface<?>>
|
||||||
|
implements ApexClassMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(ASTUserClassOrInterface<?> node) {
|
public boolean supports(ASTUserClassOrInterface<?> node) {
|
||||||
|
@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetric;
|
|||||||
*
|
*
|
||||||
* @author Clément Fournier
|
* @author Clément Fournier
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractApexOperationMetric extends AbstractApexMetric implements ApexOperationMetric {
|
public abstract class AbstractApexOperationMetric extends AbstractApexMetric<ASTMethod> implements ApexOperationMetric {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the metric can be computed on the node. For now, we filter out {@literal <clinit>, <init> and clone},
|
* Checks if the metric can be computed on the node. For now, we filter out {@literal <clinit>, <init> and clone},
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* 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.Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for all metrics.
|
||||||
|
*
|
||||||
|
* @param <N> Type of nodes the metric can be computed on
|
||||||
|
*
|
||||||
|
* @author Clément Fournier
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
public abstract class AbstractMetric<N extends Node> implements Metric<N> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metrics should be stateless, thus any instance of the same metric class should be equal.
|
||||||
|
*
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object o) {
|
||||||
|
return o != null && o.getClass() == this.getClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
return getClass().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
import net.sourceforge.pmd.lang.ast.Node;
|
import net.sourceforge.pmd.lang.ast.Node;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName;
|
import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName;
|
||||||
import net.sourceforge.pmd.lang.metrics.Metric;
|
import net.sourceforge.pmd.lang.metrics.AbstractMetric;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.metrics.Metric;
|
|||||||
*
|
*
|
||||||
* @author Clément Fournier
|
* @author Clément Fournier
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractJavaMetric<N extends Node> implements Metric<N> {
|
public abstract class AbstractJavaMetric<N extends Node> extends AbstractMetric<N> {
|
||||||
|
|
||||||
|
|
||||||
protected List<JavaQualifiedName> findAllCalls(ASTMethodOrConstructorDeclaration node) {
|
protected List<JavaQualifiedName> findAllCalls(ASTMethodOrConstructorDeclaration node) {
|
||||||
@ -33,18 +33,6 @@ public abstract class AbstractJavaMetric<N extends Node> implements Metric<N> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean equals(Object o) {
|
|
||||||
return o != null && o.getClass() == this.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int hashCode() {
|
|
||||||
return getClass().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives access to a signature matcher to metrics. They can use it to perform signature matching.
|
* Gives access to a signature matcher to metrics. They can use it to perform signature matching.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user