java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy
All Implemented Interfaces:
IElementChangedListener, ITypeHierarchy
Direct Known Subclasses:
RegionBasedTypeHierarchy

public class TypeHierarchy extends Object implements ITypeHierarchy, IElementChangedListener
See Also:
  • Field Details

    • DEBUG

      public static boolean DEBUG
    • project

      protected IJavaProject project
      The Java Project in which the hierarchy is being built - this provides the context for determining a classpath and namelookup rules. Possibly null.
    • focusType

      protected IType focusType
      The type the hierarchy was specifically computed for, possibly null.
    • workingCopies

      protected ICompilationUnit[] workingCopies
    • classToSuperclass

      protected Map<IType,IType> classToSuperclass
    • typeToSuperInterfaces

      protected Map<IType,IType[]> typeToSuperInterfaces
    • typeToSubtypes

      protected Map<IType,Set<IType>> typeToSubtypes
    • typeFlags

      protected Map<IType,Integer> typeFlags
    • rootClasses

      protected Set<IType> rootClasses
    • interfaces

      protected Set<IType> interfaces
    • missingTypes

      public Set<String> missingTypes
    • NO_TYPE

      protected static final IType[] NO_TYPE
    • progressMonitor

      protected org.eclipse.core.runtime.SubMonitor progressMonitor
      The progress monitor to report work completed too.
    • changeListeners

      protected ArrayList<ITypeHierarchyChangedListener> changeListeners
      Change listeners - null if no one is listening.
    • files

      public Map<IOpenable,ArrayList<IType>> files
    • packageRegion

      protected Region packageRegion
      A region describing the packages considered by this hierarchy. Null if not activated.
    • projectRegion

      protected Region projectRegion
      A region describing the projects considered by this hierarchy. Null if not activated.
    • computeSubtypes

      protected boolean computeSubtypes
      Whether this hierarchy should contains subtypes.
    • needsRefresh

      public boolean needsRefresh
    • changeCollector

      protected ChangeCollector changeCollector
  • Constructor Details

    • TypeHierarchy

      public TypeHierarchy()
      Creates an empty TypeHierarchy
    • TypeHierarchy

      public TypeHierarchy(IType type, ICompilationUnit[] workingCopies, IJavaProject project, boolean computeSubtypes)
      Creates a TypeHierarchy on the given type.
    • TypeHierarchy

      public TypeHierarchy(IType type, ICompilationUnit[] workingCopies, IJavaSearchScope scope, boolean computeSubtypes)
      Creates a TypeHierarchy on the given type.
  • Method Details

    • initializeRegions

      protected void initializeRegions()
      Initializes the file, package and project regions
    • addInterface

      protected void addInterface(IType type)
      Adds the type to the collection of interfaces.
    • addRootClass

      protected void addRootClass(IType type)
      Adds the type to the collection of root classes if the classes is not already present in the collection.
    • addSubtype

      protected void addSubtype(IType type, IType subtype)
      Adds the given subtype to the type.
    • addTypeHierarchyChangedListener

      public void addTypeHierarchyChangedListener(ITypeHierarchyChangedListener listener)
      Description copied from interface: ITypeHierarchy
      Adds the given listener for changes to this type hierarchy. Listeners are notified when this type hierarchy changes and needs to be refreshed. Has no effect if an identical listener is already registered.
      Specified by:
      addTypeHierarchyChangedListener in interface ITypeHierarchy
      Parameters:
      listener - the listener
      See Also:
    • cacheFlags

      public void cacheFlags(IType type, int flags)
      cacheFlags.
    • cacheSuperclass

      protected void cacheSuperclass(IType type, IType superclass)
      Caches the handle of the superclass for the specified type. As a side effect cache this type as a subtype of the superclass.
    • cacheSuperInterfaces

      protected void cacheSuperInterfaces(IType type, IType[] superinterfaces)
      Caches all of the superinterfaces that are specified for the type.
    • checkCanceled

      protected void checkCanceled()
      Checks with the progress monitor to see whether the creation of the type hierarchy should be canceled. Should be regularly called so that the user can cancel.
      Throws:
      org.eclipse.core.runtime.OperationCanceledException - if cancelling the operation has been requested
      See Also:
      • IProgressMonitor.isCanceled()
    • compute

      protected void compute() throws JavaModelException, org.eclipse.core.runtime.CoreException
      Compute this type hierarchy.
      Throws:
      JavaModelException
      org.eclipse.core.runtime.CoreException
    • contains

      public boolean contains(IType type)
      Description copied from interface: ITypeHierarchy
      Returns whether the given type is part of this hierarchy.
      Specified by:
      contains in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      true if the given type is part of this hierarchy, false otherwise
      See Also:
    • elementChanged

      public void elementChanged(ElementChangedEvent event)
      Determines if the change affects this hierarchy, and fires change notification if required.
      Specified by:
      elementChanged in interface IElementChangedListener
      Parameters:
      event - the change event
    • exists

      public boolean exists()
      Description copied from interface: ITypeHierarchy
      Returns whether the type and project this hierarchy was created on exist.
      Specified by:
      exists in interface ITypeHierarchy
      Returns:
      true if the type and project this hierarchy was created on exist, false otherwise
      See Also:
    • fireChange

      public void fireChange()
      Notifies listeners that this hierarchy has changed and needs refreshing. Note that listeners can be removed as we iterate through the list.
    • getAllClasses

      public IType[] getAllClasses()
      Description copied from interface: ITypeHierarchy
      Returns all classes in this type hierarchy's graph, in no particular order. Any classes in the creation region which were not resolved to have any subtypes or supertypes are not included in the result.
      Specified by:
      getAllClasses in interface ITypeHierarchy
      Returns:
      all classes in this type hierarchy's graph
      See Also:
    • getAllInterfaces

      public IType[] getAllInterfaces()
      Description copied from interface: ITypeHierarchy
      Returns all interfaces in this type hierarchy's graph, in no particular order. Any interfaces in the creation region which were not resolved to have any subtypes or supertypes are not included in the result.
      Specified by:
      getAllInterfaces in interface ITypeHierarchy
      Returns:
      all interfaces in this type hierarchy's graph
      See Also:
    • getAllSubtypes

      public IType[] getAllSubtypes(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all resolved subtypes (direct and indirect) of the given type, in no particular order, limited to the types in this type hierarchy's graph. An empty array is returned if there are no resolved subtypes for the given type.
      Specified by:
      getAllSubtypes in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all resolved subtypes (direct and indirect) of the given type
      See Also:
    • getAllSuperclasses

      public IType[] getAllSuperclasses(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all resolved superclasses of the given class, in bottom-up order. An empty array is returned if there are no resolved superclasses for the given class.

      NOTE: once a type hierarchy has been created, it is more efficient to query the hierarchy for superclasses than to query a class recursively up the superclass chain. Querying an element performs a dynamic resolution, whereas the hierarchy returns a pre-computed result.

      Specified by:
      getAllSuperclasses in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all resolved superclasses of the given class, in bottom-up order, an empty array if none.
      See Also:
    • getAllSuperInterfaces

      public IType[] getAllSuperInterfaces(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all resolved superinterfaces (direct and indirect) of the given type. If the given type is a class, this includes all superinterfaces of all superclasses. An empty array is returned if there are no resolved superinterfaces for the given type.

      NOTE: once a type hierarchy has been created, it is more efficient to query the hierarchy for superinterfaces than to query a type recursively. Querying an element performs a dynamic resolution, whereas the hierarchy returns a pre-computed result.

      Specified by:
      getAllSuperInterfaces in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all resolved superinterfaces (direct and indirect) of the given type, an empty array if none
      See Also:
    • getAllSupertypes

      public IType[] getAllSupertypes(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all resolved supertypes of the given type, in bottom-up order. An empty array is returned if there are no resolved supertypes for the given type.

      Note that java.lang.Object is NOT considered to be a supertype of any interface type.

      NOTE: once a type hierarchy has been created, it is more efficient to query the hierarchy for supertypes than to query a type recursively up the supertype chain. Querying an element performs a dynamic resolution, whereas the hierarchy returns a pre-computed result.

      Specified by:
      getAllSupertypes in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all resolved supertypes of the given class, in bottom-up order, an empty array if none
      See Also:
    • getAllTypes

      public IType[] getAllTypes()
      Description copied from interface: ITypeHierarchy
      Returns all types in this type hierarchy's graph, in no particular order. Any types in the creation region which were not resolved to have any subtypes or supertypes are not included in the result.
      Specified by:
      getAllTypes in interface ITypeHierarchy
      Returns:
      all types in this type hierarchy's graph
      See Also:
    • getCachedFlags

      public int getCachedFlags(IType type)
      Description copied from interface: ITypeHierarchy
      Return the flags associated with the given type (would be equivalent to IMember.getFlags()), or -1 if this information wasn't cached on the hierarchy during its computation.
      Specified by:
      getCachedFlags in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the modifier flags for this member
      See Also:
    • getExtendingInterfaces

      public IType[] getExtendingInterfaces(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all interfaces resolved to extend the given interface, in no particular order, limited to the interfaces in this hierarchy's graph. Returns an empty collection if the given type is a class, or if no interfaces were resolved to extend the given interface.
      Specified by:
      getExtendingInterfaces in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all interfaces resolved to extend the given interface limited to the interfaces in this hierarchy's graph, an empty array if none.
      See Also:
    • getImplementingClasses

      public IType[] getImplementingClasses(IType type)
      Description copied from interface: ITypeHierarchy
      Returns all classes resolved to implement the given interface, in no particular order, limited to the classes in this type hierarchy's graph. Returns an empty collection if the given type is a class, or if no classes were resolved to implement the given interface.
      Specified by:
      getImplementingClasses in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      all classes resolved to implement the given interface limited to the classes in this type hierarchy's graph, an empty array if none
      See Also:
    • getRootClasses

      public IType[] getRootClasses()
      Description copied from interface: ITypeHierarchy
      Returns all classes in the graph which have no resolved superclass, in no particular order.
      Specified by:
      getRootClasses in interface ITypeHierarchy
      Returns:
      all classes in the graph which have no resolved superclass
      See Also:
    • getRootInterfaces

      public IType[] getRootInterfaces()
      Description copied from interface: ITypeHierarchy
      Returns all interfaces in the graph which have no resolved superinterfaces, in no particular order.
      Specified by:
      getRootInterfaces in interface ITypeHierarchy
      Returns:
      all interfaces in the graph which have no resolved superinterfaces
      See Also:
    • getSubclasses

      public IType[] getSubclasses(IType type)
      Description copied from interface: ITypeHierarchy
      Returns the direct resolved subclasses of the given class, in no particular order, limited to the classes in this type hierarchy's graph. Returns an empty collection if the given type is an interface, or if no classes were resolved to be subclasses of the given class.
      Specified by:
      getSubclasses in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the direct resolved subclasses of the given class limited to the classes in this type hierarchy's graph, an empty collection if none.
      See Also:
    • getSubtypes

      public IType[] getSubtypes(IType type)
      Description copied from interface: ITypeHierarchy
      Returns the direct resolved subtypes of the given type, in no particular order, limited to the types in this type hierarchy's graph. If the type is a class, this returns the resolved subclasses. If the type is an interface, this returns both the classes which implement the interface and the interfaces which extend it.
      Specified by:
      getSubtypes in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the direct resolved subtypes of the given type limited to the types in this type hierarchy's graph
      See Also:
    • getSuperclass

      public IType getSuperclass(IType type)
      Description copied from interface: ITypeHierarchy
      Returns the resolved superclass of the given class, or null if the given class has no superclass, the superclass could not be resolved, or if the given type is an interface.
      Specified by:
      getSuperclass in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the resolved superclass of the given class, or null if the given class has no superclass, the superclass could not be resolved, or if the given type is an interface
      See Also:
    • getSuperInterfaces

      public IType[] getSuperInterfaces(IType type)
      Description copied from interface: ITypeHierarchy
      Returns the direct resolved interfaces that the given type implements or extends, in no particular order, limited to the interfaces in this type hierarchy's graph. For classes, this gives the interfaces that the class implements. For interfaces, this gives the interfaces that the interface extends.
      Specified by:
      getSuperInterfaces in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the direct resolved interfaces that the given type implements or extends limited to the interfaces in this type hierarchy's graph
      See Also:
    • getSupertypes

      public IType[] getSupertypes(IType type)
      Description copied from interface: ITypeHierarchy
      Returns the resolved supertypes of the given type, in no particular order, limited to the types in this type hierarchy's graph. For classes, this returns its superclass and the interfaces that the class implements. For interfaces, this returns the interfaces that the interface extends. As a consequence java.lang.Object is NOT considered to be a supertype of any interface type.
      Specified by:
      getSupertypes in interface ITypeHierarchy
      Parameters:
      type - the given type
      Returns:
      the resolved supertypes of the given type limited to the types in this type hierarchy's graph
      See Also:
    • getType

      public IType getType()
      Description copied from interface: ITypeHierarchy
      Returns the type this hierarchy was computed for. Returns null if this hierarchy was computed for a region.
      Specified by:
      getType in interface ITypeHierarchy
      Returns:
      the type this hierarchy was computed for
      See Also:
    • growAndAddToArray

      protected IType[] growAndAddToArray(IType[] array, IType[] additions)
      Adds the new elements to a new array that contains all of the elements of the old array. Returns the new array.
    • growAndAddToArray

      protected IType[] growAndAddToArray(IType[] array, IType addition)
      Adds the new element to a new array that contains all of the elements of the old array. Returns the new array.
    • hasFineGrainChanges

      public boolean hasFineGrainChanges()
    • initialize

      protected void initialize(int size)
      Initializes this hierarchy's internal tables with the given size.
    • isAffected

      public boolean isAffected(IJavaElementDelta delta, int eventType)
      Returns true if the given delta could change this type hierarchy
      Parameters:
      eventType - TODO
    • isAffectedByOpenable

      protected boolean isAffectedByOpenable(IJavaElementDelta delta, IJavaElement element, int eventType)
      Returns true if the given type delta (a compilation unit delta or a class file delta) could affect this type hierarchy.
      Parameters:
      eventType - TODO
    • javaProject

      public IJavaProject javaProject()
      Returns the java project this hierarchy was created in.
    • readUntil

      protected static byte[] readUntil(InputStream input, byte separator) throws JavaModelException, IOException
      Throws:
      JavaModelException
      IOException
    • readUntil

      protected static byte[] readUntil(InputStream input, byte separator, int offset) throws IOException, JavaModelException
      Throws:
      IOException
      JavaModelException
    • load

      public static ITypeHierarchy load(IType type, InputStream input, WorkingCopyOwner owner) throws JavaModelException
      Throws:
      JavaModelException
    • packageRegionContainsSamePackageFragment

      protected boolean packageRegionContainsSamePackageFragment(PackageFragment element)
      Returns true if an equivalent package fragment is included in the package region. Package fragments are equivalent if they both have the same name.
    • refresh

      public void refresh(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ITypeHierarchy
      Re-computes the type hierarchy reporting progress.
      Specified by:
      refresh in interface ITypeHierarchy
      Parameters:
      monitor - the given progress monitor
      Throws:
      JavaModelException - if unable to refresh the hierarchy
      See Also:
    • removeTypeHierarchyChangedListener

      public void removeTypeHierarchyChangedListener(ITypeHierarchyChangedListener listener)
      Description copied from interface: ITypeHierarchy
      Removes the given listener from this type hierarchy. Has no effect if an identical listener is not registered.
      Specified by:
      removeTypeHierarchyChangedListener in interface ITypeHierarchy
      Parameters:
      listener - the listener
      See Also:
    • store

      public void store(OutputStream output, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ITypeHierarchy
      Stores the type hierarchy in an output stream. This stored hierarchy can be load by IType#loadTypeHierachy(IJavaProject, InputStream, IProgressMonitor). Listeners of this hierarchy are not stored. Only hierarchies created by the following methods can be store:
      • IType#newSupertypeHierarchy(IProgressMonitor)
      • IType#newTypeHierarchy(IJavaProject, IProgressMonitor)
      • IType#newTypeHierarchy(IProgressMonitor)
      Specified by:
      store in interface ITypeHierarchy
      Parameters:
      output - output stream where the hierarchy will be stored
      monitor - the given progress monitor
      Throws:
      JavaModelException - if unable to store the hierarchy in the ouput stream
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • worked

      protected void worked(int work)
      See Also:
      • IProgressMonitor