Corrections for review #451
This commit is contained in:
@ -35,30 +35,6 @@ public abstract class AbstractMetric implements Metric {
|
||||
return Metrics.getTopLevelPackageStats();
|
||||
}
|
||||
|
||||
|
||||
protected List<QualifiedName> findAllCalls(ASTMethodOrConstructorDeclaration node) {
|
||||
List<QualifiedName> result = new ArrayList<>();
|
||||
// TODO:cf
|
||||
// Needs TypeRes
|
||||
// Find the qualified names of all methods called in that method's block
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation of the supports method, which filters out abstract nodes. Metrics that support abstract
|
||||
* nodes should override this method.
|
||||
*
|
||||
* @param node The node to check.
|
||||
*
|
||||
* @return True if the metric can be computed on this node.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(AccessNode node) {
|
||||
return !node.isAbstract();
|
||||
}
|
||||
|
||||
|
||||
// TODO:cf all these methods mimic the behaviour of resultoptions, perhaps not great.
|
||||
/**
|
||||
* Gets the sum of the value of an operation metric over all operations in this class (excluding nested classes).
|
||||
* The computation is not forced (memoized results are used if they can be found).
|
||||
@ -102,12 +78,14 @@ public abstract class AbstractMetric implements Metric {
|
||||
double total = 0;
|
||||
for (ASTMethodOrConstructorDeclaration op : operations) {
|
||||
double val = Metrics.get(key, op, version);
|
||||
total += val == Double.NaN ? 1 : val;
|
||||
total += val == Double.NaN ? 0 : val;
|
||||
}
|
||||
return total / operations.size();
|
||||
}
|
||||
|
||||
|
||||
// TODO:cf all these methods mimic the behaviour of resultoptions, perhaps not great.
|
||||
|
||||
/**
|
||||
* Gets the highest value of an operation metric over all operations in this class (excluding nested classes).
|
||||
* The computation is not forced (memoized results are used if they can be found).
|
||||
@ -135,10 +113,6 @@ public abstract class AbstractMetric implements Metric {
|
||||
return highest;
|
||||
}
|
||||
|
||||
|
||||
// TODO:cf this one is computed every time
|
||||
// TODO:cf it might not be at the best place too (used by ClassStats)
|
||||
|
||||
/**
|
||||
* Finds the declaration nodes of all methods or constructors that are declared inside a class.
|
||||
*
|
||||
@ -169,4 +143,29 @@ public abstract class AbstractMetric implements Metric {
|
||||
return operations;
|
||||
}
|
||||
|
||||
protected List<QualifiedName> findAllCalls(ASTMethodOrConstructorDeclaration node) {
|
||||
List<QualifiedName> result = new ArrayList<>();
|
||||
// TODO:cf
|
||||
// Needs TypeRes
|
||||
// Find the qualified names of all methods called in that method's block
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// TODO:cf this one is computed every time
|
||||
// TODO:cf it might not be at the best place too (used by ClassStats)
|
||||
|
||||
/**
|
||||
* Default implementation of the supports method, which filters out abstract nodes. Metrics that support abstract
|
||||
* nodes should override this method.
|
||||
*
|
||||
* @param node The node to check.
|
||||
*
|
||||
* @return True if the metric can be computed on this node.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(AccessNode node) {
|
||||
return !node.isAbstract();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public final class ParameterizedMetricKey {
|
||||
public String toString() {
|
||||
return "ParameterizedMetricKey{"
|
||||
+ "key=" + key
|
||||
+ ", options=" + version
|
||||
+ ", version=" + version
|
||||
+ '}';
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class CyclomaticComplexityRule extends AbstractJavaRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTConstructorDeclaration node, Object data) {
|
||||
int cyclo = (int) Metrics.get(OperationMetricKey.CYCLO, node);
|
||||
int cyclo = (int) Metrics.get(OperationMetricKey.CYCLO, node, cycloVersion);
|
||||
|
||||
if (showMethodsComplexity && cyclo >= reportLevel) {
|
||||
addViolation(data, node, new String[] {"constructor", node.getQualifiedName().getOperation(), "" + cyclo});
|
||||
|
@ -161,7 +161,7 @@ public final class OperationSignature extends Signature {
|
||||
/** Attempts to determine if the method is a setter. */
|
||||
private static boolean isSetter(ASTMethodDeclaration node, Map<String, String> fieldNames) {
|
||||
|
||||
if (node.getFirstDescendantOfType(ASTFormalParameters.class).jjtGetNumChildren() == 0) {
|
||||
if (node.getFirstDescendantOfType(ASTFormalParameters.class).jjtGetNumChildren() != 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<!--
|
||||
|
||||
<code-fragment id="basic-violation">
|
||||
<![CDATA[
|
||||
public class Complicated {
|
||||
@ -233,7 +233,7 @@
|
||||
</expected-messages>
|
||||
<code-ref id="fallthroughSwitch"/>
|
||||
</test-code>
|
||||
-->
|
||||
|
||||
<code-fragment id="manyBooleanOps">
|
||||
<![CDATA[
|
||||
class Foo {
|
||||
@ -250,7 +250,7 @@
|
||||
}
|
||||
]]>
|
||||
</code-fragment>
|
||||
<!--
|
||||
|
||||
<test-code>
|
||||
<description>Standard Cyclo should count boolean paths</description>
|
||||
<rule-property name="showClassesComplexity">false</rule-property>
|
||||
@ -273,7 +273,7 @@
|
||||
</expected-messages>
|
||||
<code-ref id="manyBooleanOps"/>
|
||||
</test-code>
|
||||
-->
|
||||
|
||||
<test-code>
|
||||
<description>Avoid division by 0 when averaging a metric over no operations</description>
|
||||
<rule-property name="reportLevel">-1</rule-property>
|
||||
|
Reference in New Issue
Block a user