1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core;
13 import java.io.OutputStream;
15 import org.eclipse.core.runtime.IProgressMonitor;
18 * A type hierarchy provides navigations between a type and its resolved
19 * supertypes and subtypes for a specific type or for all types within a region.
20 * Supertypes may extend outside of the type hierarchy's region in which it was
21 * created such that the root of the hierarchy is always included. For example, if a type
22 * hierarchy is created for a <code>java.io.File</code>, and the region the hierarchy was
23 * created in is the package fragment <code>java.io</code>, the supertype
24 * <code>java.lang.Object</code> will still be included.
26 * A type hierarchy is static and can become stale. Although consistent when
27 * created, it does not automatically track changes in the model.
28 * As changes in the model potentially invalidate the hierarchy, change notifications
29 * are sent to registered <code>ITypeHierarchyChangedListener</code>s. Listeners should
30 * use the <code>exists</code> method to determine if the hierarchy has become completely
31 * invalid (for example, when the type or project the hierarchy was created on
32 * has been removed). To refresh a hierarchy, use the <code>refresh</code> method.
35 * The type hierarchy may contain cycles due to malformed supertype declarations.
36 * Most type hierarchy queries are oblivious to cycles; the <code>getAll* </code>
37 * methods are implemented such that they are unaffected by cycles.
40 * This interface is not intended to be implemented by clients.
43 public interface ITypeHierarchy {
45 * Adds the given listener for changes to this type hierarchy. Listeners are
46 * notified when this type hierarchy changes and needs to be refreshed.
47 * Has no effect if an identical listener is already registered.
49 * @param listener the listener
51 void addTypeHierarchyChangedListener(ITypeHierarchyChangedListener listener);
53 * Returns whether the given type is part of this hierarchy.
55 * @param type the given type
56 * @return true if the given type is part of this hierarchy, false otherwise
58 boolean contains(IType type);
60 * Returns whether the type and project this hierarchy was created on exist.
61 * @return true if the type and project this hierarchy was created on exist, false otherwise
65 * Returns all classes in this type hierarchy's graph, in no particular
66 * order. Any classes in the creation region which were not resolved to
67 * have any subtypes or supertypes are not included in the result.
69 * @return all classes in this type hierarchy's graph
71 IType[] getAllClasses();
73 * Returns all interfaces in this type hierarchy's graph, in no particular
74 * order. Any interfaces in the creation region which were not resolved to
75 * have any subtypes or supertypes are not included in the result.
77 * @return all interfaces in this type hierarchy's graph
79 IType[] getAllInterfaces();
81 * Returns all resolved subtypes (direct and indirect) of the
82 * given type, in no particular order, limited to the
83 * types in this type hierarchy's graph. An empty array
84 * is returned if there are no resolved subtypes for the
87 * @param type the given type
88 * @return all resolved subtypes (direct and indirect) of the given type
90 IType[] getAllSubtypes(IType type);
92 * Returns all resolved superclasses of the
93 * given class, in bottom-up order. An empty array
94 * is returned if there are no resolved superclasses for the
97 * <p>NOTE: once a type hierarchy has been created, it is more efficient to
98 * query the hierarchy for superclasses than to query a class recursively up
99 * the superclass chain. Querying an element performs a dynamic resolution,
100 * whereas the hierarchy returns a pre-computed result.
102 * @param type the given type
103 * @return all resolved superclasses of the given class, in bottom-up order, an empty
106 IType[] getAllSuperclasses(IType type);
108 * Returns all resolved superinterfaces (direct and indirect) of the given type.
109 * If the given type is a class, this includes all superinterfaces of all superclasses.
110 * An empty array is returned if there are no resolved superinterfaces for the
113 * <p>NOTE: once a type hierarchy has been created, it is more efficient to
114 * query the hierarchy for superinterfaces than to query a type recursively.
115 * Querying an element performs a dynamic resolution,
116 * whereas the hierarchy returns a pre-computed result.
118 * @param type the given type
119 * @return all resolved superinterfaces (direct and indirect) of the given type, an empty array if none
121 IType[] getAllSuperInterfaces(IType type);
123 * Returns all resolved supertypes of the
124 * given type, in bottom-up order. An empty array
125 * is returned if there are no resolved supertypes for the
128 * Note that <code>java.lang.Object</code> is NOT considered to be a supertype
129 * of any interface type.
130 * </p><p>NOTE: once a type hierarchy has been created, it is more efficient to
131 * query the hierarchy for supertypes than to query a type recursively up
132 * the supertype chain. Querying an element performs a dynamic resolution,
133 * whereas the hierarchy returns a pre-computed result.
135 * @param type the given type
136 * @return all resolved supertypes of the given class, in bottom-up order, an empty array
139 IType[] getAllSupertypes(IType type);
141 * Returns all types in this type hierarchy's graph, in no particular
142 * order. Any types in the creation region which were not resolved to
143 * have any subtypes or supertypes are not included in the result.
145 * @return all types in this type hierarchy's grap
147 IType[] getAllTypes();
150 * Return the flags associated with the given type (would be equivalent to <code>IMember.getFlags()</code>),
151 * or <code>-1</code> if this information wasn't cached on the hierarchy during its computation.
153 * @param type the given type
154 * @return the modifier flags for this member
158 int getCachedFlags(IType type);
161 * Returns all interfaces resolved to extend the given interface,
162 * in no particular order, limited to the interfaces in this
164 * Returns an empty collection if the given type is a class, or
165 * if no interfaces were resolved to extend the given interface.
167 * @param type the given type
168 * @return all interfaces resolved to extend the given interface limited to the interfaces in this
169 * hierarchy's graph, an empty array if none.
171 IType[] getExtendingInterfaces(IType type);
173 * Returns all classes resolved to implement the given interface,
174 * in no particular order, limited to the classes in this type
175 * hierarchy's graph. Returns an empty collection if the given type is a
176 * class, or if no classes were resolved to implement the given
179 * @param type the given type
180 * @return all classes resolved to implement the given interface limited to the classes in this type
181 * hierarchy's graph, an empty array if none
183 IType[] getImplementingClasses(IType type);
185 * Returns all classes in the graph which have no resolved superclass,
186 * in no particular order.
188 * @return all classes in the graph which have no resolved superclass
190 IType[] getRootClasses();
192 * Returns all interfaces in the graph which have no resolved superinterfaces,
193 * in no particular order.
195 * @return all interfaces in the graph which have no resolved superinterfaces
197 IType[] getRootInterfaces();
199 * Returns the direct resolved subclasses of the given class,
200 * in no particular order, limited to the classes in this
201 * type hierarchy's graph.
202 * Returns an empty collection if the given type is an interface,
203 * or if no classes were resolved to be subclasses of the given
206 * @param type the given type
207 * @return the direct resolved subclasses of the given class limited to the classes in this
208 * type hierarchy's graph, an empty collection if none.
210 IType[] getSubclasses(IType type);
212 * Returns the direct resolved subtypes of the given type,
213 * in no particular order, limited to the types in this
214 * type hierarchy's graph.
215 * If the type is a class, this returns the resolved subclasses.
216 * If the type is an interface, this returns both the classes which implement
217 * the interface and the interfaces which extend it.
219 * @param type the given type
220 * @return the direct resolved subtypes of the given type limited to the types in this
221 * type hierarchy's graph
223 IType[] getSubtypes(IType type);
225 * Returns the resolved superclass of the given class,
226 * or <code>null</code> if the given class has no superclass,
227 * the superclass could not be resolved, or if the given
228 * type is an interface.
230 * @param type the given type
231 * @return the resolved superclass of the given class,
232 * or <code>null</code> if the given class has no superclass,
233 * the superclass could not be resolved, or if the given
234 * type is an interface
236 IType getSuperclass(IType type);
238 * Returns the direct resolved interfaces that the given type implements or extends,
239 * in no particular order, limited to the interfaces in this type
241 * For classes, this gives the interfaces that the class implements.
242 * For interfaces, this gives the interfaces that the interface extends.
244 * @param type the given type
245 * @return the direct resolved interfaces that the given type implements or extends limited to the interfaces in this type
248 IType[] getSuperInterfaces(IType type);
250 * Returns the resolved supertypes of the given type,
251 * in no particular order, limited to the types in this
252 * type hierarchy's graph.
253 * For classes, this returns its superclass and the interfaces that the class implements.
254 * For interfaces, this returns the interfaces that the interface extends. As a consequence
255 * <code>java.lang.Object</code> is NOT considered to be a supertype of any interface
258 * @param type the given type
259 * @return the resolved supertypes of the given type limited to the types in this
260 * type hierarchy's graph
262 IType[] getSupertypes(IType type);
264 * Returns the type this hierarchy was computed for.
265 * Returns <code>null</code> if this hierarchy was computed for a region.
267 * @return the type this hierarchy was computed for
271 * Re-computes the type hierarchy reporting progress.
273 * @param monitor the given progress monitor
274 * @exception JavaModelException if unable to refresh the hierarchy
276 void refresh(IProgressMonitor monitor) throws JavaModelException;
278 * Removes the given listener from this type hierarchy.
279 * Has no affect if an identical listener is not registered.
281 * @param listener the listener
283 void removeTypeHierarchyChangedListener(ITypeHierarchyChangedListener listener);
285 * Stores the type hierarchy in an output stream. This stored hierarchy can be load by
286 * IType#loadTypeHierachy(IJavaProject, InputStream, IProgressMonitor).
287 * Listeners of this hierarchy are not stored.
289 * Only hierarchies created by the following methods can be store:
291 * <li>IType#newSupertypeHierarchy(IProgressMonitor)</li>
292 * <li>IType#newTypeHierarchy(IJavaProject, IProgressMonitor)</li>
293 * <li>IType#newTypeHierarchy(IProgressMonitor)</li>
296 * @param outputStream output stream where the hierarchy will be stored
297 * @param monitor the given progress monitor
298 * @exception JavaModelException if unable to store the hierarchy in the ouput stream
299 * @see IType#loadTypeHierachy(java.io.InputStream, IProgressMonitor)
302 void store(OutputStream outputStream, IProgressMonitor monitor) throws JavaModelException;