Package classycle
Class Analyser
- java.lang.Object
-
- classycle.Analyser
-
public class Analyser extends java.lang.ObjectMain class of the Classycle tool. Runs on the command line and produces a report.- Author:
- Franz-Josef Elmer
-
-
Constructor Summary
Constructors Constructor Description Analyser(java.lang.String[] classFiles)Creates an instance for the specified files or folders.Analyser(java.lang.String[] classFiles, StringPattern pattern, StringPattern reflectionPattern, boolean mergeInnerClasses)Creates an instance for the specified files or folders which are filtered by the specifiedStringPatternobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longcalculateClassLayerMap()Calculates the for each class its layer index.longcalculatePackageLayerMap()Calculates the for each package its layer index.longcondenseClassGraph()Condenses the class graph to an acyclic graph of its strong components.longcondensePackageGraph()Condenses the package graph to an acyclic graph of its strong components.longcreateClassGraph()Parses the class files and creates the class graph.longcreatePackageGraph()Creates the package graph from the class graph.AtomicVertex[]getClassGraph()Returns the class graph.java.util.Map<AtomicVertex,java.lang.Integer>getClassLayerMap()Calculates the for each class its layer index and returns a Map where the classes are the keys (typeAtomicVertex) and the layer indices are the values (type Integer).StrongComponent[]getCondensedClassGraph()Returns the condensed the class graph, i.e. the acyclic graph of its strong components.StrongComponent[]getCondensedPackageGraph()Returns the condensed package graph, i.e. the acyclic graph of its strong components.intgetNumberOfExternalClasses()Counts the number of external classes.AtomicVertex[]getPackageGraph()Returns the package graph created the class graph.java.util.Map<AtomicVertex,java.lang.Integer>getPackageLayerMap()Calculates the for each package its layer index and returns a Map where the packages are the keys (typeAtomicVertex) and the layer indices are the values (type Integer).static voidmain(java.lang.String[] args)Main method of the Analyser.voidprintComponents(java.io.PrintWriter writer, int minSize)Prints for each strong component of the class graph a raw output into the specified writer.voidprintCSV(java.io.PrintWriter writer)Prints a CSV report into the specified writer.voidprintRaw(java.io.PrintWriter writer)Prints for each class a raw output into the specified writer.voidprintXML(java.lang.String title, boolean packagesOnly, java.io.PrintWriter writer)Prints an XML report into the specified writer.voidreadAndAnalyse(boolean packagesOnly)Reads and analyses class files.
-
-
-
Constructor Detail
-
Analyser
public Analyser(java.lang.String[] classFiles)
Creates an instance for the specified files or folders.- Parameters:
classFiles- Absolute or relative file names.
-
Analyser
public Analyser(java.lang.String[] classFiles, StringPattern pattern, StringPattern reflectionPattern, boolean mergeInnerClasses)Creates an instance for the specified files or folders which are filtered by the specifiedStringPatternobject.- Parameters:
classFiles- Absolute or relative file names.pattern- Pattern fully-qualified class name have to match in order to be a part of the class graph.reflectionPattern- Pattern ordinary string constants of a class file have to fullfill in order to be handled as a class references. In addition such strings have to be syntactically valid fully qualified class names. If null ordinary string constants will not be checked.mergeInnerClasses- Iftruemerge inner classes with its outer class
-
-
Method Detail
-
createClassGraph
public long createClassGraph() throws java.io.IOExceptionParses the class files and creates the class graph.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.io.IOException- if a problem occured during reading
-
getClassGraph
public AtomicVertex[] getClassGraph()
Returns the class graph. InvokescreateClassGraph()if not already invoked.
-
getNumberOfExternalClasses
public int getNumberOfExternalClasses()
Counts the number of external classes.
-
condenseClassGraph
public long condenseClassGraph()
Condenses the class graph to an acyclic graph of its strong components.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
getCondensedClassGraph
public StrongComponent[] getCondensedClassGraph()
Returns the condensed the class graph, i.e. the acyclic graph of its strong components.- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
calculateClassLayerMap
public long calculateClassLayerMap()
Calculates the for each class its layer index. The layer index of a class is the length of the longest path in the acyclic graph of strong components starting at the strong component to which the class belongs.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
getClassLayerMap
public java.util.Map<AtomicVertex,java.lang.Integer> getClassLayerMap()
Calculates the for each class its layer index and returns a Map where the classes are the keys (typeAtomicVertex) and the layer indices are the values (type Integer).- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
createPackageGraph
public long createPackageGraph()
Creates the package graph from the class graph.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
printCSV
public void printCSV(java.io.PrintWriter writer)
Prints a CSV report into the specified writer. Delimiter is ','. First, a header with column titles is print. The columns are- class name
- inner class (false or true)
- size (in bytes)
- used by (number of classes using this class)
- uses internal classes (number of classes of the graph used by this class)
- uses external classes (number of external classes used by this class)
- layer index
- Parameters:
writer- Output stream.
-
printRaw
public void printRaw(java.io.PrintWriter writer)
Prints for each class a raw output into the specified writer. This output includes all classes used by the class.- Parameters:
writer- Output stream.
-
printComponents
public void printComponents(java.io.PrintWriter writer, int minSize)Prints for each strong component of the class graph a raw output into the specified writer. The strong component must have at least minSize classes in order to be printed out. This output includes all classes of the strong component.- Parameters:
writer- Output stream.minSize- Minimum size of the strong component.- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
getPackageGraph
public AtomicVertex[] getPackageGraph()
Returns the package graph created the class graph.- Throws:
java.lang.IllegalStateException- if this method is called beforecreateClassGraph().
-
condensePackageGraph
public long condensePackageGraph()
Condenses the package graph to an acyclic graph of its strong components.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreatePackageGraph().
-
getCondensedPackageGraph
public StrongComponent[] getCondensedPackageGraph()
Returns the condensed package graph, i.e. the acyclic graph of its strong components.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreatePackageGraph().
-
calculatePackageLayerMap
public long calculatePackageLayerMap()
Calculates the for each package its layer index. The layer index of a package is the length of the longest path in the acyclic graph of strong components starting at the strong component to which the package belongs.- Returns:
- the duration of this operation in milliseconds.
- Throws:
java.lang.IllegalStateException- if this method is called beforecreatePackageGraph().
-
getPackageLayerMap
public java.util.Map<AtomicVertex,java.lang.Integer> getPackageLayerMap()
Calculates the for each package its layer index and returns a Map where the packages are the keys (typeAtomicVertex) and the layer indices are the values (type Integer).- Throws:
java.lang.IllegalStateException- if this method is called beforecreatePackageGraph().
-
readAndAnalyse
public void readAndAnalyse(boolean packagesOnly) throws java.io.IOExceptionReads and analyses class files. Does only package analysis if packagesOnly == true. Reports progress of analysis on System.out.- Throws:
java.io.IOException- in case of reading problems.
-
printXML
public void printXML(java.lang.String title, boolean packagesOnly, java.io.PrintWriter writer)Prints an XML report into the specified writer.- Parameters:
title- Title of the report.packagesOnly- if true classes are omitted.writer- Output stream.- Throws:
java.lang.IllegalStateException- if this method is called beforecreatePackageGraph().
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionMain method of the Analyser. Prints on the console its usage if some invalid command line argument occurs or is missed.- Parameters:
args- command line arguments.- Throws:
java.lang.Exception
-
-