SandMark version 3.0


sandmark.statistics
Class Stats

java.lang.Object
  |
  +--sandmark.statistics.Stats
Direct Known Subclasses:
Test.Stats

public class Stats
extends java.lang.Object

This class is a collection of StatisticsRecords. It builds these records from ClassFileCollection input. It can find a record, access it and provide statistical data about the classes it records.


Nested Class Summary
static class Stats.MetricWrapper
           
 
Constructor Summary
Stats()
          onstructs an empty new Statistics collection.
Stats(ClassFileCollection aCollection)
          Constructs a new Statistics collection.
 
Method Summary
 boolean callsDynamicMethods(java.lang.String className, java.lang.String methodName)
          Returns true if specified method calls other dynamic methods, or false if it does not.
 boolean callsStaticMethods(java.lang.String className, java.lang.String methodName)
          Returns true if specified method calls other static methods, or false if it does not.
 boolean findPackage(java.lang.String packageToFind)
          Checks to see if the named package is in this collection.
 java.util.Vector getAllClassNames()
           
 java.util.Vector getAllMethodNames()
           
 int getAverageNumberOfMethodParams(java.lang.String packageName, java.lang.String className)
           
 int getAvgNumberOfInstanceMethods()
           
 int getAvgNumberOfInstanceVariables()
           
 java.util.List getByteCode()
           
 java.util.List getByteCode(java.lang.String className, java.lang.String methodName)
          Returns the bytecode of a specified method.
 java.util.List getByteCodeByClassName(java.lang.String packageName, java.lang.String className)
           
 java.util.List getByteCodeByPackage(java.lang.String packageName)
           
 java.util.Hashtable getByteCodeUsage(java.lang.String className, java.lang.String methodName)
           
 java.util.Hashtable getByteCodeUsage2(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 int getClassHierarchyLevel(java.lang.String className)
           
 java.lang.String getClassNameAt(int index)
          Returns the classname at the specified index
 java.util.List getListOfClassesByPackageName(java.lang.String packageName)
          Returns a list of all of the classNames are in the specified package.
 java.lang.String getMethodByteCodeUsage(java.lang.String className, java.lang.String methodName)
           
 EDU.purdue.cs.bloat.editor.MethodEditor getMethodEditor(java.lang.String className, java.lang.String methodName)
           
 EDU.purdue.cs.bloat.editor.MethodEditor getMethodEditor2(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 java.lang.String[] getMethodNames(java.lang.String packageName, java.lang.String className)
          Returns the names of all of the methods in the class specified
 java.lang.String[] getMethodNames2(java.lang.String className)
           
 int getMethodSizeInBytes(java.lang.String className, java.lang.String methodName)
          Returns the size of the method in bytes, or -1 if the class or method does not exist
 int[] getMethodVectorDimensions(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 Metric[] getMetrics()
          returns the 'metric' objects
 Stats.MetricWrapper[] getMetricWrappers()
           
 java.lang.String[] getNamesOfMethodsInvoked(java.lang.String className, java.lang.String methodName)
           
 java.util.List getNonStaticFields(java.lang.String className)
          Returns a List of all the Non-Static fields in the specified class.
 int getNumberOfAbstractClasses()
           
 int getNumberOfApiCalls(java.lang.String className)
           
 int getNumberOfClassMethods(java.lang.String className)
           
 int getNumberOfConditionalStatements(java.lang.String className)
           
 int getNumberOfCondStatsInMethod(java.lang.String className, java.lang.String methodName)
           
 int getNumberOfInstanceMethods(java.lang.String className)
           
 int getNumberOfInstanceVariables(java.lang.String className)
           
 int getNumberOfMessageSends(java.lang.String className, java.lang.String methodName)
          public int getAvgNumberOfStatementsInMethod(String className) { StatisticsRecord stat = null; if((stat = findRecord(className)) == null) return -1; // could have implemented using getMethodNames API return stat.getAvgNumberOfStatementsInMethod(); }
 int getNumberOfMethodParams(java.lang.String className, java.lang.String methodName)
           
 int getNumberOfMethodsAdded(java.lang.String className)
           
 int getNumberOfMethodsInherited(java.lang.String className)
           
 int getNumberOfMethodsInScope(java.lang.String className)
           
 int getNumberOfMethodsInvoked(java.lang.String className)
           
 int getNumberOfMethodsOverridden(java.lang.String className)
           
 int getNumberOfMetrics()
          public getLevelsOfLoopNesting(String className, String methodName) {}
 int getNumberOfmultipleInheritance(java.lang.String className)
           
 int getNumberOfOpcodesInClass(java.lang.String packageName, java.lang.String className, java.lang.String opcode)
           
 int getNumberOfOpcodesInMethod(java.lang.String packageName, java.lang.String className, java.lang.String methodName, java.lang.String opcode)
          Runs a few tests public static void main(String argv[]) throws Exception { System.out.println( "Starting Stats test..." ); String s = argv[0]; sandmark.util.ClassFileCollection cfc = new sandmark.util.ClassFileCollection(s); Stats stats = new Stats ( cfc ); java.util.List list = stats.getByteCode("Simple6", "P"); System.out.println( "List: " + list ); System.out.println( "Usage: " + stats.getMethodByteCodeUsage("Simple6", "P" ) ); System.out.println( "Starting list: " ); java.util.Hashtable h = stats.getByteCodeUsage("Simple6", "P"); java.util.Enumeration e = h.keys(); while ( e.hasMoreElements() ) { Object o = e.nextElement(); System.out.println ( "*: " + o + h.get(o) ); } }
 int getNumberOfOpcodesInPackage(java.lang.String packageName, java.lang.String opcode)
           
 int getNumberOfPublicMethods(java.lang.String className)
           
 int getNumberOfScalarLocals(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 int getNumberOfScalars(java.lang.String packageName, java.lang.String className)
           
 int getNumberOfStaticFields(java.lang.String className)
          Returns the number of fields in the specified class which are static, or -1 if the class does not exist
 int getNumberOfStatmentsInMethod(java.lang.String className, java.lang.String methodName)
           
 int getNumberOfSubClasses(java.lang.String className)
           
 int getNumberOfVectorLocals(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 int getNumberOfVectors(java.lang.String packageName, java.lang.String className)
           
 int getNumClasses()
          Returns the number of classes in this collection
 int getNumClassesInPackage(java.lang.String packageName)
          Returns the number of classes in the specified package.
 int getNumFieldsNonBasicTypes(java.lang.String className)
          Returns the number of fields that are not basic in the specified class, or -1 if the class does not exist
 int getNumMethods(java.lang.String className)
          Returns the number of the method in specified class, or -1 if class does not exist.
 int getNumNonStaticFields(java.lang.String className)
           
 int getNumNonStaticFieldsByType(java.lang.String className, java.lang.String type)
          Returns the number of fields, by type in the specified class which are non-static, or -1 if the class does not exist
 int getNumPackages()
          Returns the number of packages in this collection
 int getPackageIndex(java.lang.String packageToFind)
           
 java.lang.String getPackageName(java.lang.String className)
           
 java.lang.String getPackageNameAt(int index)
          Given a specific index, this method returns the packageName at that index
 java.util.List getPackageNames()
          Returns a list of all of the packages in this collection, discounting duplicates.
 java.util.Vector getVectorDimensions(java.lang.String packageName, java.lang.String className)
           
 java.util.Vector halsteadMeasures(java.lang.String packageName, java.lang.String className, java.lang.String methodName)
           
 boolean hasBackwardBranches(java.lang.String className, java.lang.String methodName)
          Returns true if specified method uses backward branches, or false if it does not.
 boolean hasForwardBranches(java.lang.String className, java.lang.String methodName)
          Returns true if specified method uses forward branches, or false if it does not.
 double nestingLevelComplexity(java.lang.String className, java.lang.String methodName, de.fub.bytecode.generic.MethodGen mg)
           
 boolean throwsCatchesExceptions(java.lang.String className, java.lang.String methodName)
          Returns true if specified method throws or catches exceptions, or false if it does not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Stats

public Stats()
onstructs an empty new Statistics collection. Used for testing purposes.


Stats

public Stats(ClassFileCollection aCollection)
Constructs a new Statistics collection.

Parameters:
aCollection - The ClassFileCollection which contains the classes to analyze
Method Detail

getByteCode

public java.util.List getByteCode()

getByteCodeByPackage

public java.util.List getByteCodeByPackage(java.lang.String packageName)

getNumMethods

public int getNumMethods(java.lang.String className)
Returns the number of the method in specified class, or -1 if class does not exist.

Parameters:
className - the name of the class
Returns:
The number of methods in the class, or -1 if the class does not exist

getMethodNames

public java.lang.String[] getMethodNames(java.lang.String packageName,
                                         java.lang.String className)
Returns the names of all of the methods in the class specified

Parameters:
className - the name of the class
Returns:
String array representing all of the method names in the class specified

getMethodNames2

public java.lang.String[] getMethodNames2(java.lang.String className)

getClassNameAt

public java.lang.String getClassNameAt(int index)
Returns the classname at the specified index

Parameters:
index - the index at which to get the classname
Returns:
the name of the class at index

getNumClasses

public int getNumClasses()
Returns the number of classes in this collection

Returns:
the number of classes in this collection

getPackageNameAt

public java.lang.String getPackageNameAt(int index)
Given a specific index, this method returns the packageName at that index

Parameters:
index - the index at which to get the packageName
Returns:
the name of the package at index

getPackageName

public java.lang.String getPackageName(java.lang.String className)

getNumPackages

public int getNumPackages()
Returns the number of packages in this collection

Returns:
the number of packages in this collection

getListOfClassesByPackageName

public java.util.List getListOfClassesByPackageName(java.lang.String packageName)
Returns a list of all of the classNames are in the specified package.

Parameters:
packageName - the name of the package from which to get classNames.
Returns:
a list of all of the classNames are in the specified package.

getAllClassNames

public java.util.Vector getAllClassNames()

getAllMethodNames

public java.util.Vector getAllMethodNames()

getNumClassesInPackage

public int getNumClassesInPackage(java.lang.String packageName)
Returns the number of classes in the specified package.

Parameters:
packageName - the name of the package to investigate.
Returns:
the number of classes in the specified package.

getPackageNames

public java.util.List getPackageNames()
Returns a list of all of the packages in this collection, discounting duplicates.

Returns:
a list of all of the packages in this collection.

findPackage

public boolean findPackage(java.lang.String packageToFind)
Checks to see if the named package is in this collection.

Parameters:
packageToFind - the name of the package to look for in this collection.
Returns:
true if package exists in this collection, false if it does not.

getPackageIndex

public int getPackageIndex(java.lang.String packageToFind)

getByteCodeByClassName

public java.util.List getByteCodeByClassName(java.lang.String packageName,
                                             java.lang.String className)

getByteCode

public java.util.List getByteCode(java.lang.String className,
                                  java.lang.String methodName)
Returns the bytecode of a specified method.

Parameters:
className - the name of the class.
methodName - the name of the method from which to get the bytecode.
Returns:
the List representation of the bytecode.

getMethodByteCodeUsage

public java.lang.String getMethodByteCodeUsage(java.lang.String className,
                                               java.lang.String methodName)

getByteCodeUsage2

public java.util.Hashtable getByteCodeUsage2(java.lang.String packageName,
                                             java.lang.String className,
                                             java.lang.String methodName)

getByteCodeUsage

public java.util.Hashtable getByteCodeUsage(java.lang.String className,
                                            java.lang.String methodName)

getMethodSizeInBytes

public int getMethodSizeInBytes(java.lang.String className,
                                java.lang.String methodName)
Returns the size of the method in bytes, or -1 if the class or method does not exist

Parameters:
className - the name of the class
methodName - the name of the method from which to get the size.
Returns:
the number of bytes in the method, or -1 if the class or method does not exist

throwsCatchesExceptions

public boolean throwsCatchesExceptions(java.lang.String className,
                                       java.lang.String methodName)
Returns true if specified method throws or catches exceptions, or false if it does not.

Parameters:
className - the name of the class
methodName - the name of the method to investigate
Returns:
true if specified method throws or catches exceptions, or false if it does not.

getNumNonStaticFields

public int getNumNonStaticFields(java.lang.String className)

getNumberOfStaticFields

public int getNumberOfStaticFields(java.lang.String className)
Returns the number of fields in the specified class which are static, or -1 if the class does not exist

Parameters:
className - the name of the class
Returns:
the number of fields in the specified class which are static, or -1 if the class does not exist

getNumNonStaticFieldsByType

public int getNumNonStaticFieldsByType(java.lang.String className,
                                       java.lang.String type)
Returns the number of fields, by type in the specified class which are non-static, or -1 if the class does not exist

Parameters:
className - the name of the class
type - the type to count.
Returns:
the number of fields, by type in the specified class which are non-static, or -1 if the class does not exist

getNumFieldsNonBasicTypes

public int getNumFieldsNonBasicTypes(java.lang.String className)
Returns the number of fields that are not basic in the specified class, or -1 if the class does not exist

Parameters:
className - the name of the class
Returns:
the number of fields that are not basic in the specified class, or -1 if the class does not exist

hasForwardBranches

public boolean hasForwardBranches(java.lang.String className,
                                  java.lang.String methodName)
Returns true if specified method uses forward branches, or false if it does not.

Parameters:
className - the name of the class
methodName - the name of the method to investigate
Returns:
true if specified method uses forward branches, or false if it does not.

hasBackwardBranches

public boolean hasBackwardBranches(java.lang.String className,
                                   java.lang.String methodName)
Returns true if specified method uses backward branches, or false if it does not.

Parameters:
className - the name of the class
methodName - the name of the method to investigate
Returns:
true if specified method uses backward branches, or false if it does not.

getNonStaticFields

public java.util.List getNonStaticFields(java.lang.String className)
Returns a List of all the Non-Static fields in the specified class.

Parameters:
className - the name of the class from which to retrieve the Non-static field types
Returns:
a List representation of all non-static field types in the specified class

callsStaticMethods

public boolean callsStaticMethods(java.lang.String className,
                                  java.lang.String methodName)
Returns true if specified method calls other static methods, or false if it does not.

Parameters:
className - the name of the class
methodName - the name of the method to investigate
Returns:
true if specified method calls other static methods, or false if it does not.

callsDynamicMethods

public boolean callsDynamicMethods(java.lang.String className,
                                   java.lang.String methodName)
Returns true if specified method calls other dynamic methods, or false if it does not.

Parameters:
className - the name of the class
methodName - the name of the method to investigate
Returns:
true if specified method calls other dynamic methods, or false if it does not.

getNumberOfOpcodesInMethod

public int getNumberOfOpcodesInMethod(java.lang.String packageName,
                                      java.lang.String className,
                                      java.lang.String methodName,
                                      java.lang.String opcode)
Runs a few tests public static void main(String argv[]) throws Exception { System.out.println( "Starting Stats test..." ); String s = argv[0]; sandmark.util.ClassFileCollection cfc = new sandmark.util.ClassFileCollection(s); Stats stats = new Stats ( cfc ); java.util.List list = stats.getByteCode("Simple6", "P"); System.out.println( "List: " + list ); System.out.println( "Usage: " + stats.getMethodByteCodeUsage("Simple6", "P" ) ); System.out.println( "Starting list: " ); java.util.Hashtable h = stats.getByteCodeUsage("Simple6", "P"); java.util.Enumeration e = h.keys(); while ( e.hasMoreElements() ) { Object o = e.nextElement(); System.out.println ( "*: " + o + h.get(o) ); } }


getNumberOfOpcodesInClass

public int getNumberOfOpcodesInClass(java.lang.String packageName,
                                     java.lang.String className,
                                     java.lang.String opcode)

getNumberOfOpcodesInPackage

public int getNumberOfOpcodesInPackage(java.lang.String packageName,
                                       java.lang.String opcode)

getMethodEditor

public EDU.purdue.cs.bloat.editor.MethodEditor getMethodEditor(java.lang.String className,
                                                               java.lang.String methodName)

getMethodEditor2

public EDU.purdue.cs.bloat.editor.MethodEditor getMethodEditor2(java.lang.String packageName,
                                                                java.lang.String className,
                                                                java.lang.String methodName)

getNumberOfStatmentsInMethod

public int getNumberOfStatmentsInMethod(java.lang.String className,
                                        java.lang.String methodName)

getNumberOfMessageSends

public int getNumberOfMessageSends(java.lang.String className,
                                   java.lang.String methodName)
public int getAvgNumberOfStatementsInMethod(String className) { StatisticsRecord stat = null; if((stat = findRecord(className)) == null) return -1; // could have implemented using getMethodNames API return stat.getAvgNumberOfStatementsInMethod(); }


getNumberOfPublicMethods

public int getNumberOfPublicMethods(java.lang.String className)

getNumberOfInstanceMethods

public int getNumberOfInstanceMethods(java.lang.String className)

getAvgNumberOfInstanceMethods

public int getAvgNumberOfInstanceMethods()

getNumberOfInstanceVariables

public int getNumberOfInstanceVariables(java.lang.String className)

getAvgNumberOfInstanceVariables

public int getAvgNumberOfInstanceVariables()

getNumberOfClassMethods

public int getNumberOfClassMethods(java.lang.String className)

getNumberOfApiCalls

public int getNumberOfApiCalls(java.lang.String className)

getNamesOfMethodsInvoked

public java.lang.String[] getNamesOfMethodsInvoked(java.lang.String className,
                                                   java.lang.String methodName)

getNumberOfMethodParams

public int getNumberOfMethodParams(java.lang.String className,
                                   java.lang.String methodName)

getNumberOfCondStatsInMethod

public int getNumberOfCondStatsInMethod(java.lang.String className,
                                        java.lang.String methodName)

getNumberOfScalarLocals

public int getNumberOfScalarLocals(java.lang.String packageName,
                                   java.lang.String className,
                                   java.lang.String methodName)

getNumberOfVectorLocals

public int getNumberOfVectorLocals(java.lang.String packageName,
                                   java.lang.String className,
                                   java.lang.String methodName)

getMethodVectorDimensions

public int[] getMethodVectorDimensions(java.lang.String packageName,
                                       java.lang.String className,
                                       java.lang.String methodName)

getNumberOfConditionalStatements

public int getNumberOfConditionalStatements(java.lang.String className)

getAverageNumberOfMethodParams

public int getAverageNumberOfMethodParams(java.lang.String packageName,
                                          java.lang.String className)

getNumberOfScalars

public int getNumberOfScalars(java.lang.String packageName,
                              java.lang.String className)

getNumberOfVectors

public int getNumberOfVectors(java.lang.String packageName,
                              java.lang.String className)

getVectorDimensions

public java.util.Vector getVectorDimensions(java.lang.String packageName,
                                            java.lang.String className)

getNumberOfMethodsInvoked

public int getNumberOfMethodsInvoked(java.lang.String className)

getNumberOfMethodsInScope

public int getNumberOfMethodsInScope(java.lang.String className)

getClassHierarchyLevel

public int getClassHierarchyLevel(java.lang.String className)

getNumberOfSubClasses

public int getNumberOfSubClasses(java.lang.String className)

getNumberOfAbstractClasses

public int getNumberOfAbstractClasses()

getNumberOfmultipleInheritance

public int getNumberOfmultipleInheritance(java.lang.String className)

getNumberOfMethodsInherited

public int getNumberOfMethodsInherited(java.lang.String className)

getNumberOfMethodsAdded

public int getNumberOfMethodsAdded(java.lang.String className)

getNumberOfMethodsOverridden

public int getNumberOfMethodsOverridden(java.lang.String className)

getNumberOfMetrics

public int getNumberOfMetrics()
public getLevelsOfLoopNesting(String className, String methodName) {}


getMetrics

public Metric[] getMetrics()
returns the 'metric' objects


getMetricWrappers

public Stats.MetricWrapper[] getMetricWrappers()

halsteadMeasures

public java.util.Vector halsteadMeasures(java.lang.String packageName,
                                         java.lang.String className,
                                         java.lang.String methodName)

nestingLevelComplexity

public double nestingLevelComplexity(java.lang.String className,
                                     java.lang.String methodName,
                                     de.fub.bytecode.generic.MethodGen mg)

SandMark version 3.0

Wed Jan 29 10:30:05 MST 2003