Class Openable
- All Implemented Interfaces:
IBufferChangedListener, IJavaElement, IOpenable, org.eclipse.core.runtime.IAdaptable
- Direct Known Subclasses:
AbstractClassFile, CompilationUnit, JavaModel, JavaProject, PackageFragment, PackageFragmentRoot
- See Also:
-
Field Summary
Fields inherited from class JavaElement
JEM_ANNOTATION, JEM_CLASSFILE, JEM_COMPILATIONUNIT, JEM_COUNT, JEM_DELIMITER_ESCAPE, JEM_ESCAPE, JEM_FIELD, JEM_IMPORTDECLARATION, JEM_INITIALIZER, JEM_JAVAPROJECT, JEM_LAMBDA_EXPRESSION, JEM_LAMBDA_METHOD, JEM_LOCALVARIABLE, JEM_METHOD, JEM_MODULAR_CLASSFILE, JEM_MODULE, JEM_PACKAGEDECLARATION, JEM_PACKAGEFRAGMENT, JEM_PACKAGEFRAGMENTROOT, JEM_STRING, JEM_TYPE, JEM_TYPE_PARAMETER, NO_ELEMENTS, NO_INFO, NO_STRINGSModifier 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 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_PARAMETERModifier and TypeFieldDescriptionstatic final intConstant representing an annotation.static final intConstant representing a class file.static final intConstant representing a Java compilation unit.static final intConstant representing a field.static final intConstant representing all import declarations within a compilation unit.static final intConstant representing an import declaration within a compilation unit.static final intConstant representing a stand-alone instance or class initializer.static final intConstant representing a Java model (workspace level object).static final intConstant represents a module descriptor.static final intConstant representing a Java project.static final intConstant representing a local variable declaration.static final intConstant representing a method or constructor.static final intConstant representing a package declaration within a compilation unit.static final intConstant representing a package fragment.static final intConstant representing a package fragment root.static final intConstant representing a type (a class or interface).static final intConstant representing a type parameter declaration. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbufferChanged(BufferChangedEvent event) The buffer associated with this element has changed.protected abstract booleanbuildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.resources.IResource underlyingResource) Builds this element's structure and properties in the given info object, based on this element's current contents (reuse buffer contents if this element has an open buffer, or resource contents if this element does not have an open buffer).booleanbooleancanBufferBeRemovedFromCache(IBuffer buffer) protected voidClose the buffer associated with this element, if any.protected voidThis element is being closed.protected voidcodeComplete(ICompilationUnit cu, ICompilationUnit unitToSkip, int position, CompletionRequestor requestor, WorkingCopyOwner owner, ITypeRoot typeRoot, org.eclipse.core.runtime.IProgressMonitor monitor) protected IJavaElement[]codeSelect(ICompilationUnit cu, int offset, int length, WorkingCopyOwner owner) protected OpenableElementInfobooleanexists()Returns whether this Java element exists in the model.Finds and returns the recommended line separator for this element.protected voidgenerateInfos(IElementInfo info, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor monitor) Generates the element infos for this element, its ancestors (if they are not opened) and its children (if it is an Openable).Note: a buffer with no unsaved changes can be closed by the Java Model since it has a finite number of buffers allowed open at one time.Deprecated.protected BufferManagerReturns the buffer manager for this element.org.eclipse.core.resources.IResourceReturn my underlying resource.Returns the first openable parent.Find enclosing package fragment root if anyorg.eclipse.core.resources.IResourceReturns the innermost resource enclosing this element.org.eclipse.core.resources.IResourceReturns the smallest underlying resource that contains this element, ornullif this element is not contained in a resource.protected booleanReturns true if this element may have an associated source buffer, otherwise false.booleanReturnstrueif this element is open and: its buffer has unsaved changes, or one of its descendants has unsaved changes, or a working copy has been created on one of this element's children and has not yet destroyedprotected booleanignoreErrorStatus(org.eclipse.core.runtime.IStatus status) booleanSubclasses must override as required.booleanisOpen()Returns whether this openable is open.protected booleanReturns true if this represents a source element.booleanReturns whether the structure of this element is known.voidmakeConsistent(org.eclipse.core.runtime.IProgressMonitor monitor) Makes this element consistent with its underlying resource or buffer by updating the element's structure and properties as necessary.voidopen(org.eclipse.core.runtime.IProgressMonitor pm) Opens this element and all parent elements that are not already open.protected voidopenAncestors(Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor monitor) protected IBufferopenBuffer(org.eclipse.core.runtime.IProgressMonitor pm, IElementInfo info) Opens a buffer on the contents of this element, and returns the buffer, or returnsnullif opening fails.org.eclipse.core.resources.IResourceresource()protected abstract org.eclipse.core.resources.IResourceresource(PackageFragmentRoot root) protected booleanresourceExists(org.eclipse.core.resources.IResource underlyingResource) Returns whether the corresponding resource or associated file existsvoidsave(org.eclipse.core.runtime.IProgressMonitor pm, boolean force) Saves any changes in this element's buffer to its underlying resource via a workspace resource operation.protected abstract org.eclipse.core.runtime.IStatusvalidateExistence(org.eclipse.core.resources.IResource underlyingResource) Methods inherited from class JavaElement
appendEscapedDelimiter, calculateHashCode, close, equals, escapeMementoName, findNode, getAncestor, getAttachedJavadoc, getChildren, getChildrenOfType, getClassFile, getCompilationUnit, getElementInfo, getElementInfo, getElementName, getHandleFromMemento, getHandleFromMemento, getHandleIdentifier, getHandleMemento, getHandleMemento, getHandleMementoDelimiter, getJavadocBaseLocation, getJavaModel, getJavaProject, getLibraryJavadocLocation, getOpenableParent, getParent, getPrimaryElement, getPrimaryElement, getSchedulingRule, getSourceElementAt, getSourceMapper, getURLContents, hasChildren, hashCode, isAncestorOf, isReadOnly, newDoesNotExistStatus, newJavaModelException, newNotPresentException, openWhenClosed, readableName, resetHashCode, resolved, tabString, toDebugString, toString, toString, toStringAncestors, toStringChildren, toStringInfo, toStringInfo, toStringName, toStringWithAncestors, toStringWithAncestors, unresolved, validateAndCacheModifier and TypeMethodDescriptionprotected voidappendEscapedDelimiter(StringBuilder buffer, char delimiter) protected intvoidclose()booleanReturns true if this handle represents the same Java element as the given handle.protected voidescapeMementoName(StringBuilder buffer, String mementoName) findNode(CompilationUnit ast) Returns theASTNodethat corresponds to thisJavaElementornullif there is no corresponding node.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 URLReturn 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.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"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 interface IJavaElement
getElementType, getPathModifier and TypeMethodDescriptionintReturns this element's kind encoded as an integer.org.eclipse.core.runtime.IPathgetPath()Returns the path to the innermost resource enclosing this element.
-
Constructor Details
-
Openable
-
-
Method Details
-
bufferChanged
The buffer associated with this element has changed. Registers this element as being out of synch with its buffer's contents. If the buffer has been closed, this element is set as NOT out of synch with the contents.- Specified by:
bufferChangedin interfaceIBufferChangedListener- Parameters:
event- the change event- See Also:
-
buildStructure
protected abstract boolean buildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.resources.IResource underlyingResource) throws JavaModelException Builds this element's structure and properties in the given info object, based on this element's current contents (reuse buffer contents if this element has an open buffer, or resource contents if this element does not have an open buffer). Children are placed in the given newElements table (note, this element has already been placed in the newElements table). Returns true if successful, or false if an error is encountered while determining the structure of this element.- Throws:
JavaModelException
-
canBeRemovedFromCache
public boolean canBeRemovedFromCache() -
canBufferBeRemovedFromCache
-
closeBuffer
protected void closeBuffer()Close the buffer associated with this element, if any. -
closing
This element is being closed. Do any necessary cleanup.- Specified by:
closingin classJavaElement
-
codeComplete
protected void codeComplete(ICompilationUnit cu, ICompilationUnit unitToSkip, int position, CompletionRequestor requestor, WorkingCopyOwner owner, ITypeRoot typeRoot, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException - Throws:
JavaModelException
-
codeSelect
protected IJavaElement[] codeSelect(ICompilationUnit cu, int offset, int length, WorkingCopyOwner owner) throws JavaModelException - Throws:
JavaModelException
-
createElementInfo
- Specified by:
createElementInfoin classJavaElement
-
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- Overrides:
existsin classJavaElement- Returns:
trueif this element exists in the Java model, andfalseif this element does not exist- See Also:
-
findRecommendedLineSeparator
Description copied from interface:IOpenableFinds and returns the recommended line separator for this element. The element's buffer is first searched and the first line separator in this buffer is returned if any. Otherwise the preferencePlatform.PREF_LINE_SEPARATORon this element's project or workspace is returned. Finally if no such preference is set, the system line separator is returned.- Specified by:
findRecommendedLineSeparatorin interfaceIOpenable- Returns:
- the recommended line separator for this element
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.
-
generateInfos
protected void generateInfos(IElementInfo info, Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Description copied from class:JavaElementGenerates 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.- Specified by:
generateInfosin classJavaElement- Throws:
JavaModelException
-
ignoreErrorStatus
protected boolean ignoreErrorStatus(org.eclipse.core.runtime.IStatus status) -
getBuffer
Note: a buffer with no unsaved changes can be closed by the Java Model since it has a finite number of buffers allowed open at one time. If this is the first time a request is being made for the buffer, an attempt is made to create and fill this element's buffer. If the buffer has been closed since it was first opened, the buffer is re-created.- Specified by:
getBufferin interfaceIOpenable- Returns:
- the buffer opened for this element, or
nullif this element does not have a buffer - Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- See Also:
-
getBufferFactory
Deprecated.Answers the buffer factory to use for creating new buffers -
getBufferManager
Returns the buffer manager for this element. -
getCorrespondingResource
Return my underlying resource. Elements that may not have a corresponding resource must override this method.- Specified by:
getCorrespondingResourcein interfaceIJavaElement- Returns:
- the corresponding resource, or
nullif none - Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource- 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- Overrides:
getOpenablein classJavaElement- Returns:
- the first openable parent or
nullif this element doesn't have an openable parent.
-
getUnderlyingResource
Description copied from interface:IJavaElementReturns the smallest underlying resource that contains this element, ornullif this element is not contained in a resource.- Specified by:
getUnderlyingResourcein interfaceIJavaElement- Returns:
- the underlying resource, or
nullif none - Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its underlying resource- See Also:
-
hasBuffer
protected boolean hasBuffer()Returns true if this element may have an associated source buffer, otherwise false. Subclasses must override as required. -
hasUnsavedChanges
Description copied from interface:IOpenableReturnstrueif this element is open and:- its buffer has unsaved changes, or
- one of its descendants has unsaved changes, or
- a working copy has been created on one of this element's children and has not yet destroyed
- Specified by:
hasUnsavedChangesin interfaceIOpenable- Returns:
trueif this element is open and:- its buffer has unsaved changes, or
- one of its descendants has unsaved changes, or
- a working copy has been created on one of this element's children and has not yet destroyed
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- See Also:
-
isConsistent
public boolean isConsistent()Subclasses must override as required.- Specified by:
isConsistentin interfaceIOpenable- Returns:
- true if the element is consistent with its underlying resource or buffer, false otherwise.
- See Also:
-
isOpen
public boolean isOpen()Description copied from interface:IOpenableReturns whether this openable is open. This is a handle-only method.Note: This method doesn't tell whether an
IJavaProject'sgetProject()is open. It is not equivalent toIProject.isOpen()!Note: Although
IOpenable.isOpen()is exposed in the API, clients rarely have a need to rely on this internal state of the Java model. -
isSourceElement
protected boolean isSourceElement()Returns true if this represents a source element. Openable source elements have an associated buffer created when they are opened. -
isStructureKnown
Description copied from interface:IJavaElementReturns whether the structure of this element is known. For example, for a compilation unit that has syntax errors,falseis returned. If the structure of an element is unknown, navigations will return reasonable defaults. For example,getChildrenfor 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.
- Specified by:
isStructureKnownin interfaceIJavaElement- Returns:
trueif the structure of this element is known- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource- See Also:
-
makeConsistent
public void makeConsistent(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Description copied from interface:IOpenableMakes this element consistent with its underlying resource or buffer by updating the element's structure and properties as necessary.Note: Using this functionality on a working copy will interfere with any subsequent reconciling operation. Indeed, the next
ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)orICompilationUnit.reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor)operation will not account for changes which occurred before an explicit use ofIOpenable.makeConsistent(IProgressMonitor)- Specified by:
makeConsistentin interfaceIOpenable- Parameters:
monitor- the given progress monitor- Throws:
JavaModelException- if the element is unable to access the contents of its underlying resource. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- See Also:
-
open
Description copied from interface:IOpenableOpens this element and all parent elements that are not already open. For compilation units, a buffer is opened on the contents of the underlying resource.Note: Although
IOpenable.open(IProgressMonitor)is exposed in the API, clients are not expected to open and close elements - the Java model does this automatically as elements are accessed.- Specified by:
openin interfaceIOpenable- Parameters:
pm- the given progress monitor- Throws:
JavaModelException- if an error occurs accessing the contents of its underlying resource. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- See Also:
-
openBuffer
protected IBuffer openBuffer(org.eclipse.core.runtime.IProgressMonitor pm, IElementInfo info) throws JavaModelException Opens a buffer on the contents of this element, and returns the buffer, or returnsnullif opening fails. By default, do nothing - subclasses that have buffers must override as required.- Throws:
JavaModelException
-
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- Overrides:
getResourcein classJavaElement- Returns:
- the innermost resource enclosing this element,
nullif this element is included in an external archive
-
resource
public org.eclipse.core.resources.IResource resource()- Specified by:
resourcein classJavaElement
-
resource
-
resourceExists
protected boolean resourceExists(org.eclipse.core.resources.IResource underlyingResource) Returns whether the corresponding resource or associated file exists -
save
public void save(org.eclipse.core.runtime.IProgressMonitor pm, boolean force) throws JavaModelException Description copied from interface:IOpenableSaves any changes in this element's buffer to its underlying resource via a workspace resource operation. This has no effect if the element has no underlying buffer, or if there are no unsaved changed in the buffer.The
forceparameter controls how this method deals with cases where the workbench is not completely in sync with the local file system. Iffalseis specified, this method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workbench. This option ensures there is no unintended data loss; it is the recommended setting. However, iftrueis specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).As a result of this operation, the element is consistent with its underlying resource or buffer.
- Specified by:
savein interfaceIOpenable- Parameters:
pm- the given progress monitorforce- it controls how this method deals with cases where the workbench is not completely in sync with the local file system- Throws:
JavaModelException- if an error occurs accessing the contents of its underlying resource. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- This Java element is read-only (READ_ONLY)
- See Also:
-
getPackageFragmentRoot
Find enclosing package fragment root if any -
validateExistence
protected abstract org.eclipse.core.runtime.IStatus validateExistence(org.eclipse.core.resources.IResource underlyingResource) -
openAncestors
protected void openAncestors(Map<IJavaElement, IElementInfo> newElements, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException - Throws:
JavaModelException
-