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

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




Back to the top