Community
Participate
Working Groups
Build 20021018 If you create an ICompilationUnit on a resource which is outside the project's classpath, all subsequent operations (except the creation of a working copy) should fail with a JavaModelException (status ELEMENT_DOES_NOT_EXIST)
We should wait until we have some feedback on this front.
Current plan is to release this no later than 2.1-M3.
Fixed CompilationUnit to ensure that exists() returns false for a cu outside the classpath and that it cannot be opened. Fixed WorkingCopy to allow to open a working copy on such a cu.
In case this fix needs to be undone: 1. Add the following methods to CompilationUnit: public IResource getUnderlyingResource() throws JavaModelException { return getResource(); } protected boolean parentExists(){ return true; // tolerate units outside classpath } 2. Move WorkingCopy.openParent() to CompilationUnit 3. Replace WorkingCopy.commit with the following contents: /** * @see IWorkingCopy */ public void commit(boolean force, IProgressMonitor monitor) throws JavaModelException { ICompilationUnit original = (ICompilationUnit)this.getOriginalElement(); if (original.exists()) { CommitWorkingCopyOperation op= new CommitWorkingCopyOperation (this, force); runOperation(op, monitor); } else { IFile originalRes = (IFile)original.getResource(); try { originalRes.create( new InputStream() { public int read() throws IOException { return -1; } }, force, monitor); } catch (CoreException e) { throw new JavaModelException(e); } original.getBuffer().setContents(this.getContents()); original.save(monitor, force); } }
Actually point 3 is not needed.
Added flag CompilationUnit.FIX_BUG25184 which is set to true. To undo the fix, set it to false.
Verified.