Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apex] Remove apex statistical rules #1750

Merged
merged 7 commits into from Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -70,6 +70,14 @@ public boolean hasSuppressWarningsAnnotationFor(Rule rule) {
return false;
}

/**
* Returns true if this is a synthetic class initializer, inserted
* by the parser.
*/
public boolean isSynthetic() {
return getImage().matches("<clinit>|<init>|clone");
}

public boolean isConstructor() {
return node.getMethodInfo().isConstructor();
}
Expand Down
Expand Up @@ -33,7 +33,7 @@ protected List<ASTMethod> findOperations(ASTUserClassOrInterface<?> node) {
List<ASTMethod> candidates = node.findChildrenOfType(ASTMethod.class);
List<ASTMethod> result = new ArrayList<>(candidates);
for (ASTMethod method : candidates) {
if (method.getImage().matches("(<clinit>|<init>|clone)")) {
if (method.isSynthetic()) {
result.remove(method);
}
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ public abstract class AbstractApexOperationMetric extends AbstractApexMetric<AST
*/
@Override
public boolean supports(ASTMethod node) {
return !node.getImage().matches("(<clinit>|<init>|clone)")
return !node.isSynthetic()
&& !node.getFirstChildOfType(ASTModifierNode.class).isAbstract();
}
}

This file was deleted.

@@ -0,0 +1,90 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/

package net.sourceforge.pmd.lang.apex.rule.design;

import static net.sourceforge.pmd.properties.constraints.NumericConstraints.positive;

import java.lang.reflect.Modifier;

import net.sourceforge.pmd.lang.apex.ast.AbstractApexNodeBase;
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
import net.sourceforge.pmd.lang.rule.internal.CommonPropertyDescriptors;
import net.sourceforge.pmd.properties.PropertyDescriptor;


/**
* Abstract class for rules counting some integer metric on some node.
*
* @author Clément Fournier
* @since 6.7.0
oowekyala marked this conversation as resolved.
Show resolved Hide resolved
*/
abstract class AbstractCounterCheckRule<T extends ApexNode<?>> extends AbstractApexRule {
oowekyala marked this conversation as resolved.
Show resolved Hide resolved


private final PropertyDescriptor<Integer> reportLevel =
CommonPropertyDescriptors.reportLevelProperty()
.desc("Threshold above which a node is reported")
.require(positive())
.defaultValue(defaultReportLevel()).build();


AbstractCounterCheckRule(Class<T> nodeType) {
definePropertyDescriptor(reportLevel);
if (!(Modifier.isAbstract(nodeType.getModifiers()) || nodeType.isInterface())) {
addRuleChainVisit(nodeType);
} else {
assert false : "Rule chain visits must be concrete node types";
oowekyala marked this conversation as resolved.
Show resolved Hide resolved
}
}


protected abstract int defaultReportLevel();


protected Object[] getViolationParameters(T node, int metric) {
return new Object[] {metric};
}


protected abstract int getMetric(T node);

/** Return true if the node should be ignored. */
protected boolean isIgnored(T node) {
return false;
}


@Override
public Object visit(AbstractApexNodeBase node, Object data) {
@SuppressWarnings("unchecked")
T t = (T) node;
// since we only visit this node, it's ok

if (!isIgnored(t)) {
int metric = getMetric(t);
if (metric >= getProperty(reportLevel)) {
addViolation(data, node, getViolationParameters(t, metric));
}
}

return data;
}

abstract static class AbstractLineLengthCheckRule<T extends ApexNode<?>> extends AbstractCounterCheckRule<T> {

AbstractLineLengthCheckRule(Class<T> nodeType) {
super(nodeType);
}

@Override
protected int getMetric(T node) {
return node.getEndLine() - node.getBeginLine();
}

}


}