diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/visitor/ClassStats.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/visitor/ClassStats.java index f441fceb1a..2f4ebbfc99 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/visitor/ClassStats.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/oom/visitor/ClassStats.java @@ -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> operations = new HashMap<>(); private Map> fields = new HashMap<>(); private Map 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()); + } + 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()); + } + fields.get(sig).add(name); + } + //TODO }