views:

87

answers:

1

I implemented an eclipse quick fix to change a block of code.

I'm using something like this to save my changes:

TextEdit edits = rewrite.rewriteAST();
UndoEdit undo = edits.apply(document);

But when i undo my changes (CTRL+Z), i have to step through all the TextEdit actions one by one.
Is there a way to group them so the quick fix is rolled back in a single step?

A: 

I'm just guessing, but I think the MultiTextEdit class is what you want here. You can search for an example of how it's used, but I think this example might be good:

    private void applyTransformation(IDocument document) throws MalformedTreeException {
 TextEdit newEdit= new MultiTextEdit(0, document.getLength());
 ReplaceEdit[] replaces= fModifier.getModifications(document.get());
 for (int i= 0; i < replaces.length; i++) {
  newEdit.addChild(replaces[i]);
 }
 try {
  newEdit.apply(document, TextEdit.NONE);
 } catch (BadLocationException cannotHappen) {
  Assert.isTrue(false);
 }
}
Francis Upton
Sorry, that's not it. The ASTRewrite is already giving me a MultiTextEdit and encapsulating it seems to do nothing. So in a way i want the opposite of a MultiTextEdit, i.e. an edit that that behaves like a singular change even though it contains several edits.
Stroboskop
Bummer, as I said, it was just a guess, you might want to post on the Platform newsgroup for Eclipse; the Platform Text committers look at that and should be able to give you an answer. Alternatively, you can try to debug it. Should not be too hard.
Francis Upton