public abstract class JavaElement extends PlatformObject implements IJavaElement
IJavaElement| Modifier and Type | Field and Description |
|---|---|
static char |
JEM_ANNOTATION |
static char |
JEM_CLASSFILE |
static char |
JEM_COMPILATIONUNIT |
static char |
JEM_COUNT |
static char |
JEM_DELIMITER_ESCAPE
Before ')', '&' and '"' became the newest additions as delimiters, the former two
were allowed as part of element attributes and possibly stored.
|
static char |
JEM_ESCAPE |
static char |
JEM_FIELD |
static char |
JEM_IMPORTDECLARATION |
static char |
JEM_INITIALIZER |
static char |
JEM_JAVAPROJECT |
static char |
JEM_LAMBDA_EXPRESSION |
static char |
JEM_LAMBDA_METHOD |
static char |
JEM_LOCALVARIABLE |
static char |
JEM_METHOD |
static char |
JEM_PACKAGEDECLARATION |
static char |
JEM_PACKAGEFRAGMENT |
static char |
JEM_PACKAGEFRAGMENTROOT |
static char |
JEM_STRING |
static char |
JEM_TYPE |
static char |
JEM_TYPE_PARAMETER |
protected static JavaElement[] |
NO_ELEMENTS |
protected static java.lang.Object |
NO_INFO |
protected JavaElement |
parent
This element's parent, or
null if this
element does not have a parent. |
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER| Modifier | Constructor and Description |
|---|---|
protected |
JavaElement(JavaElement parent)
Constructs a handle for a java element with
the given parent element.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
appendEscapedDelimiter(java.lang.StringBuffer buffer,
char delimiter) |
void |
close() |
protected abstract void |
closing(java.lang.Object info)
This element is being closed.
|
protected abstract java.lang.Object |
createElementInfo() |
boolean |
equals(java.lang.Object o)
Returns true if this handle represents the same Java element
as the given handle.
|
protected void |
escapeMementoName(java.lang.StringBuffer buffer,
java.lang.String mementoName) |
boolean |
exists()
Returns whether this Java element exists in the model.
|
ASTNode |
findNode(CompilationUnit ast)
Returns the
ASTNode that corresponds to this JavaElement
or null if there is no corresponding node. |
protected abstract void |
generateInfos(java.lang.Object info,
java.util.HashMap newElements,
IProgressMonitor pm)
Generates the element infos for this element, its ancestors (if they are not opened) and its children (if it is an Openable).
|
IJavaElement |
getAncestor(int ancestorType)
Returns this Java element or the first ancestor of this element that has the given type.
|
java.lang.String |
getAttachedJavadoc(IProgressMonitor monitor)
Returns the Javadoc as HTML source if this element has attached Javadoc,
null otherwise. |
IJavaElement[] |
getChildren() |
java.util.ArrayList |
getChildrenOfType(int type)
Returns a collection of (immediate) children of this node of the
specified type.
|
IClassFile |
getClassFile() |
ICompilationUnit |
getCompilationUnit() |
java.lang.Object |
getElementInfo()
Returns the info for this handle.
|
java.lang.Object |
getElementInfo(IProgressMonitor monitor)
Returns the info for this handle.
|
java.lang.String |
getElementName()
Returns the name of this element.
|
IJavaElement |
getHandleFromMemento(MementoTokenizer memento,
WorkingCopyOwner owner) |
abstract IJavaElement |
getHandleFromMemento(java.lang.String token,
MementoTokenizer memento,
WorkingCopyOwner owner) |
java.lang.String |
getHandleIdentifier()
Returns a string representation of this element handle.
|
java.lang.String |
getHandleMemento() |
protected void |
getHandleMemento(java.lang.StringBuffer buff) |
protected abstract char |
getHandleMementoDelimiter()
Returns the
char that marks the start of this handles
contribution to a memento. |
protected java.net.URL |
getJavadocBaseLocation() |
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). |
protected static java.net.URL |
getLibraryJavadocLocation(IClasspathEntry entry) |
IOpenable |
getOpenable()
Returns the first openable parent.
|
IOpenable |
getOpenableParent()
Return the first instance of IOpenable in the parent
hierarchy of this element.
|
IJavaElement |
getParent()
Returns the element directly containing this element,
or
null if this element has no parent. |
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.
|
IJavaElement |
getPrimaryElement(boolean checkOwner) |
IResource |
getResource()
Returns the innermost resource enclosing this element.
|
ISchedulingRule |
getSchedulingRule()
Returns the scheduling rule associated with this Java element.
|
protected IJavaElement |
getSourceElementAt(int position)
Returns the element that is located at the given source position
in this element.
|
SourceMapper |
getSourceMapper()
Returns the SourceMapper facility for this element, or
null if this element does not have a
SourceMapper. |
protected java.lang.String |
getURLContents(java.net.URL baseLoc,
java.lang.String docUrlValue) |
boolean |
hasChildren() |
int |
hashCode()
Returns the hash code for this Java element.
|
boolean |
isAncestorOf(IJavaElement e)
Returns true if this element is an ancestor of the given element,
otherwise false.
|
boolean |
isReadOnly()
Returns whether this Java element is read-only.
|
protected JavaModelStatus |
newDoesNotExistStatus() |
JavaModelException |
newJavaModelException(IStatus status)
Creates and returns a new Java model exception for this element with the given status.
|
JavaModelException |
newNotPresentException()
Creates and returns a new not present exception for this element.
|
protected java.lang.Object |
openWhenClosed(java.lang.Object info,
boolean forceAdd,
IProgressMonitor monitor) |
java.lang.String |
readableName() |
JavaElement |
resolved(Binding binding) |
abstract IResource |
resource() |
protected java.lang.String |
tabString(int tab) |
java.lang.String |
toDebugString()
Debugging purposes
|
java.lang.String |
toString()
Debugging purposes
|
protected void |
toString(int tab,
java.lang.StringBuffer buffer)
Debugging purposes
|
protected void |
toStringAncestors(java.lang.StringBuffer buffer)
Debugging purposes
|
protected void |
toStringChildren(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info)
Debugging purposes
|
java.lang.Object |
toStringInfo(int tab,
java.lang.StringBuffer buffer)
Debugging purposes
|
protected void |
toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
Debugging purposes
|
protected void |
toStringName(java.lang.StringBuffer buffer)
Debugging purposes
|
java.lang.String |
toStringWithAncestors()
Debugging purposes
|
java.lang.String |
toStringWithAncestors(boolean showResolvedInfo)
Debugging purposes
|
JavaElement |
unresolved() |
protected void |
validateAndCache(java.net.URL baseLoc,
java.io.FileNotFoundException e) |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetCorrespondingResource, getElementType, getPath, getUnderlyingResource, isStructureKnownpublic static final char JEM_ESCAPE
public static final char JEM_JAVAPROJECT
public static final char JEM_PACKAGEFRAGMENTROOT
public static final char JEM_PACKAGEFRAGMENT
public static final char JEM_FIELD
public static final char JEM_METHOD
public static final char JEM_INITIALIZER
public static final char JEM_COMPILATIONUNIT
public static final char JEM_CLASSFILE
public static final char JEM_TYPE
public static final char JEM_PACKAGEDECLARATION
public static final char JEM_IMPORTDECLARATION
public static final char JEM_COUNT
public static final char JEM_LOCALVARIABLE
public static final char JEM_TYPE_PARAMETER
public static final char JEM_ANNOTATION
public static final char JEM_LAMBDA_EXPRESSION
public static final char JEM_LAMBDA_METHOD
public static final char JEM_STRING
public static final char JEM_DELIMITER_ESCAPE
protected JavaElement parent
null if this
element does not have a parent.protected static final JavaElement[] NO_ELEMENTS
protected static final java.lang.Object NO_INFO
protected JavaElement(JavaElement parent) throws java.lang.IllegalArgumentException
parent - The parent of java elementjava.lang.IllegalArgumentException - if the type is not one of the valid
Java element type constantspublic void close()
throws JavaModelException
JavaModelExceptionIOpenableprotected abstract void closing(java.lang.Object info)
throws JavaModelException
JavaModelExceptionprotected abstract java.lang.Object createElementInfo()
public boolean equals(java.lang.Object o)
If a subclass has other requirements for equality, this method must be overridden.
Object.equals(java.lang.Object)protected void appendEscapedDelimiter(java.lang.StringBuffer buffer,
char delimiter)
JEM_DELIMITER_ESCAPEprotected void escapeMementoName(java.lang.StringBuffer buffer,
java.lang.String mementoName)
public boolean exists()
IJavaElement
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).
exists in interface IJavaElementtrue if this element exists in the Java model, and
false if this element does not existIJavaElementpublic ASTNode findNode(CompilationUnit ast)
ASTNode that corresponds to this JavaElement
or null if there is no corresponding node.protected abstract void generateInfos(java.lang.Object info,
java.util.HashMap newElements,
IProgressMonitor pm)
throws JavaModelException
JavaModelExceptionpublic IJavaElement getAncestor(int ancestorType)
IJavaElementnull if no such element can be found.
This is a handle-only method.getAncestor in interface IJavaElementancestorType - the given typenull if no such element can be foundIJavaElementpublic IJavaElement[] getChildren() throws JavaModelException
JavaModelExceptionIParentpublic java.util.ArrayList getChildrenOfType(int type)
throws JavaModelException
type - - one of the JEM_* constants defined by JavaElementJavaModelExceptionpublic IClassFile getClassFile()
IMemberpublic ICompilationUnit getCompilationUnit()
IMemberpublic java.lang.Object getElementInfo()
throws JavaModelException
JavaModelException - if the element is not present or not accessiblepublic java.lang.Object getElementInfo(IProgressMonitor monitor)
throws JavaModelException
JavaModelException - if the element is not present or not accessiblepublic java.lang.String getElementName()
IJavaElementgetElementName in interface IJavaElementIAdaptablepublic abstract IJavaElement getHandleFromMemento(java.lang.String token, MementoTokenizer memento, WorkingCopyOwner owner)
public IJavaElement getHandleFromMemento(MementoTokenizer memento, WorkingCopyOwner owner)
public java.lang.String getHandleIdentifier()
IJavaElementJavaCore.create(String) method.getHandleIdentifier in interface IJavaElementIJavaElementpublic java.lang.String getHandleMemento()
getHandleMemento()protected void getHandleMemento(java.lang.StringBuffer buff)
protected abstract char getHandleMementoDelimiter()
char that marks the start of this handles
contribution to a memento.public IJavaModel getJavaModel()
IJavaElementgetJavaModel in interface IJavaElementIJavaElementpublic IJavaProject getJavaProject()
IJavaElementnull 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.getJavaProject in interface IJavaElementnull if this element is
not contained in a Java projectIJavaElementpublic IOpenable getOpenable()
IJavaElementnull if this element doesn't have
an openable parent.
This is a handle-only method.getOpenable in interface IJavaElementnull if this element doesn't have
an openable parent.public IOpenable getOpenableParent()
Subclasses that are not IOpenable's must override this method.
public IJavaElement getParent()
IJavaElementnull if this element has no parent.
This is a handle-only method.getParent in interface IJavaElementnull if this element has no parentIJavaElementpublic IJavaElement getPrimaryElement()
IJavaElementgetPrimaryElement in interface IJavaElementpublic IJavaElement getPrimaryElement(boolean checkOwner)
public IResource getResource()
IJavaElementnull
is returned.
This is a handle-only method.getResource in interface IJavaElementnull if this
element is included in an external archivepublic abstract IResource resource()
protected IJavaElement getSourceElementAt(int position) throws JavaModelException
ICompilationUnit#getElementAt,
and only works on compilation units and types. The position given is
known to be within this element's source range already, and if no finer
grained element is found at the position, this element is returned.JavaModelExceptionpublic SourceMapper getSourceMapper()
null if this element does not have a
SourceMapper.public ISchedulingRule getSchedulingRule()
IJavaElementgetSchedulingRule in interface IJavaElementpublic boolean hasChildren()
throws JavaModelException
JavaModelExceptionIParentpublic int hashCode()
public boolean isAncestorOf(IJavaElement e)
public boolean isReadOnly()
IJavaElementNote 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.
isReadOnly in interface IJavaElementtrue if this element is read-onlyIJavaElementpublic JavaModelException newNotPresentException()
protected JavaModelStatus newDoesNotExistStatus()
public JavaModelException newJavaModelException(IStatus status)
protected java.lang.Object openWhenClosed(java.lang.Object info,
boolean forceAdd,
IProgressMonitor monitor)
throws JavaModelException
JavaModelExceptionpublic java.lang.String readableName()
public JavaElement resolved(Binding binding)
public JavaElement unresolved()
protected java.lang.String tabString(int tab)
public java.lang.String toDebugString()
public java.lang.String toString()
protected void toString(int tab,
java.lang.StringBuffer buffer)
public java.lang.String toStringWithAncestors()
public java.lang.String toStringWithAncestors(boolean showResolvedInfo)
protected void toStringAncestors(java.lang.StringBuffer buffer)
protected void toStringChildren(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info)
public java.lang.Object toStringInfo(int tab,
java.lang.StringBuffer buffer)
protected void toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
showResolvedInfo - TODOprotected void toStringName(java.lang.StringBuffer buffer)
protected java.net.URL getJavadocBaseLocation()
throws JavaModelException
JavaModelExceptionprotected static java.net.URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException
JavaModelExceptionpublic java.lang.String getAttachedJavadoc(IProgressMonitor monitor)
throws JavaModelException
IJavaElementReturns the Javadoc as HTML source if this element has 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 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.
getAttachedJavadoc in interface IJavaElementmonitor - the given progress monitor, can be nullnull if noneJavaModelException - if:IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAMEprotected void validateAndCache(java.net.URL baseLoc,
java.io.FileNotFoundException e)
throws JavaModelException
JavaModelExceptionprotected java.lang.String getURLContents(java.net.URL baseLoc,
java.lang.String docUrlValue)
throws JavaModelException
JavaModelException