diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java index b939df5c09..e9ac0a2262 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTClassOrInterfaceDeclaration.java @@ -61,7 +61,7 @@ public class ASTClassOrInterfaceDeclaration extends AbstractJavaAccessTypeNode i } @Override - public TypeKind getTypeKind(){ + public TypeKind getTypeKind() { return isInterface() ? TypeKind.INTERFACE : TypeKind.CLASS; } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java index fa88fdfbe5..1b8543289b 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTEnumDeclaration.java @@ -43,7 +43,7 @@ public class ASTEnumDeclaration extends AbstractJavaAccessTypeNode implements AS } @Override - public TypeKind getTypeKind(){ + public TypeKind getTypeKind() { return TypeKind.ENUM; } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/ClassStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/ClassStats.java index e1076cf257..0a884d5270 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/ClassStats.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/ClassStats.java @@ -29,8 +29,8 @@ import net.sourceforge.pmd.lang.java.oom.signature.OperationSignature; /** * Statistics about a class, enum, interface, or annotation. Gathers information about the contained members and their * signatures. This class does not provide methods to operate directly on its nested classes, but only on itself. To - * operate on a nested class, retrieve the correct ClassStats with {@link PackageStats#getClassStats(QualifiedName, - * boolean)} then use the methods of ClassStats. + * operate on a nested class, retrieve the correct ClassStats with + * {@link PackageStats#getClassStats(QualifiedName, boolean)} then use the methods of ClassStats. * *
Note that at this level, entities of the DS do not manipulate QualifiedNames anymore, only Strings.
*
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/OperationStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/OperationStats.java
index c1d9acf422..742b270133 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/OperationStats.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/OperationStats.java
@@ -9,7 +9,6 @@ import java.util.Map;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
import net.sourceforge.pmd.lang.java.oom.api.MemoKey;
-import net.sourceforge.pmd.lang.java.oom.api.Metric;
import net.sourceforge.pmd.lang.java.oom.api.Metric.Version;
import net.sourceforge.pmd.lang.java.oom.api.MetricVersion;
import net.sourceforge.pmd.lang.java.oom.api.OperationMetric;
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/AtfdMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/AtfdMetric.java
index b2656980e0..e7f768f03a 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/AtfdMetric.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/AtfdMetric.java
@@ -7,9 +7,7 @@ package net.sourceforge.pmd.lang.java.oom.metrics;
import java.util.List;
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
-import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
-import net.sourceforge.pmd.lang.java.ast.AccessNode;
import net.sourceforge.pmd.lang.java.ast.QualifiedName;
import net.sourceforge.pmd.lang.java.oom.AbstractMetric;
import net.sourceforge.pmd.lang.java.oom.api.ClassMetric;
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/LocMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/LocMetric.java
index 658df4ee62..41740dafd6 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/LocMetric.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/LocMetric.java
@@ -35,16 +35,13 @@ public final class LocMetric extends AbstractMetric implements ClassMetric, Oper
@Override
public double computeFor(ASTAnyTypeDeclaration node, MetricVersion version) {
- return node.getEndLine() - node.getBeginLine();
+ return 1 + node.getEndLine() - node.getBeginLine();
}
@Override
public double computeFor(ASTMethodOrConstructorDeclaration node, MetricVersion version) {
- if (node.isAbstract()) {
- return 1;
- }
- return node.getEndLine() - node.getBeginLine();
+ return 1 + node.getEndLine() - node.getBeginLine();
}
}
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/NcssMetric.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/NcssMetric.java
index 60dc7a6571..6f85a47acd 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/NcssMetric.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/metrics/NcssMetric.java
@@ -44,7 +44,8 @@ import net.sourceforge.pmd.lang.java.oom.api.OperationMetric;
/**
* Non Commenting Source Statements. Similar to LOC but only counts statements, which is roughly equivalent
* to counting the number of semicolons and opening braces in the program. The precise rules for counting
- * statements comply with JavaNCSS rules.
+ * statements comply with JavaNCSS rules. The only
+ * difference is that import and package statements are not counted.
*
* @author Clément Fournier
* @see LocMetric
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/MetricsForceHook.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/MetricsForceHook.java
index e9b1b6432e..0688c2a4f7 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/MetricsForceHook.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/MetricsForceHook.java
@@ -15,4 +15,8 @@ public class MetricsForceHook {
Metrics.setForce(b);
}
+ private MetricsForceHook() {
+
+ }
+
}
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/AllMetricsTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/AllMetricsTest.java
index 5312260473..1d341568c5 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/AllMetricsTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/AllMetricsTest.java
@@ -18,6 +18,7 @@ public class AllMetricsTest extends SimpleAggregatorTst {
addRule(RULESET, "CycloTest");
addRule(RULESET, "NcssTest");
addRule(RULESET, "WmcTest");
+ addRule(RULESET, "LocTest");
}
}
diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/LocTestRule.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/LocTestRule.java
new file mode 100644
index 0000000000..cd7469f1e0
--- /dev/null
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/oom/metrics/LocTestRule.java
@@ -0,0 +1,24 @@
+/**
+ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
+ */
+
+package net.sourceforge.pmd.lang.java.oom.metrics;
+
+import net.sourceforge.pmd.lang.java.oom.api.ClassMetricKey;
+import net.sourceforge.pmd.lang.java.oom.api.OperationMetricKey;
+
+/**
+ * @author Clément Fournier
+ */
+public class LocTestRule extends AbstractMetricTestRule {
+
+ @Override
+ protected ClassMetricKey getClassKey() {
+ return ClassMetricKey.LOC;
+ }
+
+ @Override
+ protected OperationMetricKey getOpKey() {
+ return OperationMetricKey.LOC;
+ }
+}
diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/LocTest.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/LocTest.xml
new file mode 100644
index 0000000000..c5cb71a41e
--- /dev/null
+++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/oom/metrics/xml/LocTest.xml
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
+
+