Class JavaElement
- All Implemented Interfaces:
IJavaElement,org.eclipse.core.runtime.IAdaptable
- Direct Known Subclasses:
Openable,SourceRefElement
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charstatic final charstatic final charstatic final charstatic final charBefore ')','&'and '"' became the newest additions as delimiters, the former two were allowed as part of element attributes and possibly stored.static final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charprotected static final JavaElement[]protected static final Objectstatic 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
ConstructorsModifierConstructorDescriptionprotectedJavaElement(JavaElement parent) Constructs a handle for a java element with the given parent element. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendEscapedDelimiter(StringBuilder buffer, char delimiter) protected intvoidclose()protected abstract voidThis element is being closed.protected abstract JavaElementInfobooleanReturns true if this handle represents the same Java element as the given handle.protected voidescapeMementoName(StringBuilder buffer, String mementoName) booleanexists()Returns whether this Java element exists in the model.findNode(CompilationUnit ast) Returns theASTNodethat corresponds to thisJavaElementornullif there is no corresponding node.protected abstract voidgenerateInfos(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,nullotherwise.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 IJavaElementgetHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) getHandleFromMemento(MementoTokenizer memento, WorkingCopyOwner owner) Returns a string representation of this element handle.protected voidprotected abstract charReturns thecharthat marks the start of this handles contribution to a memento.protected URLReturns the Java model.Returns the Java project this element is contained in, ornullif this element is not contained in any Java project (for instance, theIJavaModelis not contained in any Java project).protected static URLReturns the first openable parent.Return the first instance of IOpenable in the parent hierarchy of this element.Returns the element directly containing this element, ornullif 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.IResourceReturns the innermost resource enclosing this element.org.eclipse.core.runtime.jobs.ISchedulingRuleReturns the scheduling rule associated with this Java element.protected IJavaElementgetSourceElementAt(int position) Returns the element that is located at the given source position in this element.Returns the SourceMapper facility for this element, ornullif this element does not have a SourceMapper.protected StringgetURLContents(URL baseLoc, String docUrlValue) booleanfinal inthashCode()Returns the hash code for this Java element.booleanReturns true if this element is an ancestor of the given element, otherwise false.booleanReturns whether this Java element is read-only.protected JavaModelStatusnewJavaModelException(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 IElementInfoopenWhenClosed(IElementInfo info, boolean forceAdd, org.eclipse.core.runtime.IProgressMonitor monitor) protected voidshould not be needed but some implementations do have mutable member "occurrenceCount"abstract org.eclipse.core.resources.IResourceresource()protected StringtabString(int tab) Debugging purposestoString()Debugging purposesprotected voidtoString(int tab, StringBuilder buffer) Debugging purposesprotected voidtoStringAncestors(StringBuilder buffer) Debugging purposesprotected voidtoStringChildren(int tab, StringBuilder buffer, Object info) Debugging purposestoStringInfo(int tab, StringBuilder buffer) Debugging purposesprotected voidtoStringInfo(int tab, StringBuilder buffer, Object info, boolean showResolvedInfo) Debugging purposesprotected voidtoStringName(StringBuilder buffer) Debugging purposesDebugging purposestoStringWithAncestors(boolean showResolvedInfo) Debugging purposesprotected voidvalidateAndCache(URL baseLoc, FileNotFoundException e) Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapterMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapterMethods 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 ')','&'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:IJavaElementReturns 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:
existsin interfaceIJavaElement- Returns:
trueif this element exists in the Java model, andfalseif this element does not exist- See Also:
-
findNode
Returns theASTNodethat corresponds to thisJavaElementornullif 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:IJavaElementReturns this Java element or the first ancestor of this element that has the given type. Returnsnullif no such element can be found. This is a handle-only method.- Specified by:
getAncestorin interfaceIJavaElement- Parameters:
ancestorType- the given type- Returns:
- this Java element or the first ancestor of this element that has the given type, or
nullif 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:IJavaElementReturns the name of this element. This is a handle-only method.- Specified by:
getElementNamein interfaceIJavaElement- Returns:
- the element name
- See Also:
-
getHandleFromMemento
public abstract IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) -
getHandleFromMemento
-
getHandleIdentifier
Description copied from interface:IJavaElementReturns 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:
getHandleIdentifierin interfaceIJavaElement- Returns:
- the string handle identifier
- See Also:
-
getHandleMemento
- See Also:
-
getHandleMemento
-
getHandleMementoDelimiter
protected abstract char getHandleMementoDelimiter()Returns thecharthat marks the start of this handles contribution to a memento. -
getJavaModel
Description copied from interface:IJavaElementReturns the Java model. This is a handle-only method.- Specified by:
getJavaModelin interfaceIJavaElement- Returns:
- the Java model
- See Also:
-
getJavaProject
Description copied from interface:IJavaElementReturns the Java project this element is contained in, ornullif this element is not contained in any Java project (for instance, theIJavaModelis not contained in any Java project). This is a handle-only method.- Specified by:
getJavaProjectin interfaceIJavaElement- Returns:
- the containing Java project, or
nullif this element is not contained in a Java project - See Also:
-
getOpenable
Description copied from interface:IJavaElementReturns the first openable parent. If this element is openable, the element itself is returned. Returnsnullif this element doesn't have an openable parent. This is a handle-only method.- Specified by:
getOpenablein interfaceIJavaElement- Returns:
- the first openable parent or
nullif 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:IJavaElementReturns the element directly containing this element, ornullif this element has no parent. This is a handle-only method.- Specified by:
getParentin interfaceIJavaElement- Returns:
- the parent element, or
nullif this element has no parent - See Also:
-
getPrimaryElement
Description copied from interface:IJavaElementReturns 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:
getPrimaryElementin 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:IJavaElementReturns 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,nullis returned. This is a handle-only method.- Specified by:
getResourcein interfaceIJavaElement- Returns:
- the innermost resource enclosing this element,
nullif 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, ornullif this element does not have a SourceMapper. -
getSchedulingRule
public org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()Description copied from interface:IJavaElementReturns the scheduling rule associated with this Java element. This is a handle-only method.- Specified by:
getSchedulingRulein 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:IJavaElementReturns 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:
isReadOnlyin interfaceIJavaElement- Returns:
trueif 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
-
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:IJavaElementReturns the Javadoc as HTML source if this element has attached Javadoc,
nullotherwise.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,
nullis returned.The HTML is extracted from the attached Javadoc and provided as is. No transformation or validation is done.
- Specified by:
getAttachedJavadocin interfaceIJavaElement- Parameters:
monitor- the given progress monitor, can benull- Returns:
- the extracted javadoc from the attached javadoc,
nullif 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
-