Bug 14597 - rearrange source code
Summary: rearrange source code
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 13538 20253 22897 23209 26426 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-04-25 08:51 EDT by Xavier Méhaut CLA
Modified: 2003-06-23 08:58 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xavier Méhaut CLA 2002-04-25 08:51:52 EDT
hello,
I would suggest the following feature ; be able to rearrange the source code. 
Why this feature? For instance you sorted your method view in the java browsing 
perspective to have the methods in alphabetic order. You add then a method . 
Presently, it will be inserted in the source code where you write the code. The 
rearrange feature would enable the user to place its method automatically in 
the right place.
regards
Xavier
Comment 1 Martin Aeschlimann CLA 2002-04-26 10:15:47 EDT
is it like a reformat, or just a different view of the file?
Comment 2 Xavier Méhaut CLA 2002-04-26 10:44:49 EDT
I think it is like a reformat feature applied on all the source file. It is 
rearranging all the methods and variables. Example :

I had :
public void toto(...
public void albert(...
public void zozo(...

I would like to have after the processing :
public void albert
public void toto
public void zozo

Comment 3 Erich Gamma CLA 2002-05-02 19:54:11 EDT
agreed, that this is a useful formatting option. Some Java formatters provide 
this kind of support - not for 2.0
Comment 4 Dirk Baeumer CLA 2002-07-23 13:02:22 EDT
Reopening
Comment 5 Dirk Baeumer CLA 2002-07-23 13:05:59 EDT
Will the new formatter consider this
Comment 6 Philipe Mulet CLA 2002-07-25 08:20:06 EDT
*** Bug 20253 has been marked as a duplicate of this bug. ***
Comment 7 Adam Kiezun CLA 2002-08-28 04:52:49 EDT
*** Bug 22897 has been marked as a duplicate of this bug. ***
Comment 8 Carl Rosenberger CLA 2002-09-14 06:58:28 EDT
I would really love to see this one also since I prefer to order my methods in 
alphabetical order. A suggestion for a very fast and easy implementation of the 
GUI for it:
Simply add the setting "oder methods alphabetically" in the
Java + Code Formatter preferences.
Carl
Comment 9 Olivier Thomann CLA 2002-11-05 16:57:25 EST
*** Bug 23209 has been marked as a duplicate of this bug. ***
Comment 10 Gunnar Wagenknecht CLA 2002-11-06 00:03:10 EST
Another solution maybe to sort the methodes like defined in the preferences. 
You can configure the order for the outline view. Simply use this settings.

It should go into 2.1
Comment 11 Olivier Thomann CLA 2002-11-06 08:07:44 EST
I disagree. The formatter doesn't have any knowledge about the outliner. We 
might add a option to sort alphabetically the body declarations inside a type, 
but I don't see why we would rely on some outliner settings.
Comment 12 Gunnar Wagenknecht CLA 2002-11-06 11:20:56 EST
Well, I not really mean the outliner.

There are settings for the member sort order. Go to "Window->Preferences->Java-
>Appearance->Member Sort Order".

The Code Formatter should use this settings if the user wants it. Thus, there 
is no need to add an additional preference page. 

Or simply ignore that and only provide alphabetical ordering (statics first).

Comment 13 Olivier Thomann CLA 2002-11-06 11:42:54 EST
The new formatter I am working on has much more options than the actual one. 
Therefore we might need to change the preference page of the formatter and this 
is a good thing to add on this preference page. For me the appearance and the 
code formatting need to be clearly separated. A code formatter can be provided 
through an extension point and therefore we cannot make any assumption on the 
formatter option through a different preference page.
Comment 14 Gunnar Wagenknecht CLA 2002-11-06 11:46:51 EST
ACK. Didn't know about your design.
Comment 15 Olivier Thomann CLA 2003-01-15 13:28:59 EST
*** Bug 26426 has been marked as a duplicate of this bug. ***
Comment 16 Olivier Thomann CLA 2003-01-15 13:33:40 EST
*** Bug 13538 has been marked as a duplicate of this bug. ***
Comment 17 Gunnar Wagenknecht CLA 2003-01-15 13:43:48 EST
Will this be in M5?
Comment 18 Olivier Thomann CLA 2003-01-15 13:48:46 EST
I don't know. The code needs to be integrated within the Java core operations. 
I will release it as soon as we have something reliable enough. When the 
support is ready on the JDT/Core side, we still need to add it on the JDT/UI 
side. So I really don't know if this will be ready in time for 2.1 M5.
Comment 19 Olivier Thomann CLA 2003-01-27 11:57:01 EST
The code is released on the JDT/Core side.
See the new org.eclipse.code.util.CompilationUnitSorter. The corresponding
javadoc might be improved in the next integration build, but the implementation
is pretty stable.
Fixed and released in 2.1 stream. Regression tests added.

Move to JDT/UI for adding the proper UI for this new API.
I think we need:
1) A way to map the actual sorting in the outliner with the new API. If I sort
the outliner contents I should end up with the same result after sorting using
this new API and the default comparator properly initialized (categories values).
2) Provide more predefined comparators (visibility, syntactical order, ...)
3) A new action on IJavaProject, IPackageFragmentRoot, IPackageFragment,
ICompilationUnit, on the compilation unit editor.
Comment 20 Dirk Baeumer CLA 2003-01-27 12:02:29 EST
Martin, you know best what to do.
Comment 21 Olivier Thomann CLA 2003-01-28 14:32:37 EST
Working with Jim on the javadoc, we realized that we might need to slightly
change the API. Instead of working on ICompilationUnit, it is more flexible to
work on IWorkingCopy. So the API might change from using ICompilationUnit[] to
IJavaElement[] which will be required to be working copies. Please defer any
work on the UI side till we completely finalize this API.
NOTE: You might want to prepare all the UI actions anyway.
Comment 22 Olivier Thomann CLA 2003-01-28 14:33:40 EST
Move back to JDT/Core till the API is clearly specified.
Comment 23 Martin Aeschlimann CLA 2003-01-29 03:09:28 EST
ICompilationUnit is an IWorkingCopy, so I don't think there is a change needed.
Comment 24 Jim des Rivieres CLA 2003-01-31 12:57:44 EST
The API is as follows:

