Interface IWorkingCopy
- All Known Subinterfaces:
ICompilationUnit
A working copy of a Java element acts just like a regular element (handle), except it is not attached to an underlying resource. A working copy is not visible to the rest of the Java model. Changes in a working copy's buffer are not realized in a resource. To bring the Java model up-to-date with a working copy's contents, an explicit commit must be performed on the working copy. Other operations performed on a working copy update the contents of the working copy's buffer but do not commit the contents of the working copy.
Note: The contents of a working copy is determined when a working
copy is created, based on the current content of the element the working
copy is created from. If a working copy is an IOpenable
and is explicitly
closed, the working copy's buffer will be thrown away. However, clients should not
explicitly open and close working copies.
The client that creates a working copy is responsible for
destroying the working copy. The Java model will never automatically
destroy or close a working copy. (Note that destroying a working copy
does not commit it to the model, it only frees up the memory occupied by
the element). After a working copy is destroyed, the working copy cannot
be accessed again. Non-handle methods will throw a
JavaModelException
indicating the Java element does not exist.
A working copy cannot be created from another working copy.
Calling getWorkingCopy
on a working copy returns the receiver.
- Restriction:
- This interface is not intended to be implemented by clients.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
commit
(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) Deprecated.void
destroy()
Deprecated.UseICompilationUnit.discardWorkingCopy()
instead.findElements
(IJavaElement element) Deprecated.UseICompilationUnit.findElements(IJavaElement)
instead.Deprecated.UseITypeRoot.findPrimaryType()
instead.findSharedWorkingCopy
(IBufferFactory bufferFactory) Deprecated.UseICompilationUnit.findWorkingCopy(WorkingCopyOwner)
instead.getOriginal
(IJavaElement workingCopyElement) Deprecated.UseIJavaElement.getPrimaryElement()
instead.Deprecated.UseIJavaElement.getPrimaryElement()
instead.getSharedWorkingCopy
(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) Deprecated.Deprecated.UseICompilationUnit.getWorkingCopy(IProgressMonitor)
instead.getWorkingCopy
(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) Deprecated.boolean
isBasedOn
(org.eclipse.core.resources.IResource resource) Deprecated.UseICompilationUnit.hasResourceChanged()
instead.boolean
Deprecated.UseICompilationUnit.isWorkingCopy()
instead.org.eclipse.core.resources.IMarker[]
Deprecated.void
reconcile
(boolean forceProblemDetection, org.eclipse.core.runtime.IProgressMonitor monitor) Deprecated.void
restore()
Deprecated.UseICompilationUnit.restore()
instead.
-
Method Details
-
commit
void commit(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Deprecated.Commits the contents of this working copy to its original element and underlying resource, bringing the Java model up-to-date with the current contents of the working copy.It is possible that the contents of the original resource have changed since this working copy was created, in which case there is an update conflict. The value of the
force
parameter affects the resolution of such a conflict:-
true
- in this case the contents of this working copy are applied to the underlying resource even though this working copy was created before a subsequent change in the resource -
false
- in this case aJavaModelException
is thrown
Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Parameters:
force
- a flag to handle the cases when the contents of the original resource have changed since this working copy was createdmonitor
- the given progress monitor- Throws:
JavaModelException
- if this working copy could not commit. Reasons include:- A
CoreException
occurred while updating an underlying resource - This element is not a working copy (INVALID_ELEMENT_TYPES)
- A update conflict (described above) (UPDATE_CONFLICT)
- A
-
-
destroy
void destroy()Deprecated.UseICompilationUnit.discardWorkingCopy()
instead.Destroys this working copy, closing its buffer and discarding its structure. Subsequent attempts to access non-handle information for this working copy will result inIJavaModelException
s. Has no effect if this element is not a working copy.If this working copy is shared, it is destroyed only when the number of calls to
destroy()
is the same as the number of calls togetSharedWorkingCopy(IProgressMonitor, IBufferFactory)
.When it is destroyed, a REMOVED IJavaElementDelta is reported on this working copy.
-
getOriginal
Deprecated.UseIJavaElement.getPrimaryElement()
instead.Returns the original element the specified working copy element was created from, ornull
if this is not a working copy element. This is a handle only method, the returned element may or may not exist.- Parameters:
workingCopyElement
- the specified working copy element- Returns:
- the original element the specified working copy element was created from,
or
null
if this is not a working copy element
-
getOriginalElement
IJavaElement getOriginalElement()Deprecated.UseIJavaElement.getPrimaryElement()
instead.Returns the original element this working copy was created from, ornull
if this is not a working copy.- Returns:
- the original element this working copy was created from,
or
null
if this is not a working copy
-
findElements
Deprecated.UseICompilationUnit.findElements(IJavaElement)
instead.Finds the elements in this compilation unit that correspond to the given element. An element A corresponds to an element B if:- A has the same element name as B.
- If A is a method, A must have the same number of arguments as B and the simple names of the argument types must be equals.
- The parent of A corresponds to the parent of B recursively up to their respective compilation units.
- A exists.
null
if no such java elements can be found or if the given element is not included in a compilation unit.- Parameters:
element
- the given element- Returns:
- the found elements in this compilation unit that correspond to the given element
- Since:
- 2.0
-
findPrimaryType
IType findPrimaryType()Deprecated.UseITypeRoot.findPrimaryType()
instead.Finds the primary type of this compilation unit (that is, the type with the same name as the compilation unit), ornull
if no such a type exists.- Returns:
- the found primary type of this compilation unit, or
null
if no such a type exists - Since:
- 2.0
-
getWorkingCopy
Deprecated.UseICompilationUnit.getWorkingCopy(IProgressMonitor)
instead.Returns a new working copy of this element if this element is not a working copy, or this element if this element is already a working copy.Note: if intending to share a working copy amongst several clients, then
#getSharedWorkingCopy
should be used instead.When the working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.
Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Returns:
- a new working copy of this element if this element is not a working copy, or this element if this element is already a working copy
- Throws:
JavaModelException
- if the contents of this element can not be determined.
-
getWorkingCopy
IJavaElement getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException Deprecated.Returns a new working copy of this element using the given factory to create the buffer, or this element if this element is already a working copy. Note that this factory will be used for the life time of this working copy, that is if the working copy is closed then reopened, this factory will be reused. The buffer will be automatically initialized with the original's compilation unit content upon creation.Note: if intending to share a working copy amongst several clients, then
#getSharedWorkingCopy
should be used instead.When the working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.
Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Parameters:
monitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reportedfactory
- the factory that creates a buffer that is used to get the content of the working copy ornull
if the internal factory should be usedproblemRequestor
- a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set tonull
indicating that the client is not interested in problems.- Returns:
- a new working copy of this element using the given factory to create the buffer, or this element if this element is already a working copy
- Throws:
JavaModelException
- if the contents of this element can not be determined.- Since:
- 2.0
-
isBasedOn
boolean isBasedOn(org.eclipse.core.resources.IResource resource) Deprecated.UseICompilationUnit.hasResourceChanged()
instead.Returns whether this working copy's original element's content has not changed since the inception of this working copy.- Parameters:
resource
- this working copy's resource- Returns:
- true if this working copy's original element's content has not changed since the inception of this working copy, false otherwise
-
isWorkingCopy
boolean isWorkingCopy()Deprecated.UseICompilationUnit.isWorkingCopy()
instead.Returns whether this element is a working copy.- Returns:
- true if this element is a working copy, false otherwise
-
reconcile
Deprecated.Reconciles the contents of this working copy. It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.If the working copy hasn't changed, then no problem will be detected, this is equivalent to
IWorkingCopy#reconcile(false, null)
.Compilation problems found in the new contents are notified through the
IProblemRequestor
interface which was passed at creation, and no longer as transient markers. Therefore this API will returnnull
.Note: Since 3.0 added/removed/changed inner types generate change deltas.
- Returns:
null
- Throws:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
-
reconcile
void reconcile(boolean forceProblemDetection, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Deprecated.Reconciles the contents of this working copy. It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.The boolean argument allows to force problem detection even if the working copy is already consistent.
Compilation problems found in the new contents are notified through the
IProblemRequestor
interface which was passed at creation, and no longer as transient markers. Therefore this API answers nothing.Note: Since 3.0 added/removed/changed inner types generate change deltas.
- Parameters:
forceProblemDetection
- boolean indicating whether problem should be recomputed even if the source hasn't changed.monitor
- a progress monitor- Throws:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- Since:
- 2.0
-
restore
Deprecated.UseICompilationUnit.restore()
instead.Restores the contents of this working copy to the current contents of this working copy's original element. Has no effect if this element is not a working copy.Note: This is the inverse of committing the content of the working copy to the original element with
commit(boolean, IProgressMonitor)
.- Throws:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
-
ICompilationUnit
instead