|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IJavaElement
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.
Methods annotated as "handle-only" do not require underlying elements to exist.
Methods that require underlying elements to exist throw
a JavaModelException
when an underlying element is missing.
JavaModelException.isDoesNotExist
can be used to recognize
this common special case.
Field Summary | |
---|---|
static int |
ANNOTATION
Constant representing an annotation. |
static int |
CLASS_FILE
Constant representing a class file. |
static int |
COMPILATION_UNIT
Constant representing a Java compilation unit. |
static int |
FIELD
Constant representing a field. |
static int |
IMPORT_CONTAINER
Constant representing all import declarations within a compilation unit. |
static int |
IMPORT_DECLARATION
Constant representing an import declaration within a compilation unit. |
static int |
INITIALIZER
Constant representing a stand-alone instance or class initializer. |
static int |
JAVA_MODEL
Constant representing a Java model (workspace level object). |
static int |
JAVA_PROJECT
Constant representing a Java project. |
static int |
LOCAL_VARIABLE
Constant representing a local variable declaration. |
static int |
METHOD
Constant representing a method or constructor. |
static int |
PACKAGE_DECLARATION
Constant representing a package declaration within a compilation unit. |
static int |
PACKAGE_FRAGMENT
Constant representing a package fragment. |
static int |
PACKAGE_FRAGMENT_ROOT
Constant representing a package fragment root. |
static int |
TYPE
Constant representing a type (a class or interface). |
static int |
TYPE_PARAMETER
Constant representing a type parameter declaration. |
Method Summary | |
---|---|
boolean |
exists()
Returns whether this Java element exists in the model. |
IJavaElement |
getAncestor(int ancestorType)
Returns the first ancestor of this Java element that has the given type. |
java.lang.String |
getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor)
Returns the Javadoc as an html source if this element has an attached javadoc, null otherwise. |
IResource |
getCorrespondingResource()
Returns the resource that corresponds directly to this element, or null if there is no resource that corresponds to
this element. |
java.lang.String |
getElementName()
Returns the name of this element. |
int |
getElementType()
Returns this element's kind encoded as an integer. |
java.lang.String |
getHandleIdentifier()
Returns a string representation of this element handle. |
IJavaModel |
getJavaModel()
Returns the Java model. |
IJavaProject |
getJavaProject()
Returns the Java project this element is contained in, or null if this element is not contained in any Java project
(for instance, the IJavaModel is not contained in any Java
project). |
IOpenable |
getOpenable()
Returns the first openable parent. |
IJavaElement |
getParent()
Returns the element directly containing this element, or null if this element has no parent. |
org.eclipse.core.runtime.IPath |
getPath()
Returns the path to the innermost resource enclosing this element. |
IJavaElement |
getPrimaryElement()
Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g. |
IResource |
getResource()
Returns the innermost resource enclosing this element. |
org.eclipse.core.runtime.jobs.ISchedulingRule |
getSchedulingRule()
Returns the scheduling rule associated with this Java element. |
IResource |
getUnderlyingResource()
Returns the smallest underlying resource that contains this element, or null if this element is not contained
in a resource. |
boolean |
isReadOnly()
Returns whether this Java element is read-only. |
boolean |
isStructureKnown()
Returns whether the structure of this element is known. |
Methods inherited from interface org.eclipse.core.runtime.IAdaptable |
---|
getAdapter |
Field Detail |
---|
static final int JAVA_MODEL
IJavaModel
.
static final int JAVA_PROJECT
IJavaProject
.
static final int PACKAGE_FRAGMENT_ROOT
IPackageFragmentRoot
.
static final int PACKAGE_FRAGMENT
IPackageFragment
.
static final int COMPILATION_UNIT
ICompilationUnit
.
static final int CLASS_FILE
IClassFile
.
static final int TYPE
IType
.
static final int FIELD
IField
.
static final int METHOD
IMethod
.
static final int INITIALIZER
IInitializer
.
static final int PACKAGE_DECLARATION
IPackageDeclaration
.
static final int IMPORT_CONTAINER
IImportContainer
.
static final int IMPORT_DECLARATION
IImportDeclaration
.
static final int LOCAL_VARIABLE
ILocalVariable
.
static final int TYPE_PARAMETER
ITypeParameter
.
static final int ANNOTATION
IAnnotation
.
Method Detail |
---|
boolean exists()
Java elements are handle objects that may or may not be backed by an
actual element. Java elements that are backed by an actual element are
said to "exist", and this method returns true
. For Java
elements that are not working copies, it is always the case that if the
element exists, then its parent also exists (provided it has one) and
includes the element as one of its children. It is therefore possible
to navigated to any existing Java element from the root of the Java model
along a chain of existing Java elements. On the other hand, working
copies are said to exist until they are destroyed (with
IWorkingCopy.destroy
). Unlike regular Java elements, a
working copy never shows up among the children of its parent element
(which may or may not exist).
true
if this element exists in the Java model, and
false
if this element does not existIJavaElement getAncestor(int ancestorType)
null
if no such an ancestor can be found.
This is a handle-only method.
ancestorType
- the given type
java.lang.String getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
Returns the Javadoc as an html source if this element has an attached javadoc, null otherwise.
This should be used only for binary elements. Source elements will always return null.
The encoding used to read the javadoc is the one defined by the content type of the file. If none is defined, then the project's encoding of this java element is used. If the project's encoding cannot be retrieved, then the platform encoding is used.
In case of the javadoc doesn't exist for this element, null is returned.
The html is extracted from the attached javadoc and provided as is. No transformation or validation is done.
monitor
- the given progress monitor
JavaModelException
- if:IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME
IResource getCorrespondingResource() throws JavaModelException
null
if there is no resource that corresponds to
this element.
For example, the corresponding resource for an ICompilationUnit
is its underlying IFile
. The corresponding resource for
an IPackageFragment
that is not contained in an archive
is its underlying IFolder
. An IPackageFragment
contained in an archive has no corresponding resource. Similarly, there
are no corresponding resources for IMethods
,
IFields
, etc.
null
if none
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resourcejava.lang.String getElementName()
int getElementType()
IJavaElement
IJavaElement
java.lang.String getHandleIdentifier()
JavaCore.create(String)
method.
JavaCore.create(java.lang.String)
IJavaModel getJavaModel()
IJavaProject getJavaProject()
null
if this element is not contained in any Java project
(for instance, the IJavaModel
is not contained in any Java
project).
This is a handle-only method.
null
if this element is
not contained in a Java projectIOpenable getOpenable()
null
if this element doesn't have
an openable parent.
This is a handle-only method.
null
if this element doesn't have
an openable parent.IJavaElement getParent()
null
if this element has no parent.
This is a handle-only method.
null
if this element has no parentorg.eclipse.core.runtime.IPath getPath()
IJavaElement getPrimaryElement()
IResource getResource()
null
is returned.
This is a handle-only method.
null
if this
element is included in an external archiveorg.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()
IResource getUnderlyingResource() throws JavaModelException
null
if this element is not contained
in a resource.
null
if none
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its underlying resourceboolean isReadOnly()
Note this is different from IResource.isReadOnly(). For example, .jar files are read-only as the java model doesn't know how to add/remove elements in this file, but the underlying IFile can be writable.
This is a handle-only method.
true
if this element is read-onlyboolean isStructureKnown() throws JavaModelException
false
is returned.
If the structure of an element is unknown, navigations will return reasonable
defaults. For example, getChildren
for a compilation unit with
syntax errors will return a collection of the children that could be parsed.
Note: This does not imply anything about consistency with the underlying resource/buffer contents.
true
if the structure of this element is known
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |