use of org.eclipse.text.edits.InsertEdit in project eclipse.jdt.ls by eclipse.
the class ChangeUtilTest method testConvertSimpleCompositeChange.
// Composite Changes
@Test
public void testConvertSimpleCompositeChange() throws CoreException {
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
ICompilationUnit cu = pack1.createCompilationUnit("E.java", "", false, null);
CompositeChange change = new CompositeChange("simple composite change");
RenameCompilationUnitChange resourceChange = new RenameCompilationUnitChange(cu, "ENew.java");
change.add(resourceChange);
CompilationUnitChange textChange = new CompilationUnitChange("insertText", cu);
textChange.setEdit(new InsertEdit(0, "// some content"));
change.add(textChange);
WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(change);
assertEquals(edit.getDocumentChanges().size(), 2);
assertTrue(edit.getDocumentChanges().get(0).getRight() instanceof RenameFile);
assertTrue(edit.getDocumentChanges().get(1).getLeft() instanceof TextDocumentEdit);
}
use of org.eclipse.text.edits.InsertEdit in project eclipse.jdt.ls by eclipse.
the class CompletionHandlerTest method testSkipAdditionalEditForImport.
@Test
public void testSkipAdditionalEditForImport() throws JavaModelException, MalformedTreeException, BadLocationException {
// @formatter:off
ICompilationUnit unit = getWorkingCopy("src/org/sample/Test.java", "package org.sample;\n" + "import " + "public class Test {\n" + "}");
// @formatter:on
// mock the user's input behavior
int startOffset = JsonRpcHelpers.toOffset(unit.getBuffer(), 1, 7);
InsertEdit edit = new InsertEdit(startOffset, "j");
IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
edit.apply(document, org.eclipse.text.edits.TextEdit.NONE);
CompletionList list = requestCompletions(unit, "import j");
assertNotNull(list);
List<CompletionItem> items = new ArrayList<>(list.getItems());
CompletionItem item = items.get(0);
CompletionItem resolved = server.resolveCompletionItem(item).join();
assertNull(resolved.getAdditionalTextEdits());
}
use of org.eclipse.text.edits.InsertEdit in project erlide_eclipse by erlang.
the class ChangesetMaker method createReplaceEdit.
/**
* Creates a <code>ReplaceEdit</code> object from the given parameters and the stored
* input/output strings.
*
* @param addedStart
* @param addedEnd
* @param deletedStart
* @param deletedEnd
* @return
*/
private static TextEdit createReplaceEdit(final int addedStart, final int addedEnd, final int deletedStart, final int deletedEnd) {
final TextEdit result = new MultiTextEdit();
final int addedLength = addedEnd - addedStart + 1;
final int deletedLength = deletedEnd - deletedStart + 1;
final int minLength = Math.min(addedLength, deletedLength);
if (deletedLength < addedLength) {
result.addChild(new InsertEdit(deletedStart + minLength, ChangesetMaker.getString(addedStart + minLength, addedEnd)));
}
result.addChild(new ReplaceEdit(deletedStart, minLength, ChangesetMaker.getString(addedStart, addedStart + minLength - 1)));
if (addedLength < deletedLength) {
result.addChild(new DeleteEdit(deletedStart + minLength, deletedLength - minLength));
}
return result;
}
Aggregations