* Method processElement.
* @param unit
* @param source
*/
private String processElement(ICompilationUnit unit, char[] source) {
Document document = new Document(new String(source));
CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
ASTParser parser = ASTParser.newParser(this.apiLevel);
parser.setCompilerOptions(options.getMap());
parser.setSource(source);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(false);
org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit ast = (org.aspectj.org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
ASTRewrite rewriter= sortCompilationUnit(ast, null);
if (rewriter == null)
return document.get();
TextEdit edits = rewriter.rewriteAST(document, null);
RangeMarker[] markers = null;
if (this.positions != null) {
markers = new RangeMarker[this.positions.length];
for (int i = 0, max = this.positions.length; i < max; i++) {
markers[i]= new RangeMarker(this.positions[i], 0);
insert(edits, markers[i]);
}
}
try {
edits.apply(document, TextEdit.UPDATE_REGIONS);
if (this.positions != null) {
for (int i= 0, max = markers.length; i < max; i++) {
this.positions[i]= markers[i].getOffset();
}
}
} catch (BadLocationException e) {
// ignore
}
return document.get();
}