Deleted OperationStats

This commit is contained in:
oowekyala committed 2017-08-04 21:29:43 +02:00
1 parent 2771448a37
commit 78814b5edb
6 files changed
+15 -120

No files matched your search

@@ -24,6 +24,12 @@ public class BasicProjectMemoizer<T extends QualifiableNode, O extends Qualifiab
private Map<QualifiedName, MetricMemoizer<T>> classes = new HashMap<>();
private Map<QualifiedName, MetricMemoizer<O>> operations = new HashMap<>();
/** Clears all memoizers. Used for tests. */
public void reset() {
classes.clear();
operations.clear();
}
@Override
public void addClassMemoizer(QualifiedName qname) {
@@ -28,7 +28,7 @@ import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature;
*/
/* default */ class ClassStats {
private Map<JavaOperationSignature, Map<String, OperationStats>> operations = new HashMap<>();
private Map<JavaOperationSignature, Set<String>> operations = new HashMap<>();
private Map<JavaFieldSignature, Set<String>> fields = new HashMap<>();
private Map<String, ClassStats> nestedClasses = new HashMap<>();
@@ -65,51 +65,17 @@ import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature;
}
private OperationStats getOperationStats(String operationName) {
for (Map<String, OperationStats> map : operations.values()) {
OperationStats stats = map.get(operationName);
if (stats != null) {
return stats;
}
}
return null;
}
/**
* Returns the correct operation stats. A non-null signature speeds up the search.
*
* @param operationName The operation to look for
* @param sig The signature, which can be null
*
* @return The operation stats corresponding to the parameters
*/
OperationStats getOperationStats(String operationName, JavaOperationSignature sig) {
if (sig == null) {
return getOperationStats(operationName);
}
Map<String, OperationStats> sigMap = operations.get(sig);
return sigMap == null ? null : sigMap.get(operationName);
}
/**
* Adds an operation to the class.
*
* @param name The name of the operation
* @param sig The signature of the operation
*
* @return The newly created operation stats
*/
/* default */ OperationStats addOperation(String name, JavaOperationSignature sig) {
/* default */ void addOperation(String name, JavaOperationSignature sig) {
if (!operations.containsKey(sig)) {
operations.put(sig, new HashMap<String, OperationStats>());
operations.put(sig, new HashSet<String>());
}
OperationStats newOp = new OperationStats(name);
operations.get(sig).put(name, newOp);
return newOp;
operations.get(sig).add(name);
}
@@ -140,7 +106,7 @@ import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature;
// Indexing on signatures optimises this type of request
for (JavaOperationSignature sig : operations.keySet()) {
if (mask.covers(sig)) {
if (operations.get(sig).containsKey(name)) {
if (operations.get(sig).contains(name)) {
return true;
}
}
@@ -166,7 +132,6 @@ import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature;
}
}
}
return false;
}
@@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
import net.sourceforge.pmd.lang.metrics.AbstractMetricsComputer;
/**
* Computes a metric. This relieves ClassStats and OperationStats from that responsibility.
* Computes a metric.
*
* @author Clément Fournier
*/
@@ -23,6 +23,7 @@ class JavaMetricsFacade extends AbstractMetricsFacade<ASTAnyTypeDeclaration, AST
/** Resets the entire data structure. Used for tests. */
void reset() {
topLevelPackageStats.reset();
memoizer.reset();
}
@@ -1,46 +0,0 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.java.metrics;
/**
* Statistics for an operation. Keeps a map of all memoized metrics results.
*
* @author Clément Fournier
*/
class OperationStats {
private final String name;
OperationStats(String name) {
this.name = name;
}
String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OperationStats stats = (OperationStats) o;
return name != null ? name.equals(stats.name) : stats.name == null;
}
@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
}
}
@@ -10,14 +10,12 @@ import java.util.Map;
import net.sourceforge.pmd.lang.java.ast.JavaQualifiedName;
import net.sourceforge.pmd.lang.java.metrics.signature.JavaFieldSigMask;
import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSigMask;
import net.sourceforge.pmd.lang.java.metrics.signature.JavaOperationSignature;
/**
* Statistics about a package. This recursive data structure mirrors the package structure of the analysed project and
* stores information about the classes and subpackages it contains.
*
* This object provides signature matching utilities.
* stores information about the classes and subpackages it contains. This object provides signature matching
* utilities to metrics.
*
* @author Clément Fournier
* @see ClassStats
@@ -45,35 +43,6 @@ public final class PackageStats implements JavaSignatureMatcher {
}
/**
* Gets the OperationStats corresponding to the qualified name.
*
* @param qname The qualified name of the operation to fetch
* @param sig The signature of the operation, which must be non-null if createIfNotFound is set
* @param createIfNotFound Create an OperationStats if missing
*
* @return The new OperationStat, or the one that was found. Can return null only if createIfNotFound is unset
*/
OperationStats getOperationStats(JavaQualifiedName qname, JavaOperationSignature sig, boolean createIfNotFound) {
ClassStats container = getClassStats(qname, createIfNotFound);
if (container == null || !qname.isOperation()) {
return null;
}
OperationStats target = container.getOperationStats(qname.getOperation(), sig);
if (target == null && createIfNotFound) {
if (sig == null) {
throw new IllegalArgumentException("Cannot add an operation with a null signature");
}
target = container.addOperation(qname.getOperation(), sig);
}
return target;
}
/**
* Gets the ClassStats corresponding to the named resource. The class can be nested. If the createIfNotFound
* parameter is set, the method also creates the hierarchy if it doesn't exist.