Package classycle

Class Analyser


  • public class Analyser
    extends java.lang.Object
    Main 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 specified StringPattern object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long calculateClassLayerMap()
      Calculates the for each class its layer index.
      long calculatePackageLayerMap()
      Calculates the for each package its layer index.
      long condenseClassGraph()
      Condenses the class graph to an acyclic graph of its strong components.
      long condensePackageGraph()
      Condenses the package graph to an acyclic graph of its strong components.
      long createClassGraph()
      Parses the class files and creates the class graph.
      long createPackageGraph()
      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 (type AtomicVertex) 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.
      int getNumberOfExternalClasses()
      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 (type AtomicVertex) and the layer indices are the values (type Integer).
      static void main​(java.lang.String[] args)
      Main method of the Analyser.
      void printComponents​(java.io.PrintWriter writer, int minSize)
      Prints for each strong component of the class graph a raw output into the specified writer.
      void printCSV​(java.io.PrintWriter writer)
      Prints a CSV report into the specified writer.
      void printRaw​(java.io.PrintWriter writer)
      Prints for each class a raw output into the specified writer.
      void printXML​(java.lang.String title, boolean packagesOnly, java.io.PrintWriter writer)
      Prints an XML report into the specified writer.
      void readAndAnalyse​(boolean packagesOnly)
      Reads and analyses class files.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 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 Detail

      • createClassGraph

        public long createClassGraph()
                              throws java.io.IOException
        Parses 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
      • 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 before createClassGraph().
      • 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 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:
        java.lang.IllegalStateException - if this method is called before createClassGraph().
      • 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 (type AtomicVertex) and the layer indices are the values (type Integer).
        Throws:
        java.lang.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:
        java.lang.IllegalStateException - if this method is called before createClassGraph().
      • 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
        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​(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 before createClassGraph().
      • getPackageGraph

        public AtomicVertex[] getPackageGraph()
        Returns the package graph created the class graph.
        Throws:
        java.lang.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:
        java.lang.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:
        java.lang.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:
        java.lang.IllegalStateException - if this method is called before createPackageGraph().
      • 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 (type AtomicVertex) and the layer indices are the values (type Integer).
        Throws:
        java.lang.IllegalStateException - if this method is called before createPackageGraph().
      • readAndAnalyse

        public void readAndAnalyse​(boolean packagesOnly)
                            throws java.io.IOException
        Reads 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 before createPackageGraph().
      • main

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