Package classycle

Class Analyser

java.lang.Object
classycle.Analyser

public class Analyser extends Object
Main class of the Classycle tool. Runs on the command line and produces a report.
Author:
Franz-Josef Elmer
  • Constructor Details

    • Analyser

      public Analyser(String[] classFiles)
      Creates an instance for the specified files or folders.
      Parameters:
      classFiles - Absolute or relative file names.
    • Analyser

      public Analyser(String[] classFiles, StringPattern pattern, StringPattern reflectionPattern, boolean mergeInnerClasses)
      Creates an instance for the specified files or folders which are filtered by the specified StringPattern object.
      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 - If true merge inner classes with its outer class
  • Method Details

    • createClassGraph

      public long createClassGraph() throws IOException
      Parses the class files and creates the class graph.
      Returns:
      the duration of this operation in milliseconds.
      Throws:
      IOException - if a problem occured during reading
    • getClassGraph

      public AtomicVertex[] getClassGraph()
      Returns the class graph. Invokes createClassGraph() 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:
      IllegalStateException - if this method is called before createClassGraph().
    • getCondensedClassGraph

      public StrongComponent[] getCondensedClassGraph()
      Returns the condensed the class graph, i.e. the acyclic graph of its strong components.
      Throws:
      IllegalStateException - if this method is called before createClassGraph().
    • 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:
      IllegalStateException - if this method is called before createClassGraph().
    • getClassLayerMap

      public Map<AtomicVertex,Integer> getClassLayerMap()
      Calculates the for each class its layer index and returns a Map where the classes are the keys (type AtomicVertex) and the layer indices are the values (type Integer).
      Throws:
      IllegalStateException - if this method is called before createClassGraph().
    • createPackageGraph

      public long createPackageGraph()
      Creates the package graph from the class graph.
      Returns:
      the duration of this operation in milliseconds.
      Throws:
      IllegalStateException - if this method is called before createClassGraph().
    • printCSV

      public void printCSV(PrintWriter writer)
      Prints a CSV report into the specified writer. Delimiter is ','. First, a header with column titles is print. The columns are
      1. class name
      2. inner class (false or true)
      3. size (in bytes)
      4. used by (number of classes using this class)
      5. uses internal classes (number of classes of the graph used by this class)
      6. uses external classes (number of external classes used by this class)
      7. layer index
      Parameters:
      writer - Output stream.
    • printRaw

      public void printRaw(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(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:
      IllegalStateException - if this method is called before createClassGraph().
    • getPackageGraph

      public AtomicVertex[] getPackageGraph()
      Returns the package graph created the class graph.
      Throws:
      IllegalStateException - if this method is called before createClassGraph().
    • 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:
      IllegalStateException - if this method is called before createPackageGraph().
    • 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:
      IllegalStateException - if this method is called before createPackageGraph().
    • 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:
      IllegalStateException - if this method is called before createPackageGraph().
    • getPackageLayerMap

      public Map<AtomicVertex,Integer> getPackageLayerMap()
      Calculates the for each package its layer index and returns a Map where the packages are the keys (type AtomicVertex) and the layer indices are the values (type Integer).
      Throws:
      IllegalStateException - if this method is called before createPackageGraph().
    • readAndAnalyse

      public void readAndAnalyse(boolean packagesOnly) throws IOException
      Reads and analyses class files. Does only package analysis if packagesOnly == true. Reports progress of analysis on System.out.
      Throws:
      IOException - in case of reading problems.
    • printXML

      public void printXML(String title, boolean packagesOnly, 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:
      IllegalStateException - if this method is called before createPackageGraph().
    • main

      public static void main(String[] args) throws Exception
      Main 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:
      Exception