org.netbeans.insane.scanner
Class CountingVisitor

java.lang.Object
  extended by org.netbeans.insane.scanner.CountingVisitor
All Implemented Interfaces:
Visitor

public class CountingVisitor
extends java.lang.Object
implements Visitor

A visitor implementation that counts occurence and total size of found objects, classified by their class. Usage: use it as a Visitor for an engine. After the engine finishes, you can query found classes and per class statistics using getClasses(), getCountForClass(java.lang.Class), getSizeForClass(java.lang.Class), and gobal statistics using getTotalCount() and getTotalSize().


Constructor Summary
CountingVisitor()
          Creates a new instance of CountingVisitor
 
Method Summary
 java.util.Set getClasses()
           
 int getCountForClass(java.lang.Class cls)
           
 int getSizeForClass(java.lang.Class cls)
           
 int getTotalCount()
           
 int getTotalSize()
           
 void visitArrayReference(ObjectMap map, java.lang.Object from, java.lang.Object to, int index)
          A new reference to target object was found.
 void visitClass(java.lang.Class cls)
          A new type was found.
 void visitObject(ObjectMap map, java.lang.Object obj)
          A new object instance was found.
 void visitObjectReference(ObjectMap map, java.lang.Object from, java.lang.Object to, java.lang.reflect.Field ref)
          A reference from object from to object to was found as the contents of the field ref.
 void visitStaticReference(ObjectMap map, java.lang.Object to, java.lang.reflect.Field ref)
          A new reference static reference to target object was found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CountingVisitor

public CountingVisitor()
Creates a new instance of CountingVisitor

Method Detail

visitClass

public void visitClass(java.lang.Class cls)
Description copied from interface: Visitor
A new type was found. It is guaranteed to be reported before first instance of given class. It is also guaranteed that all superclasses and interfaces will be reported before a subclass.

Specified by:
visitClass in interface Visitor
Parameters:
cls - the new type found.

visitObject

public void visitObject(ObjectMap map,
                        java.lang.Object obj)
Description copied from interface: Visitor
A new object instance was found. It is guaranteed to be reported before first reference sourced from or targetted to this instance. It is also guaranteed that the instance's class will be reported before the instance.

Specified by:
visitObject in interface Visitor
Parameters:
map - The ObjectMap containing this object.
obj - the reported instance.

visitStaticReference

public void visitStaticReference(ObjectMap map,
                                 java.lang.Object to,
                                 java.lang.reflect.Field ref)
Description copied from interface: Visitor
A new reference static reference to target object was found. It is guaranteed that the to object will be reported before the reference.

Specified by:
visitStaticReference in interface Visitor
Parameters:
map - The ObjectMap containing the object.
to - The object to which the reference points.
ref - The representation of the reference. Describes the class the referring field is declared in, and how it is named.

visitObjectReference

public void visitObjectReference(ObjectMap map,
                                 java.lang.Object from,
                                 java.lang.Object to,
                                 java.lang.reflect.Field ref)
Description copied from interface: Visitor
A reference from object from to object to was found as the contents of the field ref. It is guaranteed that both from and to objects will be reported before the reference.

Specified by:
visitObjectReference in interface Visitor
Parameters:
map - The ObjectMap containing the objects.
from - The object from which the reference sources.
to - The object to which the reference points.
ref - The representation of the reference. Describes the class the referring field is declared in, and how it is named.

visitArrayReference

public void visitArrayReference(ObjectMap map,
                                java.lang.Object from,
                                java.lang.Object to,
                                int index)
Description copied from interface: Visitor
A new reference to target object was found. The object to is referenced by index-th slot of the array from It is guaranteed that both from and to objects will be reported before the reference.

Specified by:
visitArrayReference in interface Visitor
Parameters:
map - The ObjectMap containing the objects.
from - The object from which the reference sources.
to - The object to which the reference points.
index - The array index of the to reference in from array.

getClasses

public java.util.Set getClasses()

getCountForClass

public int getCountForClass(java.lang.Class cls)

getSizeForClass

public int getSizeForClass(java.lang.Class cls)

getTotalCount

public int getTotalCount()

getTotalSize

public int getTotalSize()