use of org.eclipse.lsp4j.ResourceOperation in project eclipse.jdt.ls by eclipse.
the class MoveHandlerTest method testMoveInnerTypeToFile.
@Test
public void testMoveInnerTypeToFile() throws Exception {
System.setProperty("line.separator", "\n");
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
// @formatter:off
ICompilationUnit cu = pack1.createCompilationUnit("Top.java", "package test1;\n" + "\n" + "public class Top {\n" + " String name;\n\n" + " public class Inner {\n" + " public void print() {\n" + " System.out.println(Top.this.name);\n" + " }\n" + " }\n" + "}", false, null);
// @formatter:on
CodeActionParams params = CodeActionUtil.constructCodeActionParams(cu, "class Inner");
RefactorWorkspaceEdit refactorEdit = MoveHandler.move(new MoveParams("moveTypeToNewFile", params, "Foo", true), new NullProgressMonitor());
assertNotNull(refactorEdit);
assertNotNull(refactorEdit.edit);
List<Either<TextDocumentEdit, ResourceOperation>> changes = refactorEdit.edit.getDocumentChanges();
assertEquals(3, changes.size());
// @formatter:off
String expected = "package test1;\n" + "\n" + "public class Top {\n" + " String name;\n" + "}";
// @formatter:on
TextDocumentEdit textEdit = changes.get(0).getLeft();
assertNotNull(textEdit);
assertEquals(expected, TextEditUtil.apply(cu.getSource(), textEdit.getEdits()));
ResourceOperation resourceOperation = changes.get(1).getRight();
assertNotNull(resourceOperation);
assertTrue(resourceOperation instanceof CreateFile);
assertEquals(ResourceUtils.fixURI(cu.getResource().getRawLocationURI()).replace("Top", "Inner"), ((CreateFile) resourceOperation).getUri());
// @formatter:off
expected = "package test1;\n" + "\n" + "public class Inner {\n" + " /**\n" + " *\n" + " */\n" + " private final Top top;\n\n" + " /**\n" + " * @param top\n" + " */\n" + " Inner(Top top) {\n" + " this.top = top;\n" + " }\n\n" + " public void print() {\n" + " System.out.println(this.top.name);\n" + " }\n" + "}";
// @formatter:on
textEdit = changes.get(2).getLeft();
assertNotNull(textEdit);
assertEquals(expected, TextEditUtil.apply(pack1.getCompilationUnit("Inner.java").getWorkingCopy(null), textEdit.getEdits()));
}
use of org.eclipse.lsp4j.ResourceOperation in project eclipse.jdt.ls by eclipse.
the class ReorgQuickFixTest method assertRenameFileOperation.
private void assertRenameFileOperation(Either<Command, CodeAction> codeAction, String newUri) {
WorkspaceEdit edit = getWorkspaceEdit(codeAction);
List<Either<TextDocumentEdit, ResourceOperation>> documentChanges = edit.getDocumentChanges();
assertNotNull(documentChanges);
assertEquals(1, documentChanges.size());
ResourceOperation resourceOperation = documentChanges.get(0).getRight();
assertNotNull(resourceOperation);
assertTrue(resourceOperation instanceof RenameFile);
assertEquals(newUri, ((RenameFile) resourceOperation).getNewUri());
}
Aggregations