use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testSourceTransformationIncludes.
@Test
public void testSourceTransformationIncludes() throws Exception {
MoveSourceEdit ms = new MoveSourceEdit(2, 4);
MoveTargetEdit mt = new MoveTargetEdit(9, ms);
fRoot.addChild(ms);
fRoot.addChild(mt);
RangeMarker r1 = new RangeMarker(3, 2);
ms.addChild(r1);
ms.setSourceModifier(new ISourceModifier() {
@Override
public ISourceModifier copy() {
return this;
}
@Override
public ReplaceEdit[] getModifications(String source) {
return new ReplaceEdit[] { new ReplaceEdit(1, 1, "aa") };
}
});
fRoot.apply(fDocument);
String result = "016782aa459";
Assert.assertEquals("Buffer content", result, fDocument.get());
assertEquals(r1, 6, 3);
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testOverlap1.
@Test
public void testOverlap1() throws Exception {
// [ [ ] ]
fRoot.addChild(new ReplaceEdit(0, 2, "01"));
boolean exception = false;
try {
fRoot.addChild(new ReplaceEdit(1, 2, "12"));
} catch (MalformedTreeException e) {
exception = true;
}
assertTrue(exception);
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testMove4.
@Test
public void testMove4() throws Exception {
MoveSourceEdit s1 = new MoveSourceEdit(7, 2);
MoveTargetEdit t1 = new MoveTargetEdit(2, s1);
TextEdit e2 = new ReplaceEdit(5, 1, "x");
fRoot.addChild(s1);
fRoot.addChild(t1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
Assert.assertEquals("Buffer content", "0178234x69", fDocument.get());
assertEquals(s1, 9, 0);
assertEquals(t1, 2, 2);
assertEquals(e2, 7, 1);
doUndoRedo(undo, "0178234x69");
}
use of org.eclipse.text.edits.ReplaceEdit in project eclipse.platform.text by eclipse.
the class ConvertLineDelimitersOperation method computeTextEdit.
@Override
protected MultiTextEditWithProgress computeTextEdit(ITextFileBuffer fileBuffer, IProgressMonitor progressMonitor) throws CoreException {
IDocument document = fileBuffer.getDocument();
int lineCount = document.getNumberOfLines();
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, FileBuffersMessages.ConvertLineDelimitersOperation_task_generatingChanges, lineCount);
try {
MultiTextEditWithProgress multiEdit = new MultiTextEditWithProgress(FileBuffersMessages.ConvertLineDelimitersOperation_task_applyingChanges);
for (int i = 0; i < lineCount; i++) {
final String delimiter = document.getLineDelimiter(i);
if (delimiter != null && delimiter.length() > 0 && !delimiter.equals(fLineDelimiter)) {
IRegion region = document.getLineInformation(i);
multiEdit.addChild(new ReplaceEdit(region.getOffset() + region.getLength(), delimiter.length(), fLineDelimiter));
}
subMonitor.split(1);
}
return multiEdit.getChildrenSize() <= 0 ? null : multiEdit;
} catch (BadLocationException x) {
// $NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CONTENT_CHANGE_FAILED, "", x));
}
}
use of org.eclipse.text.edits.ReplaceEdit in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class MyQuickFix method modifyAST.
@Override
public void modifyAST(IIndex index, IMarker marker) {
try {
@SuppressWarnings("unused") IASTTranslationUnit ast = getTranslationUnitViaEditor(marker).getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
// a real test should use ModificationCollector/ASTRewrite or Refactoring here.
// For testing purposes, we only replace some text directly.
TextFileChange change = new TextFileChange("rename foo to bar text edit", (IFile) marker.getResource());
change.setEdit(new ReplaceEdit(4, 3, "bar"));
change.perform(new NullProgressMonitor());
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
Aggregations