}
return true;
}
});
final ASTRewrite rewriter= ASTRewrite.create(ast.getAST());
final boolean[] hasChanges= new boolean[] {false};
ast.accept(new ASTVisitor() {
private void sortElements(List elements, ListRewrite listRewrite) {
if (elements.size() == 0)
return;
final List myCopy = new ArrayList();
myCopy.addAll(elements);
Collections.sort(myCopy, SortElementsOperation.this.comparator);
for (int i = 0; i < elements.size(); i++) {
ASTNode oldNode= (ASTNode) elements.get(i);
ASTNode newNode= (ASTNode) myCopy.get(i);
if (oldNode != newNode) {
listRewrite.replace(oldNode, rewriter.createMoveTarget(newNode), group);
hasChanges[0]= true;
}
}
}
public boolean visit(org.eclipse.jdt.core.dom.CompilationUnit compilationUnit) {
if (checkMalformedNodes(compilationUnit)) {
return true; // abort sorting of current element
}
sortElements(compilationUnit.types(), rewriter.getListRewrite(compilationUnit, org.eclipse.jdt.core.dom.CompilationUnit.TYPES_PROPERTY));
return true;
}
public boolean visit(AnnotationTypeDeclaration annotationTypeDeclaration) {
if (checkMalformedNodes(annotationTypeDeclaration)) {
return true; // abort sorting of current element
}
sortElements(annotationTypeDeclaration.bodyDeclarations(), rewriter.getListRewrite(annotationTypeDeclaration, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY));
return true;
}
public boolean visit(AnonymousClassDeclaration anonymousClassDeclaration) {
if (checkMalformedNodes(anonymousClassDeclaration)) {
return true; // abort sorting of current element
}
sortElements(anonymousClassDeclaration.bodyDeclarations(), rewriter.getListRewrite(anonymousClassDeclaration, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY));
return true;
}
public boolean visit(TypeDeclaration typeDeclaration) {
if (checkMalformedNodes(typeDeclaration)) {
return true; // abort sorting of current element
}
sortElements(typeDeclaration.bodyDeclarations(), rewriter.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY));
return true;
}
public boolean visit(EnumDeclaration enumDeclaration) {
if (checkMalformedNodes(enumDeclaration)) {
return true; // abort sorting of current element
}
sortElements(enumDeclaration.bodyDeclarations(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.BODY_DECLARATIONS_PROPERTY));
sortElements(enumDeclaration.enumConstants(), rewriter.getListRewrite(enumDeclaration, EnumDeclaration.ENUM_CONSTANTS_PROPERTY));
return true;
}
});
if (!hasChanges[0])