Bug 6749 - [clean up] perform code cleanup on save [code manipulation]
Summary: [clean up] perform code cleanup on save [code manipulation]
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P4 enhancement with 5 votes (vote)
Target Milestone: 3.3 M3   Edit
Assignee: Benno Baumgartner CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 22741 22742 23332 27377 32245 41320 54562 69193 91904 99900 127166 (view as bug list)
Depends on:
Blocks:
 
Reported: 2001-12-10 13:50 EST by Sebastian Davids CLA
Modified: 2006-11-02 03:59 EST (History)
24 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Davids CLA 2001-12-10 13:50:06 EST
What about the following options:

(1) - "Automatically Organize Imports" (before "Save" and/or "Code Format")
(2) - "Save editor after Code Format"
(3) - "Automatically Format Code before Save"
(4) - "Automatically Save after Organize Imports"

The following two patterns happen quite often:

enter new code ... (if one expects errors ;-)) "Add Imports" ... 
then "Format" ... then "Save"

  or

enter new code ... then "Save" ... (if there're any errors) "Add Imports" ... 
then "Format" ... then "Save"

It would be nice if one just had to press the "Save"-Hotkey or the "Code 
Format"-hotkey (or another hotkey/menu-item) and the code would be 
formatted/saved or imports organized/formatted/saved.

If either the "Code Formatter" (which should never happen) or the "Add Imports" 
encounter any conflicts (in this "Action"-Combo") the user could be notified 
prior to the "Save".

Sebastian Davids
Comment 1 Erich Gamma CLA 2001-12-12 08:12:29 EST
most of the options make sense but can't be committed for 2.0
Comment 2 rolarenfan CLA 2001-12-20 13:42:02 EST
For the "auto-save after Organize Imports" I believe a strong case can be made 
that this is really just like refactoring, which always (am I right?) saves.  
One kind of refactoring is moving classes from one package to another, or 
renaming a package -- that requires the exact same sort of import-declaration 
adjustment, and indeed after such refactorings, Eclipse (1.0, build 137) seems 
to always save, which seems to always be good. 

Furthermore, under what circumstance would you ever want NOT to save after doing 
an Organize Imports? 
Comment 3 Erich Gamma CLA 2002-05-04 14:02:14 EDT
>Furthermore, under what circumstance would you ever want NOT to save after 
>doing an Organize Imports? 
save can trigger an auto build and when I'm in the middle of editing the file 
and just did an organize import to get code assist to work I do not want that 
an auto build is triggered. 

Other suggestions are deferred for after 2.0
Comment 4 Dirk Baeumer CLA 2002-08-23 04:39:43 EDT
*** Bug 22741 has been marked as a duplicate of this bug. ***
Comment 5 Dirk Baeumer CLA 2003-01-07 04:33:28 EST
*** Bug 27377 has been marked as a duplicate of this bug. ***
Comment 6 Dirk Baeumer CLA 2003-04-28 06:02:54 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 7 Dirk Baeumer CLA 2003-05-12 09:32:14 EDT
*** Bug 23332 has been marked as a duplicate of this bug. ***
Comment 8 Lars Ködderitzsch CLA 2004-01-05 09:52:42 EST
Is this request still on track?
I am very interested in such a auto-format-on-save feature too.
It's been a while since 2.0, so could this one be reconsidered for 3.0?
Comment 9 Adam Kiezun CLA 2004-06-10 10:38:05 EDT
+1 for organize imports on save
Comment 10 Dirk Baeumer CLA 2004-07-03 11:37:36 EDT
*** Bug 69193 has been marked as a duplicate of this bug. ***
Comment 11 Silvio Böhler CLA 2004-09-17 14:25:23 EDT
+1 for an option "Organize imports on save"
Comment 12 Aaron Luchko CLA 2005-01-11 17:09:43 EST
I don't agree with these changes.  For 1/3 I agree with some hot key for
Organizing Imports and Code Formatting but I don't believe it should be
associated with "Save".  First for a small example of where it is advantageous
to have unused imports consider the case where while developing you're
investigating the situation of using Foo or Bar.  Now you have 

import Foo;
import Bar;

...

Foo f = new Foo();
f.doSomething();
//Bar b = new Bar();
//b.doSomethingSlightlyDifferent();

In this case one is doing a test run with Foo, next they may uncomment Bar and
comment Foo and do a test run using that.  However now this person has to
undertake the additional step of using the quickfix to redo the import
everytime, no major issue but a small pain especially if one has a number of
possible supplies of Foo.

Also consider the fact that "Save" is an operation that should really not be
altering a file, it's better if it prompts but I'm still unsure as it would
likely be a hit enter for yes style query which many people will accept out of
habit then be wondering why their file just changed.

As for 2,4 I don't agree since the Save triggers the automatic build and neither
operation should change the functionality of the compiled program (I should
state I haven't used Format Code) and unused imports shouldn't change the
binaries as all (other than line numbers in debug info).  An Automatic Build in
this situation is completely unnecessary and is a big hinderance slowing down
the machine (sometimes fairly significantly).
Comment 13 Maik Schreiber CLA 2005-02-23 18:05:59 EST
+1 for organizing imports on save from me, too. Is this issue still being worked
on??
Comment 14 Dirk Baeumer CLA 2005-04-20 05:03:32 EDT
*** Bug 91904 has been marked as a duplicate of this bug. ***
Comment 15 Dani Megert CLA 2005-06-14 03:56:54 EDT
*** Bug 99900 has been marked as a duplicate of this bug. ***
Comment 16 Dani Megert CLA 2005-06-14 11:56:47 EDT
*** Bug 99900 has been marked as a duplicate of this bug. ***
Comment 17 Mark Levison CLA 2006-02-15 08:16:14 EST
+1 Both organize and format on save. Make it optional - to be fair to the person with issue about comments.

That way any file that I make changes to will always be correctly formatted.
Comment 18 Benno Baumgartner CLA 2006-02-28 04:42:42 EST
*** Bug 127166 has been marked as a duplicate of this bug. ***
Comment 19 Mark Levison CLA 2006-03-02 14:42:38 EST
This has been marked "resolved" - resolution "later" for about three years. What will it take to reopend it?
Comment 20 Ed Burnette CLA 2006-04-26 12:01:24 EDT
Can we reopen this and re-describe it as 'perform code cleanup on save' and have it make it into 3.2 or failing that, at least 3.3?
Comment 21 Sebastian Davids CLA 2006-04-26 12:11:05 EDT
as you wish :D
Comment 22 Martin Aeschlimann CLA 2006-04-27 09:45:57 EDT
This is an interesting item for 3.3.

We would appriciate if you leave the reopening of bugs to us. We try hard to keep the overview over the huge number of bugs and use 'LATER' also as way tof categorization. Simply add your comments to the bug, and we will reopen if you convinced us.

Comment 23 Dan Forward CLA 2006-05-08 18:51:33 EDT
This is a duplicate of several reported bugs that have requested a "trim trailing spaces" option, but this bug never mentions trimming trailing spaces. FWIW, the option to trim trailing spaces should not be available only when saving.
Comment 24 Martin Aeschlimann CLA 2006-06-09 05:21:16 EDT
*** Bug 54562 has been marked as a duplicate of this bug. ***
Comment 25 Dani Megert CLA 2006-10-26 12:20:54 EDT
*** Bug 41320 has been marked as a duplicate of this bug. ***
Comment 26 Dani Megert CLA 2006-10-26 12:21:45 EDT
This will be available in M3 and starting with N20061027-0010 as an experimental feature: you can select a clean up profile to be run on save.

Enjoy!
Comment 27 Dani Megert CLA 2006-10-26 12:23:45 EDT
*** Bug 22742 has been marked as a duplicate of this bug. ***
Comment 28 Dani Megert CLA 2006-10-26 12:31:30 EDT
*** Bug 32245 has been marked as a duplicate of this bug. ***
Comment 29 Prashant Deva CLA 2006-10-27 10:34:23 EDT
But once needs to think how will this evolve if you decide to later implement 'Auto Save' funcitonality for the editors.
I mean it would be kinda weird to have the formatting of a document change while the user is typing (due to auto save).
Comment 30 Dani Megert CLA 2006-10-27 10:40:00 EDT
Can't comment on that since we currently have no idea how auto-save would work. If it directly saves the resource then the current solution wouldn't trigger the save participants.