|
Eclipse JDT Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jdt.core.util.CompilationUnitSorter
Operation for sorting members within a compilation unit.
This class provides all functionality via static members; it is not intended to be instantiated or subclassed.
Field Summary | |
static String |
RELATIVE_ORDER
Name of auxillary property whose value can be used to determine the original relative order of two body declarations. |
Method Summary | |
static void |
sort(ICompilationUnit compilationUnit,
int[] positions,
Comparator comparator,
int options,
IProgressMonitor monitor)
Reorders the declarations in the given compilation unit. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String RELATIVE_ORDER
All body declarations passed to the comparator's compare
method by CompilationUnitSorter.sort
carry an
Integer-valued property. The body declaration with the lower value
comes before the one with the higher value. The exact numeric value
of these properties is unspecified.
Example usage:
BodyDeclaration b1 = (BodyDeclaration) object1; BodyDeclaration b2 = (BodyDeclaration) object2; Integer i1 = (Integer) b1.getProperty(RELATIVE_ORDER); Integer i2 = (Integer) b2.getProperty(RELATIVE_ORDER); return i1.intValue() - i2.intValue(); // preserve original order
sort(ICompilationUnit, int[], Comparator, int, IProgressMonitor)
,
BodyDeclaration
,
Constant Field ValuesMethod Detail |
public static void sort(ICompilationUnit compilationUnit, int[] positions, Comparator comparator, int options, IProgressMonitor monitor) throws JavaModelException
Note: Reordering the members within a type declaration might be more than a cosmetic change and could have potentially serious repercussions. Firstly, the order in which the fields of a type are initialized is significant in the Java language; reordering fields and initializers may result in compilation errors or change the execution behavior of the code. Secondly, reordering a class's members may affect how its instances are serialized. This operation should therefore be used with caution and due concern for potential negative side effects.
The optional positions
array contains a non-decreasing
ordered list of character-based source positions within the compilation
unit's source code string. Upon return from this method, the positions in
the array reflect the corresponding new locations in the modified source
code string, Note that this operation modifies the given array in place.
The compare
method of the given comparator is passed pairs
of AST body declarations (subclasses of BodyDeclaration
)
representing body declarations at the same level. The comparator is
called on body declarations of nested classes, including anonymous and
local classes, but always at the same level. Clients need to provide
a comparator implementation (there is no standard comparator). The
RELATIVE_ORDER
property attached to these AST nodes afforts
the comparator a way to preserve the original relative order.
The body declarations passed as parameters to the comparator
always carry at least the following minimal signature information:
TypeDeclaration |
modifiers, isInterface, name, superclass,
superInterfaces |
FieldDeclaration |
modifiers, type, fragments
(VariableDeclarationFragments
with name only) |
MethodDeclaration |
modifiers, isConstructor, returnType, name,
parameters
(SingleVariableDeclarations with name and type only),
thrownExceptions |
Initializer |
modifiers |
compilationUnit
- the given compilation unit, which must be a
working copypositions
- an array of source positions to map, or
null
if none. If supplied, the positions must
character-based source positions within the original source code for
the given compilation unit, arranged in non-decreasing order.
The array is updated in place when this method returns to reflect the
corresponding source positions in the permuted source code string
(but not necessarily any longer in non-decreasing order).comparator
- the comparator capable of ordering
BodyDeclaration
soptions
- bitwise-or of option flags; 0
for default
behavior (reserved for future growth)monitor
- the progress monitor to notify, or null
if
none
JavaModelException
- if the compilation unit could not be
sorted. Reasons include:
CoreException
occurred while accessing the underlying
resource
IllegalArgumentException
- if the given compilation unit is null
or if the given comparator is null.BodyDeclaration
,
RELATIVE_ORDER
|
Eclipse JDT Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |