Class JavaElement
- All Implemented Interfaces:
IJavaElement
,org.eclipse.core.runtime.IAdaptable
- Direct Known Subclasses:
Openable
,SourceRefElement
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final char
static final char
static final char
static final char
static final char
Before ')', 'invalid input: '&'' and '"' became the newest additions as delimiters, the former two were allowed as part of element attributes and possibly stored.static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
static final char
protected static final JavaElement[]
protected static final Object
protected static final String[]
Fields inherited from interface org.aspectj.org.eclipse.jdt.core.IJavaElement
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_MODULE, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER
-
Constructor Summary
ModifierConstructorDescriptionprotected
JavaElement
(JavaElement parent) Constructs a handle for a java element with the given parent element. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
appendEscapedDelimiter
(StringBuilder buffer, char delimiter) protected int
void
close()
protected abstract void
This element is being closed.protected abstract JavaElementInfo
boolean
Returns true if this handle represents the same Java element as the given handle.protected void
escapeMementoName
(StringBuilder buffer, String mementoName) boolean
exists()
Returns whether this Java element exists in the model.findNode
(CompilationUnit ast) Returns theASTNode
that corresponds to thisJavaElement
ornull
if there is no corresponding node.protected abstract void
generateInfos
(IElementInfo info, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor pm) Generates the element infos for this element, its ancestors (if they are not opened) and its children (if it is an Openable).getAncestor
(int ancestorType) Returns this Java element or the first ancestor of this element that has the given type.getAttachedJavadoc
(org.eclipse.core.runtime.IProgressMonitor monitor) Returns the Javadoc as HTML source if this element has attached Javadoc,null
otherwise.getChildrenOfType
(int type) Returns a collection of (immediate) children of this node of the specified type.Returns the info for this handle.getElementInfo
(org.eclipse.core.runtime.IProgressMonitor monitor) Returns the info for this handle.Returns the name of this element.abstract IJavaElement
getHandleFromMemento
(String token, MementoTokenizer memento, WorkingCopyOwner owner) getHandleFromMemento
(MementoTokenizer memento, WorkingCopyOwner owner) Returns a string representation of this element handle.protected void
protected abstract char
Returns thechar
that marks the start of this handles contribution to a memento.protected URL
Returns the Java model.Returns the Java project this element is contained in, ornull
if this element is not contained in any Java project (for instance, theIJavaModel
is not contained in any Java project).protected static URL
Returns the first openable parent.Return the first instance of IOpenable in the parent hierarchy of this element.Returns the element directly containing this element, ornull
if this element has no parent.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.getPrimaryElement
(boolean checkOwner) org.eclipse.core.resources.IResource
Returns the innermost resource enclosing this element.org.eclipse.core.runtime.jobs.ISchedulingRule
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.Returns the SourceMapper facility for this element, ornull
if this element does not have a SourceMapper.protected String
getURLContents
(URL baseLoc, String docUrlValue) boolean
final int
hashCode()
Returns the hash code for this Java element.boolean
Returns true if this element is an ancestor of the given element, otherwise false.boolean
Returns whether this Java element is read-only.protected JavaModelStatus
newJavaModelException
(org.eclipse.core.runtime.IStatus status) Creates and returns a new Java model exception for this element with the given status.Creates and returns a new not present exception for this element.protected IElementInfo
openWhenClosed
(IElementInfo info, boolean forceAdd, org.eclipse.core.runtime.IProgressMonitor monitor) protected void
should not be needed but some implementations do have mutable member "occurrenceCount"abstract org.eclipse.core.resources.IResource
resource()
protected String
tabString
(int tab) Debugging purposestoString()
Debugging purposesprotected void
toString
(int tab, StringBuilder buffer) Debugging purposesprotected void
toStringAncestors
(StringBuilder buffer) Debugging purposesprotected void
toStringChildren
(int tab, StringBuilder buffer, Object info) Debugging purposestoStringInfo
(int tab, StringBuilder buffer) Debugging purposesprotected void
toStringInfo
(int tab, StringBuilder buffer, Object info, boolean showResolvedInfo) Debugging purposesprotected void
toStringName
(StringBuilder buffer) Debugging purposesDebugging purposestoStringWithAncestors
(boolean showResolvedInfo) Debugging purposesprotected void
validateAndCache
(URL baseLoc, FileNotFoundException e) Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IJavaElement
getCorrespondingResource, getElementType, getPath, getUnderlyingResource, isStructureKnown
-
Field Details
-
JEM_ESCAPE
public static final char JEM_ESCAPE- See Also:
-
JEM_JAVAPROJECT
public static final char JEM_JAVAPROJECT- See Also:
-
JEM_PACKAGEFRAGMENTROOT
public static final char JEM_PACKAGEFRAGMENTROOT- See Also:
-
JEM_PACKAGEFRAGMENT
public static final char JEM_PACKAGEFRAGMENT- See Also:
-
JEM_FIELD
public static final char JEM_FIELD- See Also:
-
JEM_METHOD
public static final char JEM_METHOD- See Also:
-
JEM_INITIALIZER
public static final char JEM_INITIALIZER- See Also:
-
JEM_COMPILATIONUNIT
public static final char JEM_COMPILATIONUNIT- See Also:
-
JEM_CLASSFILE
public static final char JEM_CLASSFILE- See Also:
-
JEM_MODULAR_CLASSFILE
public static final char JEM_MODULAR_CLASSFILE- See Also:
-
JEM_TYPE
public static final char JEM_TYPE- See Also:
-
JEM_PACKAGEDECLARATION
public static final char JEM_PACKAGEDECLARATION- See Also:
-
JEM_IMPORTDECLARATION
public static final char JEM_IMPORTDECLARATION- See Also:
-
JEM_COUNT
public static final char JEM_COUNT- See Also:
-
JEM_LOCALVARIABLE
public static final char JEM_LOCALVARIABLE- See Also:
-
JEM_TYPE_PARAMETER
public static final char JEM_TYPE_PARAMETER- See Also:
-
JEM_ANNOTATION
public static final char JEM_ANNOTATION- See Also:
-
JEM_LAMBDA_EXPRESSION
public static final char JEM_LAMBDA_EXPRESSION- See Also:
-
JEM_LAMBDA_METHOD
public static final char JEM_LAMBDA_METHOD- See Also:
-
JEM_STRING
public static final char JEM_STRING- See Also:
-
JEM_MODULE
public static final char JEM_MODULE- See Also:
-
JEM_DELIMITER_ESCAPE
public static final char JEM_DELIMITER_ESCAPEBefore ')', 'invalid input: '&'' and '"' became the newest additions as delimiters, the former two were allowed as part of element attributes and possibly stored. Trying to recreate elements from such memento would cause undesirable results. Consider the following valid project name: (abc) If we were to use ')' alone as the delimiter and decode the above name, the memento would be wrongly identified to contain a lambda expression. In order to differentiate delimiters from characters that are part of element attributes, the following escape character is being introduced and all the new delimiters must be escaped with this. So, a lambda expression would be written as: "=)..."- See Also:
-
NO_STRINGS
-
NO_ELEMENTS
-
NO_INFO
-
-
Constructor Details
-
JavaElement
Constructs a handle for a java element with the given parent element.- Parameters:
parent
- The parent of java element- Throws:
IllegalArgumentException
- if the type is not one of the valid Java element type constants
-
-
Method Details
-
close
- Throws:
JavaModelException
- See Also:
-
closing
This element is being closed. Do any necessary cleanup.- Throws:
JavaModelException
-
createElementInfo
-
equals
Returns true if this handle represents the same Java element as the given handle. By default, two handles represent the same element if they are identical or if they represent the same type of element, have equal names, parents, and occurrence counts.If a subclass has other requirements for equality, this method must be overridden.
-
appendEscapedDelimiter
- See Also:
-
escapeMementoName
-
exists
public boolean exists()Description copied from interface:IJavaElement
Returns whether this Java element exists in the model.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 (withIWorkingCopy.destroy
). Unlike regular Java elements, a working copy never shows up among the children of its parent element (which may or may not exist).- Specified by:
exists
in interfaceIJavaElement
- Returns:
true
if this element exists in the Java model, andfalse
if this element does not exist- See Also:
-
findNode
Returns theASTNode
that corresponds to thisJavaElement
ornull
if there is no corresponding node. -
generateInfos
protected abstract void generateInfos(IElementInfo info, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor pm) throws JavaModelExceptionGenerates the element infos for this element, its ancestors (if they are not opened) and its children (if it is an Openable). Puts the newly created element info in the given map.- Throws:
JavaModelException
-
getAncestor
Description copied from interface:IJavaElement
Returns this Java element or the first ancestor of this element that has the given type. Returnsnull
if no such element can be found. This is a handle-only method.- Specified by:
getAncestor
in interfaceIJavaElement
- Parameters:
ancestorType
- the given type- Returns:
- this Java element or the first ancestor of this element that has the given type, or
null
if no such element can be found - See Also:
-
getChildren
- Throws:
JavaModelException
- See Also:
-
getChildrenOfType
Returns a collection of (immediate) children of this node of the specified type.- Parameters:
type
- - one of the JEM_* constants defined by JavaElement- Throws:
JavaModelException
-
getClassFile
- See Also:
-
getCompilationUnit
- See Also:
-
getElementInfo
Returns the info for this handle. If this element is not already open, it and all of its parents are opened. Does not return null. NOTE: BinaryType infos are NOT rooted under JavaElementInfo.- Throws:
JavaModelException
- if the element is not present or not accessible
-
getElementInfo
public IElementInfo getElementInfo(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Returns the info for this handle. If this element is not already open, it and all of its parents are opened. Does not return null. NOTE: BinaryType infos are NOT rooted under JavaElementInfo.- Throws:
JavaModelException
- if the element is not present or not accessible
-
getElementName
Description copied from interface:IJavaElement
Returns the name of this element. This is a handle-only method.- Specified by:
getElementName
in interfaceIJavaElement
- Returns:
- the element name
- See Also:
-
getHandleFromMemento
public abstract IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) -
getHandleFromMemento
-
getHandleIdentifier
Description copied from interface:IJavaElement
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 theJavaCore.create(String)
method.- Specified by:
getHandleIdentifier
in interfaceIJavaElement
- Returns:
- the string handle identifier
- See Also:
-
getHandleMemento
- See Also:
-
getHandleMemento
-
getHandleMementoDelimiter
protected abstract char getHandleMementoDelimiter()Returns thechar
that marks the start of this handles contribution to a memento. -
getJavaModel
Description copied from interface:IJavaElement
Returns the Java model. This is a handle-only method.- Specified by:
getJavaModel
in interfaceIJavaElement
- Returns:
- the Java model
- See Also:
-
getJavaProject
Description copied from interface:IJavaElement
Returns the Java project this element is contained in, ornull
if this element is not contained in any Java project (for instance, theIJavaModel
is not contained in any Java project). This is a handle-only method.- Specified by:
getJavaProject
in interfaceIJavaElement
- Returns:
- the containing Java project, or
null
if this element is not contained in a Java project - See Also:
-
getOpenable
Description copied from interface:IJavaElement
Returns the first openable parent. If this element is openable, the element itself is returned. Returnsnull
if this element doesn't have an openable parent. This is a handle-only method.- Specified by:
getOpenable
in interfaceIJavaElement
- Returns:
- the first openable parent or
null
if this element doesn't have an openable parent.
-
getOpenableParent
Return the first instance of IOpenable in the parent hierarchy of this element.Subclasses that are not IOpenable's must override this method.
-
getParent
Description copied from interface:IJavaElement
Returns the element directly containing this element, ornull
if this element has no parent. This is a handle-only method.- Specified by:
getParent
in interfaceIJavaElement
- Returns:
- the parent element, or
null
if this element has no parent - See Also:
-
getPrimaryElement
Description copied from interface:IJavaElement
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. it is a binary member). The returned element may or may not exist.- Specified by:
getPrimaryElement
in interfaceIJavaElement
- Returns:
- the primary element this working copy element was created from, or this element.
-
getPrimaryElement
-
getResource
public org.eclipse.core.resources.IResource getResource()Description copied from interface:IJavaElement
Returns the innermost resource enclosing this element. If this element is included in an archive and this archive is not external, this is the underlying resource corresponding to the archive. If this element is included in an external library,null
is returned. This is a handle-only method.- Specified by:
getResource
in interfaceIJavaElement
- Returns:
- the innermost resource enclosing this element,
null
if this element is included in an external archive
-
resource
public abstract org.eclipse.core.resources.IResource resource() -
getSourceElementAt
Returns the element that is located at the given source position in this element. This is a helper method forICompilationUnit#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.- Throws:
JavaModelException
-
getSourceMapper
Returns the SourceMapper facility for this element, ornull
if this element does not have a SourceMapper. -
getSchedulingRule
public org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()Description copied from interface:IJavaElement
Returns the scheduling rule associated with this Java element. This is a handle-only method.- Specified by:
getSchedulingRule
in interfaceIJavaElement
- Returns:
- the scheduling rule associated with this Java element
-
hasChildren
- Throws:
JavaModelException
- See Also:
-
hashCode
public final int hashCode()Returns the hash code for this Java element. By default, the hash code for an element is a combination of its thisgetElementName()
and parent's hash code. Elements with other requirements must override thiscalculateHashCode()
. -
resetHashCode
protected void resetHashCode()should not be needed but some implementations do have mutable member "occurrenceCount" -
calculateHashCode
protected int calculateHashCode() -
isAncestorOf
Returns true if this element is an ancestor of the given element, otherwise false. -
isReadOnly
public boolean isReadOnly()Description copied from interface:IJavaElement
Returns whether this Java element is read-only. An element is read-only if its structure cannot be modified by the java model.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.
- Specified by:
isReadOnly
in interfaceIJavaElement
- Returns:
true
if this element is read-only- See Also:
-
newNotPresentException
Creates and returns a new not present exception for this element. -
newDoesNotExistStatus
-
newJavaModelException
Creates and returns a new Java model exception for this element with the given status. -
openWhenClosed
protected IElementInfo openWhenClosed(IElementInfo info, boolean forceAdd, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException - Throws:
JavaModelException
-
readableName
-
resolved
-
unresolved
-
tabString
-
toDebugString
Debugging purposes -
toString
Debugging purposes -
toString
Debugging purposes -
toStringWithAncestors
Debugging purposes -
toStringWithAncestors
Debugging purposes -
toStringAncestors
Debugging purposes -
toStringChildren
Debugging purposes -
toStringInfo
Debugging purposes -
toStringInfo
Debugging purposes- Parameters:
showResolvedInfo
- TODO
-
toStringName
Debugging purposes -
getJavadocBaseLocation
- Throws:
JavaModelException
-
getLibraryJavadocLocation
- Throws:
JavaModelException
-
getAttachedJavadoc
public String getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Description copied from interface:IJavaElement
Returns 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.
- Specified by:
getAttachedJavadoc
in interfaceIJavaElement
- Parameters:
monitor
- the given progress monitor, can benull
- Returns:
- the extracted javadoc from the attached javadoc,
null
if none - Throws:
JavaModelException
- if:- this element does not exist
- retrieving the attached javadoc fails (timed-out, invalid URL, ...)
- the format of the javadoc doesn't match expected standards (different anchors,...)
- See Also:
-
validateAndCache
- Throws:
JavaModelException
-
getURLContents
- Throws:
JavaModelException
-