Last modified 19:00 CET November 20, 2003
IWorkingCopy
gathered all working copy concerns, and ICompilationUnit
implemented this interface. However, though only the factory method made sense for compilation units, they still had to implement
the entire working copy contract., which was not relevant to clients (implementation detail).
IWorkingCopy
also implemented the spec'ed factory method, but it didn't work for these.
IWorkingCopy
implement
ICompilationUnit
. However as explained in the next section, closing the gap
between resource based compilation units and working copies required to merge these two interfaces. As a consequence
the interface IWorkingCopy
is removed and all its functionality is merged into ICompilationUnit
.
IWorkingCopy
and ICompilationUnit
can adapt to this change by referencing
ICompilationUnit
instead of IWorkingCopy
when a working copy is needed. For example:
ICompilationUnit compilationUnit = ...; IWorkingCopy workingCopy = (IWorkingCopy)compilationUnit.getWorkingCopy(); workingCopy.reconcile(true/*force problem detection*/, null/*no progress monitor*/);should be converted into:
ICompilationUnit compilationUnit = ...; ICompilationUnit workingCopy = compilationUnit.getWorkingCopy(null/*no progress monitor*/); workingCopy.reconcile(true/*force problem detection*/, null/*no progress monitor*/);
IWorkingCopy
functionality into usage of ICompilationUnit
use this table:
IWorkingCopy | ICompilationUnit | Note |
---|---|---|
commit(boolean, IProgressMonitor) | commitWorkingCopy(boolean, IProgressMonitor) | |
destroy() | discardWorkingCopy() | |
findElements(IJavaElement) | findElements(IJavaElement) | |
findPrimaryType() | findPrimaryType() | |
findSharedWorkingCopy(IBufferFactory) | findWorkingCopy(WorkingCopyOwner) | See next section for details. |
getOriginal(IJavaElement) | Use IJavaElement.getPrimaryElement() instead. Note that this no longer returns null if the receiver
is not a working copy but this returns the receiver. |
|
getOriginalElement() | getPrimary() | This no longer returns null if the receiver is not a working copy but this returns the receiver.
The returned object is no longer an IJavaElement but an ICompilationUnit . |
getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor) | getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor) | See next section for details.
The returned object is no longer an IJavaElement but an ICompilationUnit . |
getWorkingCopy() | getWorkingCopy(IProgressMonitor) | The returned object is no longer an IJavaElement but an ICompilationUnit . |
getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor) | getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor) | Working copies are now implicitely shared. See next section for details.
The returned object is no longer an IJavaElement but an ICompilationUnit . |
isBasedOn(IResource) | hasResourceChanged() | The IResource was always the working copy's resource. There was no need to pass it in. |
isWorkingCopy() | isWorkingCopy() | |
reconcile() | reconcile(boolean, IProgressMonitor) | Pass in false and null to have the equivalent functionality. Note that this method doesn't
return anything. |
reconcile(boolean, IProgressMonitor) | reconcile(boolean, IProgressMonitor) | |
restore() | restore() |
createBuffer(...)
can be
provided.
IBufferFactory
should now subclass WorkingCopyOwner
and pass this working
copy owner to the Java model operation in lieu of the buffer factory. The simplest implementation being:
new WorkingCopyOwner() {}
IBufferFactory factory = ... // Create a shared working copy for this buffer factory (to show it in an editor) ICompilationUnit cu = ... IWorkingCopy copy = cu.getSharedWorkingCopy(null/*no progress monitor*/, factory, null/*no problem reporter*/); // Find out the children of a package IPackageFragment pkg = ... ICompilationUnit[] cus = pkg.getCompilationUnits(); for (int i = 0; i < cus.length; i++) { ICompilationUnit copy = (ICompilationUnit) cus[i].findSharedWorkingCopy(factory); if (copy != null) { cus[i] = copy; } }would now convert this code to:
WorkingCopyOwner owner = ... // Create a shared working copy for this working copy owner (to show it in an editor) ICompilationUnit cu = ... ICompilationUnit copy = cu.getWorkingCopy(owner, null/*no problem reporter*/, null/*no progress monitor*/); // Find out the children of a package IPackageFragment pkg = ... ICompilationUnit[] cus = pkg.getCompilationUnits(owner);
WorkingCopyOwner owner = ... // Search for references to a method in the working copies of the given owner IMethod method = .... IJavaSearchScope scope = ... IJavaSearchResultCollector resultCollector = ... SearchEngine searchEngine = new SearchEngine(owner); searchEngine.search(ResourcesPlugin.getWorkspace(), method, REFERENCES, scope, resultCollector); // Build AST for a compilation unit that contains a reference to the method // and build its bindings in the context of the working copies of the given owner ICompilationUnit cu = ...; CompilationUnit ast = AST.parseCompilationUnit(cu, true /*resolve bindings*/, owner) ;