Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-core-dev] Sort members of a compilation unit

I think I was not very clear with the java element comparator.

For now the comparator gives me preferences. Like Philippe said, in this
case we might want to move this as JavaCore preferences. Therefore we don't
need a comparator anymore and the API would simply take a IProgressMonitor.

For you second point, I didn't think this could be useful. I tried to map
the sorting feature in the outliner. So what I have done so far is:
1) sort according to the type (static fields, static methods, methods,
....)
2) When the type is identical, use the alphabetic order.

Clearly this second part should be improve. I could provide an
java.util.Comparator. But this would not help to know which order the
second part should apply. Ideally I'd like a simple way to describe which
order needs to be applied.

Olivier



                                                                                                                                                     
                      "Martin                                                                                                                        
                      Aeschlimann"               To:       <jdt-core-dev@xxxxxxxxxxx>                                                                
                      <Martin_Aeschlimann        cc:                                                                                                 
                      @oti.com>                  Subject:  Re: [jdt-core-dev] Sort members of a compilation unit                                     
                      Sent by:                                                                                                                       
                      jdt-core-dev-admin@                                                                                                            
                      eclipse.org                                                                                                                    
                                                                                                                                                     
                                                                                                                                                     
                      01/16/03 12:03 PM                                                                                                              
                      Please respond to                                                                                                              
                      jdt-core-dev                                                                                                                   
                                                                                                                                                     
                                                                                                                                                     




Would that be a Comparator like in the Java class libraries where the user
has to implement the 'int compare(member1, member2)' method?

After sorting by member type (filed/ static filed, constructor...), can the
user also decide on how members of the same kind are sorted (by name or
maybe by visibility ect.).

Martin


Hi,

In order to add this feature, we propose the following API on

ICompilationUnit. The idea is to be able to sort all members in a

compilation unit using a comparator. It would also sort members of members

and so on. It will issue delta for the compilation unit if its contents has

been changed.

public void sort(JavaElementComparator comparator, IProgressMonitor

monitor) throws JavaModelException;

The JavaElementComparator would be used to find out the order in which you

want the members to be. For now I have the following entries:

- type order (for member type)

- static initializer

- initializer

- static field

- field

- static method

- method

- constructor

This class could simply return a map containing its preferences. we can

have constants for each preference:

public static final String SORTING_TYPE_ORDER = JavaCore.PLUGIN_ID +

".sorting.type.order"; //$NON-NLS-1$

public static final String SORTING_STATIC_INITIALIZER_ORDER =

JavaCore.PLUGIN_ID + ".sorting.static_initializer.order"; //$NON-NLS-1$

public static final String SORTING_INITIALIZER_ORDER =

JavaCore.PLUGIN_ID + ".sorting.initializer.order"; //$NON-NLS-1$

public static final String SORTING_STATIC_FIELD_ORDER =

JavaCore.PLUGIN_ID + ".sorting.static_field.order"; //$NON-NLS-1$

public static final String SORTING_FIELD_ORDER = JavaCore.PLUGIN_ID +

".sorting.field.order"; //$NON-NLS-1$

public static final String SORTING_STATIC_METHOD_ORDER =

JavaCore.PLUGIN_ID + ".sorting.static_method.order"; //$NON-NLS-1$

public static final String SORTING_METHOD_ORDER = JavaCore.PLUGIN_ID

+ ".sorting.method.order"; //$NON-NLS-1$

public static final String SORTING_CONSTRUCTOR_ORDER =

JavaCore.PLUGIN_ID + ".sorting.constructor.order"; //$NON-NLS-1$

And constants for each position:

public static final String SORTING_ORDER_FIRST = "1"; //$NON-NLS-1$

public static final String SORTING_ORDER_SECOND = "2"; //$NON-NLS-1$

public static final String SORTING_ORDER_THIRD = "3"; //$NON-NLS-1$

public static final String SORTING_ORDER_FOURTH = "4"; //$NON-NLS-1$

public static final String SORTING_ORDER_FIFTH = "5"; //$NON-NLS-1$

public static final String SORTING_ORDER_SIXTH = "6"; //$NON-NLS-1$

public static final String SORTING_ORDER_SEVENTH = "7"; //$NON-NLS-1$

public static final String SORTING_ORDER_EIGHTH = "8"; //$NON-NLS-1$

Any suggestion? Comment?

Thanks,

Olivier


_______________________________________________
jdt-core-dev mailing list
jdt-core-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/jdt-core-dev






Back to the top