diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/CycloMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/CycloMetric.java index 8641ee4b0c..842e08c2aa 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/CycloMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/CycloMetric.java @@ -25,23 +25,20 @@ import net.sourceforge.pmd.lang.java.oom.metrics.visitors.StandardCycloVisitor; *

The standard version of the metric complies with McCabe's original definition: * *

* *

Version {@link Version#IGNORE_BOOLEAN_PATHS}: Boolean operators are not counted, which means that empty * fall-through cases in {@code switch} statements are not counted as well. * - *

References: - *

+ *

References:

* * @author Clément Fournier * @since June 2017 diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/WmcMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/WmcMetric.java index 0bffe15ca4..7e36b8359d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/WmcMetric.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/WmcMetric.java @@ -12,7 +12,7 @@ import net.sourceforge.pmd.lang.java.oom.api.ResultOption; /** * Weighed Method Count. It is the sum of the statical complexity of all operations of a class. We use - * {@link CycloMetric} to quantify the complexity of a metric. [1] + * the standard version of {@link CycloMetric} to quantify the complexity of a metric. [1] * *

[1] Lanza. Object-Oriented Metrics in Practice. * diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/CycloPathUnawareOperationVisitor.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/CycloPathUnawareOperationVisitor.java index 827d34623e..31a6789861 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/CycloPathUnawareOperationVisitor.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/CycloPathUnawareOperationVisitor.java @@ -15,6 +15,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTForStatement; import net.sourceforge.pmd.lang.java.ast.ASTIfStatement; import net.sourceforge.pmd.lang.java.ast.ASTSwitchLabel; import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement; +import net.sourceforge.pmd.lang.java.ast.ASTThrowStatement; import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement; import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter; @@ -75,14 +76,6 @@ public class CycloPathUnawareOperationVisitor extends JavaParserVisitorAdapter { } - @Override - public Object visit(ASTCatchStatement node, Object data) { - ((MutableInt) data).increment(); - super.visit(node, data); - return data; - } - - @Override public Object visit(ASTForStatement node, Object data) { ((MutableInt) data).increment(); @@ -97,4 +90,21 @@ public class CycloPathUnawareOperationVisitor extends JavaParserVisitorAdapter { super.visit(node, data); return data; } + + + @Override + public Object visit(ASTCatchStatement node, Object data) { + ((MutableInt) data).increment(); + super.visit(node, data); + return data; + } + + + @Override + public Object visit(ASTThrowStatement node, Object data) { + ((MutableInt) data).increment(); + super.visit(node, data); + return data; + } + } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/DefaultNcssVisitor.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/DefaultNcssVisitor.java index a1e2c8e21e..f626572b83 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/DefaultNcssVisitor.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/DefaultNcssVisitor.java @@ -44,19 +44,6 @@ import net.sourceforge.pmd.lang.java.ast.JavaParserVisitorAdapter; */ public class DefaultNcssVisitor extends JavaParserVisitorAdapter { - @Override - public Object visit(ASTImportDeclaration node, Object data) { - ((MutableInt) data).increment(); - return data; - } - - - @Override - public Object visit(ASTPackageDeclaration node, Object data) { - ((MutableInt) data).increment(); - return data; - } - @Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/StandardCycloVisitor.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/StandardCycloVisitor.java index 70cde74873..ffe8ed9923 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/StandardCycloVisitor.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/visitors/StandardCycloVisitor.java @@ -97,4 +97,5 @@ public class StandardCycloVisitor extends CycloPathUnawareOperationVisitor { } return data; } + } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/CycloTest.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/CycloTest.xml index b34eb7a44d..e7302c2c1a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/CycloTest.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/CycloTest.xml @@ -4,6 +4,20 @@ - Complicated method - 2 + Complicated method - Standard + 3 - '.Complicated' has value 18 highest 17. - '.Complicated#example()' has value 17. + '.Complicated' has value 13 highest 21. + '.Complicated#exception()' has value 4. + '.Complicated#example()' has value 21. + + + + + + Complicated method - Ignore boolean path version + 3 + ignoreBooleanPaths + + '.Complicated' has value 10 highest 14. + '.Complicated#exception()' has value 4. + '.Complicated#example()' has value 14.