1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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 org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.core.runtime.IPath;
18 * Common protocol for all elements provided by the Java model.
19 * Java model elements are exposed to clients as handles to the actual underlying element.
20 * The Java model may hand out any number of handles for each element. Handles
21 * that refer to the same element are guaranteed to be equal, but not necessarily identical.
23 * Methods annotated as "handle-only" do not require underlying elements to exist.
24 * Methods that require underlying elements to exist throw
25 * a <code>JavaModelException</code> when an underlying element is missing.
26 * <code>JavaModelException.isDoesNotExist</code> can be used to recognize
27 * this common special case.
30 * This interface is not intended to be implemented by clients.
33 public interface IJavaElement extends IAdaptable {
36 * Constant representing a Java model (workspace level object).
37 * A Java element with this type can be safely cast to <code>IJavaModel</code>.
42 * Constant representing a Java project.
43 * A Java element with this type can be safely cast to <code>IJavaProject</code>.
48 * Constant representing a package fragment root.
49 * A Java element with this type can be safely cast to <code>IPackageFragmentRoot</code>.
51 int PACKAGE_FRAGMENT_ROOT = 3;
54 * Constant representing a package fragment.
55 * A Java element with this type can be safely cast to <code>IPackageFragment</code>.
57 int PACKAGE_FRAGMENT = 4;
60 * Constant representing a Java compilation unit.
61 * A Java element with this type can be safely cast to <code>ICompilationUnit</code>.
63 int COMPILATION_UNIT = 5;
66 * Constant representing a class file.
67 * A Java element with this type can be safely cast to <code>IClassFile</code>.
72 * Constant representing a type (a class or interface).
73 * A Java element with this type can be safely cast to <code>IType</code>.
78 * Constant representing a field.
79 * A Java element with this type can be safely cast to <code>IField</code>.
84 * Constant representing a method or constructor.
85 * A Java element with this type can be safely cast to <code>IMethod</code>.
90 * Constant representing a stand-alone instance or class initializer.
91 * A Java element with this type can be safely cast to <code>IInitializer</code>.
96 * Constant representing a package declaration within a compilation unit.
97 * A Java element with this type can be safely cast to <code>IPackageDeclaration</code>.
99 int PACKAGE_DECLARATION = 11;
102 * Constant representing all import declarations within a compilation unit.
103 * A Java element with this type can be safely cast to <code>IImportContainer</code>.
105 int IMPORT_CONTAINER = 12;
108 * Constant representing an import declaration within a compilation unit.
109 * A Java element with this type can be safely cast to <code>IImportDeclaration</code>.
111 int IMPORT_DECLARATION = 13;
114 * Returns whether this Java element exists in the model.
116 * Java elements are handle objects that may or may not be backed by an
117 * actual element. Java elements that are backed by an actual element are
118 * said to "exist", and this method returns <code>true</code>. For Java
119 * elements that are not working copies, it is always the case that if the
120 * element exists, then its parent also exists (provided it has one) and
121 * includes the element as one of its children. It is therefore possible
122 * to navigated to any existing Java element from the root of the Java model
123 * along a chain of existing Java elements. On the other hand, working
124 * copies are said to exist until they are destroyed (with
125 * <code>IWorkingCopy.destroy</code>). Unlike regular Java elements, a
126 * working copy never shows up among the children of its parent element
127 * (which may or may not exist).
130 * @return <code>true</code> if this element exists in the Java model, and
131 * <code>false</code> if this element does not exist
136 * Returns the first ancestor of this Java element that has the given type.
137 * Returns <code>null</code> if no such an ancestor can be found.
138 * This is a handle-only method.
140 * @param ancestorType the given type
141 * @return the first ancestor of this Java element that has the given type, null if no such an ancestor can be found
144 IJavaElement getAncestor(int ancestorType);
147 * Returns the resource that corresponds directly to this element,
148 * or <code>null</code> if there is no resource that corresponds to
151 * For example, the corresponding resource for an <code>ICompilationUnit</code>
152 * is its underlying <code>IFile</code>. The corresponding resource for
153 * an <code>IPackageFragment</code> that is not contained in an archive
154 * is its underlying <code>IFolder</code>. An <code>IPackageFragment</code>
155 * contained in an archive has no corresponding resource. Similarly, there
156 * are no corresponding resources for <code>IMethods</code>,
157 * <code>IFields</code>, etc.
160 * @return the corresponding resource, or <code>null</code> if none
161 * @exception JavaModelException if this element does not exist or if an
162 * exception occurs while accessing its corresponding resource
164 IResource getCorrespondingResource() throws JavaModelException;
167 * Returns the name of this element. This is a handle-only method.
169 * @return the element name
171 String getElementName();
174 * Returns this element's kind encoded as an integer.
175 * This is a handle-only method.
177 * @return the kind of element; one of the constants declared in
178 * <code>IJavaElement</code>
181 int getElementType();
184 * Returns a string representation of this element handle. The format of
185 * the string is not specified; however, the identifier is stable across
186 * workspace sessions, and can be used to recreate this handle via the
187 * <code>JavaCore.create(String)</code> method.
189 * @return the string handle identifier
190 * @see JavaCore#create(java.lang.String)
192 String getHandleIdentifier();
195 * Returns the Java model.
196 * This is a handle-only method.
198 * @return the Java model
200 IJavaModel getJavaModel();
203 * Returns the Java project this element is contained in,
204 * or <code>null</code> if this element is not contained in any Java project
205 * (for instance, the <code>IJavaModel</code> is not contained in any Java
207 * This is a handle-only method.
209 * @return the containing Java project, or <code>null</code> if this element is
210 * not contained in a Java project
212 IJavaProject getJavaProject();
215 * Returns the first openable parent. If this element is openable, the element
216 * itself is returned. Returns <code>null</code> if this element doesn't have
217 * an openable parent.
218 * This is a handle-only method.
220 * @return the first openable parent or <code>null</code> if this element doesn't have
221 * an openable parent.
224 IOpenable getOpenable();
227 * Returns the element directly containing this element,
228 * or <code>null</code> if this element has no parent.
229 * This is a handle-only method.
231 * @return the parent element, or <code>null</code> if this element has no parent
233 IJavaElement getParent();
236 * Returns the path to the innermost resource enclosing this element.
237 * If this element is not included in an external archive,
238 * the path returned is the full, absolute path to the underlying resource,
239 * relative to the workbench.
240 * If this element is included in an external archive,
241 * the path returned is the absolute path to the archive in the file system.
242 * This is a handle-only method.
244 * @return the path to the innermost resource enclosing this element
250 * Returns the innermost resource enclosing this element.
251 * If this element is included in an archive and this archive is not external,
252 * this is the underlying resource corresponding to the archive.
253 * If this element is included in an external archive, <code>null</code>
255 * If this element is a working copy, <code>null</code> is returned.
256 * This is a handle-only method.
258 * @return the innermost resource enclosing this element, <code>null</code> if this
259 * element is a working copy or is included in an external archive
262 IResource getResource();
265 * Returns the smallest underlying resource that contains
266 * this element, or <code>null</code> if this element is not contained
269 * @return the underlying resource, or <code>null</code> if none
270 * @exception JavaModelException if this element does not exist or if an
271 * exception occurs while accessing its underlying resource
273 IResource getUnderlyingResource() throws JavaModelException;
276 * Returns whether this Java element is read-only. An element is read-only
277 * if its structure cannot be modified by the java model.
279 * Note this is different from IResource.isReadOnly(). For example, .jar
280 * files are read-only as the java model doesn't know how to add/remove
281 * elements in this file, but the underlying IFile can be writable.
283 * This is a handle-only method.
285 * @return <code>true</code> if this element is read-only
287 boolean isReadOnly();
290 * Returns whether the structure of this element is known. For example, for a
291 * compilation unit that could not be parsed, <code>false</code> is returned.
292 * If the structure of an element is unknown, navigations will return reasonable
293 * defaults. For example, <code>getChildren</code> will return an empty collection.
295 * Note: This does not imply anything about consistency with the
296 * underlying resource/buffer contents.
299 * @return <code>true</code> if the structure of this element is known
300 * @exception JavaModelException if this element does not exist or if an
301 * exception occurs while accessing its corresponding resource
303 boolean isStructureKnown() throws JavaModelException;