package org.eclipse.jdt.core.util;
public final class CompilationUnitSorter {
	public static final String RELATIVE_ORDER = "relativeOrder";
	public static void sort(ICompilationUnit compilationUnit,
	        int[] positions,
	        Comparator comparator,
	        int options,
	        IProgressMonitor monitor) throws JavaModelException;
}

We opted to not provide any standard implementation of a Comparator at
this time because it's difficult to come up with anything of long-term
API value. The DefaultJavaElementComparator from previous iterations of the
API will be moving up into the JDT UI, but not as API. This arrangement will 
allow us to expose a new action for 2.1 based on existing "Window->Preferences-
>Java->Appearance->Member Sort Order", which we can easily evolve and improve 
in subsequent releases. The options parameter on the sort API method allows 
the functionality to be expanded in a non-breaking way.
Comment 25 Olivier Thomann CLA 2003-01-31 13:14:04 EST
Fixed and released in 2.1 stream.
Regression test added.
Comment 26 David Audel CLA 2003-02-11 07:11:52 EST
Verified.
Comment 27 Shane Cartledge CLA 2003-06-20 17:47:15 EDT
Bugzilla Bug 13538
   Would like to move fields together (and to the top)

was marked as a duplicate (subset) of this Bugzilla Bug.

I can not, however, find an option to move fields together at the top of a 
source file. Can you please provide additional information regarding how 
Bugzilla Bug 13538 was fixed?
Comment 28 Olivier Thomann CLA 2003-06-23 08:58:55 EDT
If you go in:
Preferences>Java>Appearance>Members Sort Order you can set where you want the 
fields to be.
Then select the compilation unit you want to sort, Right click>Source>Sort 
Members should do the job.