use of org.eclipse.text.edits.MultiTextEdit in project che by eclipse.
the class TextChange method createTextEditProcessor.
private TextEditProcessor createTextEditProcessor(IDocument document, int flags, TextEditBasedChangeGroup[] changes) {
if (fEdit == null)
return new TextEditProcessor(document, new MultiTextEdit(0, 0), flags);
List includes = new ArrayList(0);
for (int c = 0; c < changes.length; c++) {
TextEditBasedChangeGroup change = changes[c];
Assert.isTrue(change.getTextEditChange() == this);
if (change.isEnabled()) {
includes.addAll(Arrays.asList(change.getTextEditGroup().getTextEdits()));
}
}
fCopier = new TextEditCopier(fEdit);
TextEdit copiedEdit = fCopier.perform();
boolean keep = getKeepPreviewEdits();
if (keep)
flags = flags | TextEdit.UPDATE_REGIONS;
LocalTextEditProcessor result = new LocalTextEditProcessor(document, copiedEdit, flags);
result.setIncludes(mapEdits((TextEdit[]) includes.toArray(new TextEdit[includes.size()]), fCopier));
if (!keep)
fCopier = null;
return result;
}
use of org.eclipse.text.edits.MultiTextEdit in project eclipse.platform.text by eclipse.
the class ReplaceRefactoring method createFileChange.
private TextChange createFileChange(IFile file, Pattern pattern, Set<FileMatch> matches, RefactoringStatus resultingStatus, Collection<MatchGroup> matchGroups) throws PatternSyntaxException, CoreException {
PositionTracker tracker = InternalSearchUI.getInstance().getPositionTracker();
TextFileChange change = new TextFileChange(Messages.format(SearchMessages.ReplaceRefactoring_group_label_change_for_file, file.getName()), file);
change.setEdit(new MultiTextEdit());
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(file.getFullPath(), LocationKind.IFILE, null);
try {
ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (textFileBuffer == null) {
resultingStatus.addError(Messages.format(SearchMessages.ReplaceRefactoring_error_accessing_file_buffer, file.getName()));
return null;
}
IDocument document = textFileBuffer.getDocument();
String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);
for (FileMatch match : matches) {
int offset = match.getOffset();
int length = match.getLength();
Position currentPosition = tracker.getCurrentPosition(match);
if (currentPosition != null) {
offset = currentPosition.offset;
if (length != currentPosition.length) {
resultingStatus.addError(Messages.format(SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
continue;
}
}
String originalText = getOriginalText(document, offset, length);
if (originalText == null) {
resultingStatus.addError(Messages.format(SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
continue;
}
String replacementString = PatternConstructor.interpretReplaceEscapes(fReplaceString, originalText, lineDelimiter);
replacementString = computeReplacementString(pattern, document, offset, replacementString);
if (replacementString == null) {
resultingStatus.addError(Messages.format(SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
continue;
}
ReplaceEdit replaceEdit = new ReplaceEdit(offset, length, replacementString);
change.addEdit(replaceEdit);
TextEditChangeGroup textEditChangeGroup = new TextEditChangeGroup(change, new TextEditGroup(SearchMessages.ReplaceRefactoring_group_label_match_replace, replaceEdit));
change.addTextEditChangeGroup(textEditChangeGroup);
matchGroups.add(new MatchGroup(textEditChangeGroup, match));
}
} finally {
manager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
}
return change;
}
use of org.eclipse.text.edits.MultiTextEdit in project eclipse.platform.text by eclipse.
the class DocumentUndoManagerTest method testCompoundTextEdit.
public void testCompoundTextEdit() throws ExecutionException, BadLocationException {
final int RANDOM_STRING_LENGTH = 50;
final int RANDOM_REPLACE_COUNT = 100;
assertTrue(RANDOM_REPLACE_COUNT >= 1);
assertTrue(RANDOM_REPLACE_COUNT <= MAX_UNDO_LEVEL);
String original = createRandomString(RANDOM_STRING_LENGTH);
final IDocument document = new Document(original);
createUndoManager(document);
// fUndoManager.beginCompoundChange();
MultiTextEdit fRoot = new MultiTextEdit();
TextEdit e1 = new DeleteEdit(3, 1);
fRoot.addChild(e1);
fRoot.apply(document);
fRoot = new MultiTextEdit();
TextEdit e2 = new DeleteEdit(3, 1);
fRoot.addChild(e2);
fRoot.apply(document);
// fUndoManager.endCompoundChange();
assertTrue(fUndoManager.undoable());
// while (fUndoManager.undoable())
fUndoManager.undo();
assertTrue(!fUndoManager.undoable());
final String reverted = document.get();
assertEquals(original, reverted);
}
use of org.eclipse.text.edits.MultiTextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testUndefinedMultiEdit5.
@Test
public void testUndefinedMultiEdit5() throws Exception {
MultiTextEdit m2 = new MultiTextEdit();
m2.addChild(new DeleteEdit(4, 2));
m2.addChild(new DeleteEdit(1, 3));
Assert.assertEquals(1, m2.getOffset());
Assert.assertEquals(5, m2.getLength());
}
use of org.eclipse.text.edits.MultiTextEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testCopy1.
@Test
public void testCopy1() throws Exception {
MultiTextEdit root = new MultiTextEdit();
TextEdit e1 = new InsertEdit(2, "yy");
TextEdit e2 = new ReplaceEdit(2, 3, "3456");
root.addChild(e1);
root.addChild(e2);
List<TextEdit> org = flatten(root);
TextEditCopier copier = new TextEditCopier(root);
List<TextEdit> copy = flatten(copier.perform());
compare(org, copy);
}
Aggregations