Bug 3849 - Refactoring - should not save file after extract method (1GEWRU6) [refactoring] [general issue]
Summary: Refactoring - should not save file after extract method (1GEWRU6) [refactorin...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: All Windows 2000
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Dirk Baeumer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-10 23:01 EDT by Erich Gamma CLA
Modified: 2004-06-09 08:34 EDT (History)
3 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:01:53 EDT
EG (6/6/2001 6:54:41 AM)	
	it is not critical for June. But we shouldn't automatically save the resource. This is inconsistent with
	organize imports.

NOTES:

DB (08.08.2001 17:01:05)
	I would like to defer this until we know how we will implement the new Code Manipulation Infrastructure.
	See also 1GEJ61L: ITPJUI:WIN2000 - Refactoring: operation aren't cancelable since the can't be executed in a different thread.
Comment 1 Dirk Baeumer CLA 2001-11-09 04:06:34 EST
This is only possible if we get a better undo story. Currently we can only push 
undo commands on the refactorings undo stack if a file is save. Otherwise the 
next save would flush the current undo stack which would remove the undo object 
for extract method.
Comment 2 Erich Gamma CLA 2001-11-09 05:26:40 EST
We cannot assume that we get a better undo story now, so we have to investigate 
alternatives. The problem is serious, when working with auto build this 
triggers a build. After an extract method is almost always an inappropriate 
time for a build.

Why can't we implement a custom undo that works on a buffer.
Comment 3 Dirk Baeumer CLA 2001-11-09 05:38:16 EST
This isn't so easy since the editor and the refactoring undo stack have nothing
to do with each other. What can happen in this scenario that someone does an 
extract method, refactoring pushes and undo object onto the stack and we doen't 
save the file. Now the user starts editing and edits some text inserted by 
extract method. What do we do in this situation: 

- remove extract method undo from the stack again.
- leaf it on the stack and hope that the user executes undo in the right order 
(first the editor undo and than the extract method undo).

It is still my opinion that refactoring isn't the right place to deal with this.
Comment 4 Erich Gamma CLA 2001-11-09 08:15:54 EST
Agreed, trying to synch to undo stacks is not doable.

Suggest to remove Refactoring undo for Extract Method when auto-build is on.
This is still a hack.

There is a need to investigate into a better solution.
Comment 5 Dirk Baeumer CLA 2002-01-22 08:47:02 EST
Still not possible since we still have the same undo problems. Still waiting 
for the final Undo proposal from workbench.
Comment 6 Dani Megert CLA 2002-02-27 09:47:36 EST
Problem still in I20020226 - leaving BR as is.
Comment 7 Dirk Baeumer CLA 2002-04-18 06:42:47 EDT
Erich, any objection if I mark this one as later. We still don't have a better 
undo stroy yet and I doubt that something will happen for 2.0
Comment 8 Dirk Baeumer CLA 2002-04-19 06:45:11 EDT
No action planned for 2.0
Comment 9 Dirk Baeumer CLA 2002-08-14 04:59:19 EDT
This is still an issue and we should find a solution for 2.x. Given the fact 
that we think about adding snap shoting support we could do the following:

- all refactoring that manipulate a single file will use the editor's undo 
  stack. This doesn't force refactoring to save the resource.
- for refactorings manipulating more than one resource we use the "upcoming"
  snap shoting support.
Comment 10 Sudarsha Wijenayake CLA 2004-02-25 16:24:11 EST
Also exists in Eclipse 3.0M7 (build id: 200402122000) on Solaris 9 and HP-UX 
11i platforms.
Comment 11 Dirk Baeumer CLA 2004-03-10 05:04:37 EST
This was an intermediate problem that got fixed again for I20040309.
Comment 12 Brian So CLA 2004-04-12 15:21:56 EDT
With Eclipse 3.0M8 (build id: 200403261517) on Solaris 9 and HP-UX11.11 
platform, the problem still exist. The following is my procedure to reproduce 
the problem:

1. Download the 3.0M8 SWT Examples zip file from the eclipse.org site and load 
it on to Eclipse workbench.
2. Create a Java project and call it "JUnit".
3. In the Packages Explorer view, select JUnit project and from its context 
menu "Import->Zip file".
4. Browse to junit37src.jar file in 
<eclipse>/plugins/org.eclipse.jdt.ui.examples.projects/archive/junit/ directory.
Select file name and click "Ok".
5. Click the "Select All" button to make sure that all the files are selected 
in the folder. Ensure that the destination folder is "JUnit". Click "Finish" 
and click "Yes" on the question box concerning .classpath file.
6. In the Package Explorer view, expand the junit.framework package, and select 
the "TestSuite.java" (double click to open the file).
7. Using Window > Preferences > Java > Editor from Workbench menu select "Show 
line numbers" from editor "Appearance" page.
8. In the TestSuite.java file, select the following range of code from Class 
superClass = theClass; to the end of "while" control statement (Lines 61- 69.
9. From the selection's context menu in the Editor window,  select Refactor > 
Extract Method.
10. Enter Method name to be "collectInheritedTests" and click "OK". 
TestSuite.java is modified to contain the new method, in place of the original 
lines 61-69, is a method call to 'collectInheritedTests()' with parameters for 
the variables used in the extracted code.  The new method 'collectInheritedTests
()' appears in the Java code (and Outline / Package Explorer views).
11. Close the TestSuite.java Editor window. No prompt dialog is displayed 
mentioning that the file has been modified, with a prompt to save the file.  

The TestSuite.java file is saved automatically!  This may not be the desired 
functionality on the part of the software designer. Please reopen this bug 
report. Thanks.
Comment 13 Dirk Baeumer CLA 2004-04-13 05:43:34 EDT
Do you have autobuild on ?
Comment 14 Brian So CLA 2004-04-13 09:29:03 EDT
Yes. I did have "Perform build autmatically on resource modification" selected. 
Does that mean I have to turn it off before refactoring for no autosave? 
Eclipse will not autosave if I just edit the file. It will provide me with 
errors only. After everything is fine it still will not autosave the file. May 
be a warning forRefactoring on autosave is needed?
Comment 15 Sudarsha Wijenayake CLA 2004-06-08 15:06:26 EDT
I agree with Brian So’s comments. Enabling “Auto Build” option should not 
force Eclipse to automatically save the associated class file. 

Extracting Java code into a method will not save the associated class file if 
it is done manually. Therefore, the automated option must behave the same way 
in order to ensure the consistency.

I think this defect should be reopened.
Comment 16 Dirk Baeumer CLA 2004-06-08 18:34:44 EDT
Here is how this is currently implemented: if the file is dirty then it is 
left dirty. If it is saved, it is saved afterwards. 
Comment 17 Sudarsha Wijenayake CLA 2004-06-09 08:34:31 EDT
I think this behavior of Eclipse is confusing. I would save a file before I 
modify its original content (in this case moving a part of its source code into 
a method) if I want to preserve the earlier work. If Eclipse automatically 
saves the file immediately after refactoring is done, then the previous work 
would be destroyed. So, what is the point of saving the file after all?

I believe that this behavior of Eclipse should be changed.