Merge branch 'master' into metrics
This commit is contained in:
@ -15,13 +15,13 @@ fi
|
||||
(
|
||||
# Run the build, truncate output due to Travis log limits
|
||||
|
||||
echo -e "\n\nExecuting ./mvnw install...\n\n"
|
||||
echo -e "\n\nExecuting ./mvnw install..."
|
||||
travis_wait ./mvnw install -DskipTests=true -B -V -q
|
||||
echo -e "Finished executing ./mvnw install\n\n"
|
||||
echo "Finished executing ./mvnw install"
|
||||
|
||||
echo -e "\n\nExecuting ./mvnw site site:stage...\n\n"
|
||||
travis_wait ./mvnw site site:stage -DskipTests=true -Psite -B -V -q
|
||||
echo -e "Finished executing ./mvnw site site:stage...\n\n"
|
||||
echo -e "\n\nExecuting ./mvnw site site:stage...
|
||||
travis_wait 40 ./mvnw site site:stage -DskipTests=true -Psite -B -V -q
|
||||
echo "Finished executing ./mvnw site site:stage..."
|
||||
)
|
||||
|
||||
echo -e "\n\nCreating pmd-doc archive...\n\n"
|
||||
|
@ -173,6 +173,38 @@ import net.sourceforge.pmd.lang.java.oom.signature.OperationSignature;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the declaration nodes of all methods or constructors that are declared inside a class.
|
||||
*
|
||||
* @param node The class in which to look for.
|
||||
* @param includeNested Include operations found in nested classes?
|
||||
*
|
||||
* @return The list of all operations declared inside the specified class.
|
||||
*
|
||||
* TODO:cf this one is computed every time
|
||||
*/
|
||||
private static List<ASTMethodOrConstructorDeclaration> findOperations(ASTAnyTypeDeclaration node,
|
||||
boolean includeNested) {
|
||||
|
||||
if (includeNested) {
|
||||
return node.findDescendantsOfType(ASTMethodOrConstructorDeclaration.class);
|
||||
}
|
||||
|
||||
List<ASTClassOrInterfaceBodyDeclaration> outerDecls
|
||||
= node.jjtGetChild(0).findChildrenOfType(ASTClassOrInterfaceBodyDeclaration.class);
|
||||
|
||||
|
||||
List<ASTMethodOrConstructorDeclaration> operations = new ArrayList<>();
|
||||
|
||||
for (ASTClassOrInterfaceBodyDeclaration decl : outerDecls) {
|
||||
if (decl.jjtGetChild(0) instanceof ASTMethodOrConstructorDeclaration) {
|
||||
operations.add((ASTMethodOrConstructorDeclaration) decl.jjtGetChild(0));
|
||||
}
|
||||
}
|
||||
return operations;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Computes the value of a metric for an operation.
|
||||
*
|
||||
@ -290,5 +322,4 @@ import net.sourceforge.pmd.lang.java.oom.signature.OperationSignature;
|
||||
private static double average(List<Double> values) {
|
||||
return sum(values) / values.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ public final class Metrics {
|
||||
* @return The value of the metric, or {@code Double.NaN} if the value couln't be computed
|
||||
*/
|
||||
public static double get(MetricKey<ASTAnyTypeDeclaration> key, ASTAnyTypeDeclaration node, MetricVersion version) {
|
||||
|
||||
if (!key.getCalculator().supports(node)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
@ -101,6 +102,7 @@ public final class Metrics {
|
||||
* @return The value of the metric, or {@code Double.NaN} if the value couln't be computed
|
||||
*/
|
||||
public static double get(MetricKey<ASTMethodOrConstructorDeclaration> key, ASTMethodOrConstructorDeclaration node, MetricVersion version) {
|
||||
|
||||
if (!key.getCalculator().supports(node)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
|
@ -15,17 +15,33 @@ import net.sourceforge.pmd.lang.java.oom.metrics.NcssMetric.NcssOperationMetric;
|
||||
*/
|
||||
public enum OperationMetricKey implements MetricKey<ASTMethodOrConstructorDeclaration> {
|
||||
|
||||
/** Access to Foreign Data. */
|
||||
ATFD(new AtfdOperationMetric()),
|
||||
/**
|
||||
* Access to Foreign Data.
|
||||
*
|
||||
* @see net.sourceforge.pmd.lang.java.oom.metrics.AtfdMetric
|
||||
*/
|
||||
ATFD(new AtfdClassMetric()),
|
||||
|
||||
/** Cyclomatic complexity. */
|
||||
CYCLO(new CycloOperationMetric()),
|
||||
/**
|
||||
* Cyclomatic complexity.
|
||||
*
|
||||
* @see net.sourceforge.pmd.lang.java.oom.metrics.CycloMetric
|
||||
*/
|
||||
CYCLO(new CycloClassMetric()),
|
||||
|
||||
/** Non Commenting Source Statements. */
|
||||
NCSS(new NcssOperationMetric()),
|
||||
/**
|
||||
* Non Commenting Source Statements.
|
||||
*
|
||||
* @see net.sourceforge.pmd.lang.java.oom.metrics.NcssMetric
|
||||
*/
|
||||
NCSS(new NcssClassMetric()),
|
||||
|
||||
/** Lines of Code. */
|
||||
LOC(new LocOperationMetric());
|
||||
/**
|
||||
* Lines of Code.
|
||||
*
|
||||
* @see net.sourceforge.pmd.lang.java.oom.metrics.LocMetric
|
||||
*/
|
||||
LOC(new LocClassMetric());
|
||||
|
||||
private final OperationMetric calculator;
|
||||
|
||||
|
@ -118,6 +118,21 @@ public class DataStructureTest extends ParserTst {
|
||||
assertEquals(expected, real);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void forceMemoizationTest() {
|
||||
ASTCompilationUnit acu = parseAndVisitForClass15(MetricsVisitorTestData.class);
|
||||
|
||||
List<Integer> reference = visitWith(acu, true);
|
||||
List<Integer> real = visitWith(acu, true);
|
||||
|
||||
assertEquals(reference.size(), real.size());
|
||||
|
||||
// we force recomputation so each result should be different
|
||||
for (int i = 0; i < reference.size(); i++) {
|
||||
assertNotEquals(reference.get(i), real.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Integer> visitWith(ASTCompilationUnit acu, final boolean force) {
|
||||
final PackageStats toplevel = Metrics.getTopLevelPackageStats();
|
||||
@ -143,22 +158,6 @@ public class DataStructureTest extends ParserTst {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void forceMemoizationTest() {
|
||||
ASTCompilationUnit acu = parseAndVisitForClass15(MetricsVisitorTestData.class);
|
||||
|
||||
List<Integer> reference = visitWith(acu, true);
|
||||
List<Integer> real = visitWith(acu, true);
|
||||
|
||||
assertEquals(reference.size(), real.size());
|
||||
|
||||
// we force recomputation so each result should be different
|
||||
for (int i = 0; i < reference.size(); i++) {
|
||||
assertNotEquals(reference.get(i), real.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class RandomOperationMetric extends AbstractOperationMetric {
|
||||
|
||||
private Random random = new Random();
|
||||
@ -179,9 +178,5 @@ public class DataStructureTest extends ParserTst {
|
||||
public double computeFor(ASTAnyTypeDeclaration node, MetricVersion version) {
|
||||
return random.nextInt();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ public class ParameterizedMetricKeyTest {
|
||||
|
||||
@Test
|
||||
public void testAdHocMetricKey() {
|
||||
|
||||
MetricKey<ASTAnyTypeDeclaration> adHocKey = ClassMetricKey.of(null, "metric");
|
||||
|
||||
MetricVersion adHocVersion = new MetricVersion() {
|
||||
|
@ -72,7 +72,7 @@ public abstract class AbstractMetricTestRule extends AbstractJavaMetricsRule {
|
||||
*/
|
||||
protected abstract OperationMetricKey getOpKey();
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTCompilationUnit node, Object data) {
|
||||
reportClasses = getProperty(reportClassesDescriptor);
|
||||
@ -155,5 +155,4 @@ public abstract class AbstractMetricTestRule extends AbstractJavaMetricsRule {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,5 +89,6 @@ Based on those metrics, rules like "GodClass" detection can be implemented more
|
||||
* [#492](https://github.com/pmd/pmd/pull/492): \[java] Typeresolution for overloaded methods - [Bendegúz Nagy](https://github.com/WinterGrascph)
|
||||
* [#495](https://github.com/pmd/pmd/pull/495): \[core] Custom rule reinitialization code - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#479](https://github.com/pmd/pmd/pull/479): \[core] Typesafe and immutable properties - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#499](https://github.com/pmd/pmd/pull/499): \[java] Metrics memoization tests - [Clément Fournier](https://github.com/oowekyala)
|
||||
* [#501](https://github.com/pmd/pmd/pull/501): \[java] Add support for most specific vararg method type resolution - [Bendegúz Nagy](https://github.com/WinterGrascph)
|
||||
|
||||
|
Reference in New Issue
Block a user