Class ClassHierarchy


  • public class ClassHierarchy
    extends java.lang.Object
    ClassHierarchy maintains a graph of the subclass relationships of the classes loaded by the ClassInfoLoader.
    See Also:
    ClassInfoLoader
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  ClassHierarchy.ResolvesToWith
      Represents a method and a set of Types.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassHierarchy​(EditorContext context, java.util.Collection initial, boolean closure)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addClassNamed​(java.lang.String name)
      Adds a class of a given name to the ClassHierarchy.
      java.util.Collection classes()
      Returns (the Types of) all of the classes and interfaces in the hierarchy.
      boolean closure()
      Returns true if class closure has been computed
      java.util.Collection implementors​(Type type)
      Returns the classes (Types) that implement a given interface as a Collection of Types.
      java.util.Collection interfaces​(Type type)
      Returns the interfaces that a given Type implements as a Collection of Types
      Type intersectType​(Type a, Type b)
      Returns the intersection of two types.
      MemberRef methodInvoked​(Type receiver, NameAndType method)
      Returns the MemberRef of the method that would be invoked if a given method of a given type was invoked.
      boolean methodIsOverridden​(Type classType, NameAndType nat)
      Determines whether or not a class's method is overriden by any of its subclasses.
      void printClasses​(java.io.PrintWriter out, int indent)
      Prints the class hierarchy (i.e.
      void printImplements​(java.io.PrintWriter out, int indent)
      Prints the implements hierarchy to a PrintWriter.
      java.util.Set resolvesToWith​(MemberRef method)
      Returns a set of ResolvesToWith that represent all subclass methods that override a given method and the subclasses that when used as receivers resolve to that method.
      static Type setToType​(java.util.BitSet v)
      Given a set of bits representing the range of values some type has, determines what that Type is.
      java.util.Collection subclasses​(Type type)
      Returns the immediate subclasses of a given Type as a Collection of Types.
      boolean subclassOf​(Type a, Type b)
      Returns whether or not a is a subclass of b.
      Type superclass​(Type type)
      Returns the superclass of a given Type.
      static java.util.BitSet typeToSet​(Type type)
      Returns a BitSet representing the possible values of a given integral type.
      Type unionType​(Type a, Type b)
      Returns the union of two types.
      Type unionTypes​(java.util.Collection types)
      Returns the most refined common supertype for a bunch of Types.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • POS_SHORT

        public static final Type POS_SHORT
      • POS_BYTE

        public static final Type POS_BYTE
      • DEBUG

        public static boolean DEBUG
      • RELAX

        public static boolean RELAX
    • Constructor Detail

      • ClassHierarchy

        public ClassHierarchy​(EditorContext context,
                              java.util.Collection initial,
                              boolean closure)
        Constructor.
        Parameters:
        context - The context in which to access an Editor and other such things.
        initial - The names of the classes that initially constitue the hierarchy.
        closure - Do we get the maximum amount of class information?
    • Method Detail

      • addClassNamed

        public void addClassNamed​(java.lang.String name)
        Adds a class of a given name to the ClassHierarchy.
      • subclasses

        public java.util.Collection subclasses​(Type type)
        Returns the immediate subclasses of a given Type as a Collection of Types.

        The subclass relationship at the classfile level is a little screwy with respect to interfaces. An interface that extends another interface is compiled into an interface that extends java.lang.Object and implements the superinterface. As a result, the interface-subinterface is not captured in subclasses as one may expect. Instead, you have to look at implementors and filter out the classes.

      • superclass

        public Type superclass​(Type type)
        Returns the superclass of a given Type. If the Type has no superclass (that is it is Type.OBJECT), then null is returned.
      • interfaces

        public java.util.Collection interfaces​(Type type)
        Returns the interfaces that a given Type implements as a Collection of Types
      • implementors

        public java.util.Collection implementors​(Type type)
        Returns the classes (Types) that implement a given interface as a Collection of Types.

        See note in subclasses for information about the interface hierarchy.

      • subclassOf

        public boolean subclassOf​(Type a,
                                  Type b)
        Returns whether or not a is a subclass of b.
      • classes

        public java.util.Collection classes()
        Returns (the Types of) all of the classes and interfaces in the hierarchy.
      • closure

        public boolean closure()
        Returns true if class closure has been computed
      • intersectType

        public Type intersectType​(Type a,
                                  Type b)
        Returns the intersection of two types. Basically, the interstion of two types is the type (if any) to which both types may be assigned. So, if a is a subtype of b, a is returned. Otherwise, Type.NULL is returned.
      • unionTypes

        public Type unionTypes​(java.util.Collection types)
        Returns the most refined common supertype for a bunch of Types.
      • unionType

        public Type unionType​(Type a,
                              Type b)
        Returns the union of two types. The union of two types is their most refined common supertype. At worst, the union is Type.OBJECT
      • printClasses

        public void printClasses​(java.io.PrintWriter out,
                                 int indent)
        Prints the class hierarchy (i.e. the "extends" hierarchy, interfaces may extends other interfaces) to a PrintWriter.
      • printImplements

        public void printImplements​(java.io.PrintWriter out,
                                    int indent)
        Prints the implements hierarchy to a PrintWriter.
      • methodIsOverridden

        public boolean methodIsOverridden​(Type classType,
                                          NameAndType nat)
        Determines whether or not a class's method is overriden by any of its subclasses.
      • methodInvoked

        public MemberRef methodInvoked​(Type receiver,
                                       NameAndType method)
        Returns the MemberRef of the method that would be invoked if a given method of a given type was invoked. Basically, dynamic dispatch is simulated.
      • setToType

        public static Type setToType​(java.util.BitSet v)
        Given a set of bits representing the range of values some type has, determines what that Type is.
      • typeToSet

        public static java.util.BitSet typeToSet​(Type type)
        Returns a BitSet representing the possible values of a given integral type.
      • resolvesToWith

        public java.util.Set resolvesToWith​(MemberRef method)
        Returns a set of ResolvesToWith that represent all subclass methods that override a given method and the subclasses that when used as receivers resolve to that method.
        See Also:
        ClassHierarchy.ResolvesToWith