Bug 8921

Summary: DCR - Need a way to create a working copy ignoring existing files
Product: [Eclipse Project] JDT Reporter: Dirk Baeumer <dirk_baeumer>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akiezun
Version: 2.0   
Target Milestone: 2.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Dirk Baeumer CLA 2002-02-01 10:16:29 EST
Build 20020129

We need a way to create a working copy ignoring existing files. This is 
necessary to analyze the impact when we are moving files to a different 
perspective. Jerome sugessted on the mailing the following:

CompilationUnit.getWorkingCopy() will throw a JavaModelException if the 
compilation unit does not exist. I guess what you would want is that it returns 
an empty working copy. This sounds like you need a new API:
ICompilationUnit.getWorkingCopy(boolean ignoreExistence)

The new API could be used as follows:

IPackageFragment pkg = ...;
String compilationUnitName = ...;
IWorkingCopy workingCopy =
pkg.getCompilationUnit(compilationUnitName).getWorkingCopy(true);

Unless you commit it, the corresponding file would not be created.

This functionality is needed to convert refactorings to the new DOM/AST
Comment 1 Philipe Mulet CLA 2002-02-07 07:35:40 EST
Agreed
Comment 2 Jerome Lanneluc CLA 2002-04-30 06:30:24 EDT
Dirk, do you still need this API?
Comment 3 Jerome Lanneluc CLA 2002-05-15 12:26:11 EDT
I assume no response means that is not that critical. Deferring.
Comment 4 Philipe Mulet CLA 2002-07-25 06:59:35 EDT
Reopening
Comment 5 Philipe Mulet CLA 2002-07-25 07:00:52 EDT
Clearing resolution
Comment 6 Philipe Mulet CLA 2002-07-25 07:24:40 EDT
Related to bug 21854, but I don't see the actual need for a separate API.

When reading the contents, if no file pre-exists, then an empty buffer should 
be used for free.
Comment 7 Jerome Lanneluc CLA 2002-08-22 11:20:56 EDT
*** Bug 21854 has been marked as a duplicate of this bug. ***
Comment 8 Jerome Lanneluc CLA 2002-08-22 11:22:20 EDT
We need a new API because the existing APIs are not handle based (they declare 
throwing a JavaModelException if the original compilation unit does not exist)
Comment 9 Jerome Lanneluc CLA 2002-09-02 09:35:36 EDT
I take what I said above back. The spec says that the reason a 
JavaModelException can be thrown include the fact that the compilation unit 
does not exist, but it doesn't enforce this exception to be thrown. So changing 
the current implementation to return an empty working copy if the cu doesn't 
exist is the right thing to do.
Comment 10 Jerome Lanneluc CLA 2002-09-03 06:50:21 EDT
Changed implementation to accept the creation of a working copy on a non-
existing cu. Also changed commit on working copies to allow to commit to a non-
existing cu (this creates the cu in this case).
Comment 11 David Audel CLA 2002-09-19 11:02:19 EDT
Verified.