Added modification methods for ClassStats

This commit is contained in:
oowekyala
2017-05-23 20:49:00 +02:00
parent e4392fc751
commit a99f0c276d

View File

@ -5,17 +5,24 @@
package net.sourceforge.pmd.lang.java.oom.visitor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sourceforge.pmd.lang.java.ast.QualifiableNode.QualifiedName;
/**
* Statistics about a class. Gathers information about the contained members and their signatures,
* subclasses and superclasses.
* subclasses and superclasses. 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.
*
* @author Clément Fournier
*/
public class ClassStats {
private Map<OperationSignature, Set<String>> operations = new HashMap<>();
private Map<FieldSignature, Set<String>> fields = new HashMap<>();
private Map<String, ClassStats> nestedClasses = new HashMap<>();
@ -27,8 +34,8 @@ public class ClassStats {
/**
* Adds a ClassStats to the children of this class. This cannot be a nested class, for that see
* {@see PackageStats#getNestedClassStats}
* Finds a ClassStats in the direct children of this class. This cannot be a nested class, for
* that see {@link PackageStats#getClassStats(QualifiedName, boolean)}.
*
* @param className Name of the nested class.
* @param createIfNotFound Create ClassStats if missing.
@ -43,5 +50,32 @@ public class ClassStats {
return nestedClasses.get(className);
}
/**
* Adds an operation to these stats
*
* @param qname The qualified name of the operation
* @param sig The signature of the operation
*/
public void addOperation(QualifiedName qname, OperationSignature sig) {
if (!operations.containsKey(sig)) {
operations.put(sig, new HashSet<String>());
}
operations.get(sig).add(qname.getOperation());
}
/**
* Adds an operation to these stats (not the nested stats!)
*
* @param name The qualified name of the operation
* @param sig The signature of the operation
*/
public void addField(String name, FieldSignature sig) {
if (!fields.containsKey(sig)) {
fields.put(sig, new HashSet<String>());
}
fields.get(sig).add(name);
}
//TODO
}