Corrections for review #451
This commit is contained in:
@ -35,30 +35,6 @@ public abstract class AbstractMetric implements Metric {
|
|||||||
return Metrics.getTopLevelPackageStats();
|
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).
|
* 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).
|
* 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;
|
double total = 0;
|
||||||
for (ASTMethodOrConstructorDeclaration op : operations) {
|
for (ASTMethodOrConstructorDeclaration op : operations) {
|
||||||
double val = Metrics.get(key, op, version);
|
double val = Metrics.get(key, op, version);
|
||||||
total += val == Double.NaN ? 1 : val;
|
total += val == Double.NaN ? 0 : val;
|
||||||
}
|
}
|
||||||
return total / operations.size();
|
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).
|
* 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).
|
* 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;
|
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.
|
* 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;
|
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() {
|
public String toString() {
|
||||||
return "ParameterizedMetricKey{"
|
return "ParameterizedMetricKey{"
|
||||||
+ "key=" + key
|
+ "key=" + key
|
||||||
+ ", options=" + version
|
+ ", version=" + version
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ public class CyclomaticComplexityRule extends AbstractJavaRule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visit(ASTConstructorDeclaration node, Object data) {
|
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) {
|
if (showMethodsComplexity && cyclo >= reportLevel) {
|
||||||
addViolation(data, node, new String[] {"constructor", node.getQualifiedName().getOperation(), "" + cyclo});
|
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. */
|
/** Attempts to determine if the method is a setter. */
|
||||||
private static boolean isSetter(ASTMethodDeclaration node, Map<String, String> fieldNames) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<test-data>
|
<test-data>
|
||||||
<!--
|
|
||||||
<code-fragment id="basic-violation">
|
<code-fragment id="basic-violation">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
public class Complicated {
|
public class Complicated {
|
||||||
@ -233,7 +233,7 @@
|
|||||||
</expected-messages>
|
</expected-messages>
|
||||||
<code-ref id="fallthroughSwitch"/>
|
<code-ref id="fallthroughSwitch"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
-->
|
|
||||||
<code-fragment id="manyBooleanOps">
|
<code-fragment id="manyBooleanOps">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
class Foo {
|
class Foo {
|
||||||
@ -250,7 +250,7 @@
|
|||||||
}
|
}
|
||||||
]]>
|
]]>
|
||||||
</code-fragment>
|
</code-fragment>
|
||||||
<!--
|
|
||||||
<test-code>
|
<test-code>
|
||||||
<description>Standard Cyclo should count boolean paths</description>
|
<description>Standard Cyclo should count boolean paths</description>
|
||||||
<rule-property name="showClassesComplexity">false</rule-property>
|
<rule-property name="showClassesComplexity">false</rule-property>
|
||||||
@ -273,7 +273,7 @@
|
|||||||
</expected-messages>
|
</expected-messages>
|
||||||
<code-ref id="manyBooleanOps"/>
|
<code-ref id="manyBooleanOps"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
-->
|
|
||||||
<test-code>
|
<test-code>
|
||||||
<description>Avoid division by 0 when averaging a metric over no operations</description>
|
<description>Avoid division by 0 when averaging a metric over no operations</description>
|
||||||
<rule-property name="reportLevel">-1</rule-property>
|
<rule-property name="reportLevel">-1</rule-property>
|
||||||
|
Reference in New Issue
Block a user