Skip to main content
summaryrefslogtreecommitdiffstats
blob: 092c56dc5e9af32fb2d18072adbaf8cc69e409e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package org.eclipse.jdt.core;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
 
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;

/**
 * Common protocol for all elements provided by the Java model.
 * Java model elements are exposed to clients as handles to the actual underlying element.
 * The Java model may hand out any number of handles for each element. Handles
 * that refer to the same element are guaranteed to be equal, but not necessarily identical.
 * <p>
 * Methods annotated as "handle-only" do not require underlying elements to exist. 
 * Methods that require underlying elements to exist throw
 * a <code>JavaModelException</code> when an underlying element is missing.
 * <code>JavaModelException.isDoesNotExist</code> can be used to recognize
 * this common special case.
 * </p>
 * <p>
 * This interface is not intended to be implemented by clients.
 * </p>
 */
public interface IJavaElement extends IAdaptable {

	/**
	 * Constant representing a Java model (workspace level object).
	 * A Java element with this type can be safely cast to <code>IJavaModel</code>.
	 */
	public static final int JAVA_MODEL = 1;

	/**
	 * Constant representing a Java project.
	 * A Java element with this type can be safely cast to <code>IJavaProject</code>.
	 */
	public static final int JAVA_PROJECT = 2;

	/**
	 * Constant representing a package fragment root.
	 * A Java element with this type can be safely cast to <code>IPackageFragmentRoot</code>.
	 */
	public static final int PACKAGE_FRAGMENT_ROOT = 3;

	/**
	 * Constant representing a package fragment.
	 * A Java element with this type can be safely cast to <code>IPackageFragment</code>.
	 */
	public static final int PACKAGE_FRAGMENT = 4;

	/**
	 * Constant representing a Java compilation unit.
	 * A Java element with this type can be safely cast to <code>ICompilationUnit</code>.
	 */
	public static final int COMPILATION_UNIT = 5;

	/**
	 * Constant representing a class file.
	 * A Java element with this type can be safely cast to <code>IClassFile</code>.
	 */
	public static final int CLASS_FILE = 6;

	/**
	 * Constant representing a type (a class or interface).
	 * A Java element with this type can be safely cast to <code>IType</code>.
	 */
	public static final int TYPE = 7;

	/**
	 * Constant representing a field.
	 * A Java element with this type can be safely cast to <code>IField</code>.
	 */
	public static final int FIELD = 8;

	/**
	 * Constant representing a method or constructor.
	 * A Java element with this type can be safely cast to <code>IMethod</code>.
	 */
	public static final int METHOD = 9;

	/**
	 * Constant representing a stand-alone instance or class initializer.
	 * A Java element with this type can be safely cast to <code>IInitializer</code>.
	 */
	public static final int INITIALIZER = 10;

	/**
	 * Constant representing a package declaration within a compilation unit.
	 * A Java element with this type can be safely cast to <code>IPackageDeclaration</code>.
	 */
	public static final int PACKAGE_DECLARATION = 11;

	/**
	 * Constant representing all import declarations within a compilation unit.
	 * A Java element with this type can be safely cast to <code>IImportContainer</code>.
	 */
	public static final int IMPORT_CONTAINER = 12;

	/**
	 * Constant representing an import declaration within a compilation unit.
	 * A Java element with this type can be safely cast to <code>IImportDeclaration</code>.
	 */
	public static final int IMPORT_DECLARATION = 13;

/**
 * Returns whether this Java element exists in the model.
 *
 * @return <code>true</code> if this element exists in the Java model
 */
boolean exists();
/**
 * Returns the resource that corresponds directly to this element,
 * or <code>null</code> if there is no resource that corresponds to
 * this element.
 * <p>
 * For example, the corresponding resource for an <code>ICompilationUnit</code>
 * is its underlying <code>IFile</code>. The corresponding resource for
 * an <code>IPackageFragment</code> that is not contained in an archive 
 * is its underlying <code>IFolder</code>. An <code>IPackageFragment</code>
 * contained in an archive has no corresponding resource. Similarly, there
 * are no corresponding resources for <code>IMethods</code>,
 * <code>IFields</code>, etc.
 * <p>
 *
 * @return the corresponding resource, or <code>null</code> if none
 * @exception JavaModelException if this element does not exist or if an
 *		exception occurs while accessing its corresponding resource
 */
IResource getCorrespondingResource() throws JavaModelException;
/**
 * Returns the name of this element. This is a handle-only method.
 *
 * @return the element name
 */
String getElementName();
/**
 * Returns this element's kind encoded as an integer.
 * This is a handle-only method.
 *
 * @return the kind of element; one of the constants declared in
 *   <code>IJavaElement</code>
 * @see IJavaElement
 */
public int getElementType();
/**
 * Returns a string representation of this element handle. The format of
 * the string is not specified; however, the identifier is stable across
 * workspace sessions, and can be used to recreate this handle via the 
 * <code>JavaCore.create(String)</code> method.
 *
 * @return the string handle identifier
 * @see JavaCore#create(java.lang.String)
 */
String getHandleIdentifier();
/**
 * Returns the Java model.
 * This is a handle-only method.
 *
 * @return the Java model
 */
IJavaModel getJavaModel();
/**
 * Returns the Java project this element is contained in,
 * or <code>null</code> if this element is not contained in any Java project
 * (for instance, the <code>IJavaModel</code> is not contained in any Java 
 * project).
 * This is a handle-only method.
 *
 * @return the containing Java project, or <code>null</code> if this element is
 *   not contained in a Java project
 */
IJavaProject getJavaProject();
/**
 * Returns the element directly containing this element,
 * or <code>null</code> if this element has no parent.
 * This is a handle-only method.
 *
 * @return the parent element, or <code>null</code> if this element has no parent
 */
IJavaElement getParent();
/**
 * Returns the smallest underlying resource that contains
 * this element, or <code>null</code> if this element is not contained
 * in a resource.
 *
 * @return the underlying resource, or <code>null</code> if none
 * @exception JavaModelException if this element does not exist or if an
 *		exception occurs while accessing its underlying resource
 */
IResource getUnderlyingResource() throws JavaModelException;
/**
 * Returns whether this Java element is read-only.
 * This is a handle-only method.
 *
 * @return <code>true</code> if this element is read-only
 */
boolean isReadOnly();
/**
 * Returns whether the structure of this element is known. For example, for a
 * compilation unit that could not be parsed, <code>false</code> is returned.
 * If the structure of an element is unknown, navigations will return reasonable
 * defaults. For example, <code>getChildren</code> will return an empty collection.
 * <p>
 * Note: This does not imply anything about consistency with the
 * underlying resource/buffer contents.
 * </p>
 *
 * @return <code>true</code> if the structure of this element is known
 * @exception JavaModelException if this element does not exist or if an
 *		exception occurs while accessing its corresponding resource
 */
boolean isStructureKnown() throws JavaModelException;
}

Back to the top