public interface IOpenable
isConsistent()
and makeConsistent(IProgressMonitor)
.
To reduce complexity in clients, elements are automatically opened by the Java model as element properties are accessed. The Java model maintains an LRU cache of open elements, and automatically closes elements as they are swapped out of the cache to make room for other elements. Elements with unsaved changes are never removed from the cache, and thus, if the client maintains many open elements with unsaved changes, the LRU cache can grow in size (in this case the cache is not bounded). However, as elements are saved, the cache will shrink back to its original bounded size.
To open an element, all openable parent elements must be open.
The Java model automatically opens parent elements, as it automatically opens elements.
Opening an element may provide access to direct children and other descendants,
but does not automatically open any descendents which are themselves IOpenable
.
For example, opening a compilation unit provides access to all its constituent elements,
but opening a package fragment does not open all compilation units in the package fragment.
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this element and its buffer (if any).
|
String |
findRecommendedLineSeparator()
Finds and returns the recommended line separator for this element.
|
IBuffer |
getBuffer()
Returns the buffer opened for this element, or
null
if this element does not have a buffer. |
boolean |
hasUnsavedChanges()
Returns
true if 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
|
boolean |
isConsistent()
Returns whether the element is consistent with its underlying resource or buffer.
|
boolean |
isOpen()
Returns whether this openable is open.
|
void |
makeConsistent(IProgressMonitor progress)
Makes this element consistent with its underlying resource or buffer
by updating the element's structure and properties as necessary.
|
void |
open(IProgressMonitor progress)
Opens this element and all parent elements that are not already open.
|
void |
save(IProgressMonitor progress,
boolean force)
Saves any changes in this element's buffer to its underlying resource
via a workspace resource operation.
|
void close() throws JavaModelException
Note: although close()
is exposed in the API, clients are
not expected to open and close elements - the Java model does this automatically
as elements are accessed.
JavaModelException
- if an error occurs closing this elementString findRecommendedLineSeparator() throws JavaModelException
Platform.PREF_LINE_SEPARATOR
on this element's project or workspace is returned.
Finally if no such preference is set, the system line separator is returned.JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IBuffer getBuffer() throws JavaModelException
null
if this element does not have a buffer.null
if this element does not have a bufferJavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.boolean hasUnsavedChanges() throws JavaModelException
true
if this element is open and:
true
if this element is open and:
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.boolean isConsistent() throws JavaModelException
NOTE: Child consistency is not considered. For example, a package fragment
responds true
when it knows about all of its
compilation units present in its underlying folder. However, one or more of
the compilation units could be inconsistent.
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.makeConsistent(IProgressMonitor)
boolean isOpen()
void makeConsistent(IProgressMonitor progress) throws JavaModelException
Note: Using this functionality on a working copy will interfere with any
subsequent reconciling operation. Indeed, the next
ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
or
ICompilationUnit.reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor)
operation will not account for changes which occurred before an
explicit use of makeConsistent(IProgressMonitor)
progress
- the given progress monitorJavaModelException
- if the element is unable to access the contents
of its underlying resource. Reasons include:
isConsistent()
,
ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
void open(IProgressMonitor progress) throws JavaModelException
Note: although open(org.eclipse.core.runtime.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.
progress
- the given progress monitorJavaModelException
- if an error occurs accessing the contents
of its underlying resource. Reasons include:
void save(IProgressMonitor progress, boolean force) throws JavaModelException
The force
parameter controls how this method deals with
cases where the workbench is not completely in sync with the local file system.
If false
is 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, if true
is 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.
progress
- the given progress monitorforce
- it controls how this method deals with
cases where the workbench is not completely in sync with the local file systemJavaModelException
- if an error occurs accessing the contents
of its underlying resource. Reasons include:
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.