Bug 4210 - copy/move read-only compilation units (1GK1KJM) [ccp] [dnd] [refactoring]
Summary: copy/move read-only compilation units (1GK1KJM) [ccp] [dnd] [refactoring]
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All Windows 2000
: P4 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: investigate
: 8663 (view as bug list)
Depends on:
Blocks: 3624
  Show dependency tree
 
Reported: 2001-10-10 23:07 EDT by Erich Gamma CLA
Modified: 2009-08-30 02:19 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erich Gamma CLA 2001-10-10 23:07:53 EDT
AK (9/14/2001 1:52:11 PM)
	1. create a cu and make it  read-only (in the navigator)
	2. create another package and copy the cu (from the packages view)
	3. you get an error dialog.
	this is inconsistent with the navigator - shows no errors
	
NOTES:
	AK (9/14/2001 1:53:48 PM)
	the navigator uses IResource::copy which does not report any errors.
	the packages view uses ISourceManipulation::copy (on CompilationUnit) which reports an error when setting
		 the new contents of the file

	one solution would be to supress the read only error (by java model) in that case
Comment 1 Martin Aeschlimann CLA 2001-10-16 11:14:06 EDT
moved to 'active'
Comment 2 Adam Kiezun CLA 2001-11-14 12:16:28 EST
i don't think ui should do something here
i think it should be handled in CompilationUnit::copy 
suggest moving to jcore
Comment 3 Erich Gamma CLA 2001-11-14 12:49:16 EST
agreed, moving to Java Core
Comment 4 Adam Kiezun CLA 2001-11-20 05:46:16 EST
same happens if you try renaming a package that has a read-only compilation
unit - you get a JavaModelException
Comment 5 Philipe Mulet CLA 2001-11-26 12:19:00 EST
The JavaModel operation does copy the resource, and then tries to update its 
content (even if nothing actually needs to be changed).

What behavior would you expect in case it did fail to update the source, and 
the source would need to be modified ? Silently fail, and no update did occur ?

Thinking of a similar problem (Java model does not notify when failing to 
update the .classpath if read-only), I do not think that silently failing is an 
option.

I did however fix the case where nothing needs to be updated, it will not even 
attempt to do so anymore.
Comment 6 Philipe Mulet CLA 2001-11-29 09:29:07 EST
As per discussion with DJ, we should not be editing the contents of read-only 
files ever (copy/move). Is it ok for you to not update their contents at all ? 
Package statements would be incorrect, but if the file is read-only anyway...
Comment 7 Erich Gamma CLA 2001-11-29 09:32:57 EST
The conclusion makes sense to me. Adopting PR.

Adam can we warn the user that the files are readonly and that the package 
declaration will not be updated?
Comment 8 Neil Swingler CLA 2001-12-14 04:03:41 EST
I don't think copied compilation units should retain the read-only attribute.
We are using a VCS where only locked files are writeable. I don't want to have
to check out a file just to make a copy of it.
Comment 9 Erich Gamma CLA 2001-12-14 06:06:48 EST
preserving the read-only attribute the common behaviour on most platforms and 
is also the behaviour I'd expect.

I don't fully understand your use case. When you copy a read only file the copy 
isn't managed by the VCM yet so you can just go in and change its attribute to 
writeable and start editing. 
Comment 10 Neil Swingler CLA 2001-12-14 07:13:25 EST
What I want is the same functionality that Together provides. Copying a
read-only java source file creates a new writeable class ready
to compile with it's new class name.

A typical example is creating a new JUnit test. I nearly always copy an
existing one.

It would be nice if the copy would change any internal references to it's own
class to the new class. e.g. in the suite method of a JUnit test.
Comment 11 David Wegener CLA 2002-02-04 11:45:55 EST
I agree with Neil.  I don't really like to 'feature' of the new file copy 
maintaining the read-only attribute.  I am often frustrated by coping a read-
onle file opening it in an editor and being frustrated when trying to save the 
file because it is read only.  We have a number of classes each representing a 
different message.  When creating a new message, we often copy an existing 
class.  If the existing class is readonly, we lose much of the benefit of the 
copy mechanism.  In our case we usually copy the class into the same package.  
This creates an entirely new class with CopyOf prepended to the class name.  
However, none of the internal references are updated.  If we subsequently check 
out the new class and rename it, we loose the automatic updating of the class 
name and constructors.

If copy needs to change the file in order for it to remain consistent, it 
should remove the read-only attribute, at least for JDT compilation units.
Comment 12 Philipe Mulet CLA 2002-04-02 08:20:37 EST
This should be driven by UI. The JCore should only do the minimal (rsc copy), 
and JUI should jump in and offer to lose the read-only flag, so as to perform 
refactoring operations.

Then maybe revert the flag back to read-only afterwards (likely not IMO).

Olivier - please check our rsc copy behavior in presence of read-only files. 
Then this problem should move to JUI for further action.
Comment 13 Olivier Thomann CLA 2002-04-02 10:06:36 EST
The problem is that JCore is doing more than just copying the file. It tries to update the package 
declaration at the beginning of the file according to where the compilation unit has been copied. 
So for now the copy fails for a compilation unit because of this update. The copy is created with the 
read-only flag. This is consistent with the copy from the navigator.

Comment 14 Olivier Thomann CLA 2002-04-02 12:04:14 EST
I added an extra check on the compilation unit copy. If the destination is read-only, there is no 
more update of its contents. This means that if you copy a compilation unit A.java from package p1 
to package p2 and A.java is read-only, you end up with A.java in p2, but its package declaration is 
still package p1;.
This is consistent with the navigator copy for read-only files. Now if an 
extra update wants to be applied, the JUI should take care of it.
Move to JUI.
Comment 15 David Wegener CLA 2002-04-02 15:20:22 EST
Is making the behavior consistent between the navigator and the package view 
really the goal?  The main reason for having separate copy behaviors was 
because the Java package view had knowledge of what is being copied and can 
insure consistency within the Java model.  A Java copy inherently requires an 
update of the compilation unit if for no other reason than to update the 
package statement.

The copy behavior is also not consistent between the two views if you make a 
copy of the file in the same directory.  Select "A.java" and say copy.  Select 
the same directory and select paste.  The navigator will create a new file 
called "Copy of A.java".  The package view will create a new file 
called "CopyOfA.java".  If "A.java" is writable, the "CopyOfA.java" file will 
have the class name and all constructors updated with the correct name.

It simply doesn't make sense to leave the new file in an inconsistent state 
when performing a copy from the Java package view.
Comment 16 Erich Gamma CLA 2002-05-11 15:12:30 EDT
*** Bug 8663 has been marked as a duplicate of this bug. ***
Comment 17 Erich Gamma CLA 2002-06-04 15:30:01 EDT
no action for 2.0
Comment 18 Dirk Baeumer CLA 2002-07-25 13:28:14 EDT
This is really annoying and we should find a solution for 2.1. I agree that 
copying a resource in a Java world should not honor the read-only flag. Or at 
least we should show a dialog upfront asking whether the user wants:

- to keep the read-only flag with no content change
- make the file writable and update the content

And there should be a check box saying: always make file writeable on copy.
Comment 19 Dirk Baeumer CLA 2003-04-28 06:03:25 EDT
Chaning state from assigned later to resolved later. Assigned later got 
introduced by the last bug conversion and is not a supported Eclipse bug state.
Comment 20 Denis Roy CLA 2009-08-30 02:19:47 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.