org.eclipse.lsp4j.RenameFile Java Examples

The following examples show how to use org.eclipse.lsp4j.RenameFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void convertMoveCompilationUnitChange(WorkspaceEdit edit, MoveCompilationUnitChange change) throws JavaModelException {
	IPackageFragment newPackage = change.getDestinationPackage();
	ICompilationUnit unit = change.getCu();
	CompilationUnit astCU = RefactoringASTParser.parseWithASTProvider(unit, true, new NullProgressMonitor());
	ASTRewrite rewrite = ASTRewrite.create(astCU.getAST());

	IPackageDeclaration[] packDecls = unit.getPackageDeclarations();
	String oldPackageName = packDecls.length > 0 ? packDecls[0].getElementName() : "";
	if (!Objects.equals(oldPackageName, newPackage.getElementName())) {
		// update the package declaration
		if (updatePackageStatement(astCU, newPackage.getElementName(), rewrite, unit)) {
			convertTextEdit(edit, unit, rewrite.rewriteAST());
		}
	}

	RenameFile cuResourceChange = new RenameFile();
	cuResourceChange.setOldUri(JDTUtils.toURI(unit));
	IPath newCUPath = newPackage.getResource().getLocation().append(unit.getPath().lastSegment());
	String newUri = ResourceUtils.fixURI(newCUPath.toFile().toURI());
	cuResourceChange.setNewUri(newUri);
	edit.getDocumentChanges().add(Either.forRight(cuResourceChange));
}
 
Example #2
Source File: ChangeUtilTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testConvertRenameCompilationUnitChange() throws CoreException {
	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", "", false, null);
	String newName = "ENew.java";
	RenameCompilationUnitChange change = new RenameCompilationUnitChange(cu, newName);
	String oldUri = JDTUtils.toURI(cu);
	String newUri = ResourceUtils.fixURI(URI.create(oldUri).resolve(newName));

	WorkspaceEdit edit = ChangeUtil.convertToWorkspaceEdit(change);

	assertEquals(edit.getDocumentChanges().size(), 1);

	ResourceOperation resourceOperation = edit.getDocumentChanges().get(0).getRight();
	assertTrue(resourceOperation instanceof RenameFile);

	assertEquals(((RenameFile) resourceOperation).getOldUri(), oldUri);
	assertEquals(((RenameFile) resourceOperation).getNewUri(), newUri);
}
 
Example #3
Source File: ChangeUtilTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: ChangeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static void convertCUResourceChange(WorkspaceEdit edit, RenameCompilationUnitChange cuChange) {
	ICompilationUnit modifiedCU = (ICompilationUnit) cuChange.getModifiedElement();
	RenameFile rf = new RenameFile();
	String newCUName = cuChange.getNewName();
	IPath currentPath = modifiedCU.getResource().getLocation();
	rf.setOldUri(ResourceUtils.fixURI(modifiedCU.getResource().getRawLocationURI()));
	IPath newPath = currentPath.removeLastSegments(1).append(newCUName);
	rf.setNewUri(ResourceUtils.fixURI(newPath.toFile().toURI()));
	edit.getDocumentChanges().add(Either.forRight(rf));
}
 
Example #5
Source File: ReorgQuickFixTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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());
}
 
Example #6
Source File: ResourceOperationTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter out, ResourceOperation value) throws IOException {
	if (value.getClass().isAssignableFrom(CreateFile.class)) {
		createFileAdapter.write(out, (CreateFile) value);
	} else if (value.getClass().isAssignableFrom(DeleteFile.class)) {
		deleteFileAdapter.write(out, (DeleteFile) value);
	} else if (value.getClass().isAssignableFrom(RenameFile.class)) {
		renameFileAdapter.write(out, (RenameFile) value);
	}
}
 
Example #7
Source File: UtilsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testApplyChanges() throws Exception {
    clearWorkDir();
    FileObject wd = FileUtil.toFileObject(getWorkDir());
    FileObject sourceFile1 = wd.createData("Test1.txt");
    try (OutputStream out = sourceFile1.getOutputStream()) {
        out.write(("0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n").getBytes("UTF-8"));
    }
    FileObject sourceFile2 = wd.createData("Test2.txt");
    try (OutputStream out = sourceFile2.getOutputStream()) {
        out.write(("0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n" +
                   "0123456789\n").getBytes("UTF-8"));
    }
    FileObject sourceFile3 = wd.createData("Test3.txt");
    WorkspaceEdit edit = new WorkspaceEdit(Arrays.asList(Either.forLeft(new TextDocumentEdit(new VersionedTextDocumentIdentifier(Utils.toURI(sourceFile1), -1), Arrays.asList(new TextEdit(new Range(new Position(2, 3), new Position(2, 6)), "a"),
                                                                                                                                                                              new TextEdit(new Range(new Position(1, 2), new Position(1, 6)), "b"),
                                                                                                                                                                              new TextEdit(new Range(new Position(3, 1), new Position(4, 4)), "c")))),
                                                         Either.forLeft(new TextDocumentEdit(new VersionedTextDocumentIdentifier(Utils.toURI(sourceFile2), -1), Arrays.asList(new TextEdit(new Range(new Position(2, 3), new Position(2, 6)), "a"),
                                                                                                                                                                              new TextEdit(new Range(new Position(1, 2), new Position(1, 6)), "b"),
                                                                                                                                                                              new TextEdit(new Range(new Position(3, 1), new Position(4, 4)), "c")))),
                                                         Either.forRight(new CreateFile(Utils.toURI(sourceFile2).replace("Test2", "Test4"))),
                                                         Either.forLeft(new TextDocumentEdit(new VersionedTextDocumentIdentifier(Utils.toURI(sourceFile2).replace("Test2", "Test4"), -1), Arrays.asList(new TextEdit(new Range(new Position(1, 1), new Position(1, 1)), "new content")))),
                                                         Either.forRight(new DeleteFile(Utils.toURI(sourceFile3))),
                                                         Either.forRight(new RenameFile(Utils.toURI(sourceFile1), Utils.toURI(sourceFile1).replace("Test1", "Test1a")))));
    Utils.applyWorkspaceEdit(edit);
    assertContent("0123456789\n" +
                  "01b6789\n" +
                  "012a6789\n" +
                  "0c456789\n",
                  wd.getFileObject("Test1a.txt"));
    assertContent("0123456789\n" +
                  "01b6789\n" +
                  "012a6789\n" +
                  "0c456789\n",
                  wd.getFileObject("Test2.txt"));
    assertContent("new content", wd.getFileObject("Test4.txt"));
    assertNull(wd.getFileObject("Test3.txt"));
    LifecycleManager.getDefault().saveAll();
}
 
Example #8
Source File: ChangeUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private static void convertRenamePackcageChange(WorkspaceEdit edit, RenamePackageChange packageChange) throws CoreException {
	IPackageFragment pack = (IPackageFragment) packageChange.getModifiedElement();
	IPath newPackageFragment = new Path(packageChange.getNewName().replace('.', IPath.SEPARATOR));
	IPath oldPackageFragment = new Path(packageChange.getOldName().replace('.', IPath.SEPARATOR));
	IPath newPackagePath = pack.getResource().getLocation().removeLastSegments(oldPackageFragment.segmentCount()).append(newPackageFragment);
	if (packageChange.getRenameSubpackages()) {
		IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
		String oldPrefix = packageChange.getOldName();
		for (IPackageFragment currentPackage : allPackages) {
			String newPkgName = packageChange.getNewName() + currentPackage.getElementName().substring(oldPrefix.length());
			//update package's declaration
			convertPackageUpdateEdit(currentPackage.getCompilationUnits(), newPkgName, edit);
		}

		RenameFile renameFile = new RenameFile();
		renameFile.setNewUri(ResourceUtils.fixURI(newPackagePath.toFile().toURI()));
		renameFile.setOldUri(ResourceUtils.fixURI(pack.getResource().getRawLocationURI()));
		edit.getDocumentChanges().add(Either.forRight(renameFile));
	} else {
		//update package's declaration
		convertPackageUpdateEdit(pack.getCompilationUnits(), packageChange.getNewName(), edit);
	
		CreateFile createFile = new CreateFile();
		createFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI()));
		createFile.setOptions(new CreateFileOptions(false, true));
		edit.getDocumentChanges().add(Either.forRight(createFile));

		for (ICompilationUnit unit : pack.getCompilationUnits()) {
			RenameFile cuResourceChange = new RenameFile();
			cuResourceChange.setOldUri(ResourceUtils.fixURI(unit.getResource().getLocationURI()));
			IPath newCUPath = newPackagePath.append(unit.getPath().lastSegment());
			cuResourceChange.setNewUri(ResourceUtils.fixURI(newCUPath.toFile().toURI()));
			edit.getDocumentChanges().add(Either.forRight(cuResourceChange));
		}

		// Workaround: https://github.com/Microsoft/language-server-protocol/issues/272
		DeleteFile deleteFile = new DeleteFile();
		deleteFile.setUri(ResourceUtils.fixURI(newPackagePath.append(TEMP_FILE_NAME).toFile().toURI()));
		deleteFile.setOptions(new DeleteFileOptions(false, true));
		edit.getDocumentChanges().add(Either.forRight(deleteFile));

	}
}
 
Example #9
Source File: ChangeUtilTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMergeChanges() {
	WorkspaceEdit editA = new WorkspaceEdit();
	String uriA = "uriA";
	TextEdit textEdit = new TextEdit(
		new Range(new Position(0, 0), new Position(0, 0)),
		"package test;");
	editA.getChanges().put(uriA, Arrays.asList(textEdit));

	WorkspaceEdit root = ChangeUtil.mergeChanges(null, editA);
	assertNotNull(root);
	assertNotNull(root.getChanges());
	assertNotNull(root.getChanges().get(uriA));
	assertEquals(1, root.getChanges().size());
	assertEquals(1, root.getChanges().get(uriA).size());

	WorkspaceEdit editB = new WorkspaceEdit();
	editB.getChanges().put(uriA, Arrays.asList(textEdit));
	List<Either<TextDocumentEdit, ResourceOperation>> documentChanges = new ArrayList<>();
	TextDocumentEdit textDocumentEdit = new TextDocumentEdit(
		new VersionedTextDocumentIdentifier(uriA, 1), Arrays.asList(textEdit));
	documentChanges.add(Either.forLeft(textDocumentEdit));
	ResourceOperation resourceOperation = new RenameFile("uriA", "uriB");
	documentChanges.add(Either.forRight(resourceOperation));
	editB.setDocumentChanges(documentChanges);

	root = ChangeUtil.mergeChanges(editA, editB);
	assertNotNull(root);
	assertNotNull(root.getChanges());
	assertNotNull(root.getChanges().get(uriA));
	assertEquals(1, root.getChanges().size());
	assertEquals(2, root.getChanges().get(uriA).size());
	assertNotNull(root.getDocumentChanges());
	assertEquals(2, root.getDocumentChanges().size());
	assertTrue(root.getDocumentChanges().get(0).isLeft());
	assertEquals(textDocumentEdit, root.getDocumentChanges().get(0).getLeft());
	assertTrue(root.getDocumentChanges().get(1).isRight());
	assertEquals(resourceOperation, root.getDocumentChanges().get(1).getRight());

	root = ChangeUtil.mergeChanges(editA, editB, true);
	assertNotNull(root);
	assertNotNull(root.getChanges());
	assertNotNull(root.getChanges().get(uriA));
	assertEquals(1, root.getChanges().size());
	assertEquals(2, root.getChanges().get(uriA).size());
	assertNotNull(root.getDocumentChanges());
	assertEquals(1, root.getDocumentChanges().size());
	assertTrue(root.getDocumentChanges().get(0).isLeft());
	assertEquals(textDocumentEdit, root.getDocumentChanges().get(0).getLeft());
}
 
Example #10
Source File: RenameHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testRenameTypeWithResourceChanges() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);

	String[] codes = { "package test1;\n",
			           "public class E|* {\n",
			           "   public E() {\n",
			           "   }\n",
			           "   public int bar() {\n", "   }\n",
			           "   public int foo() {\n",
			           "		this.bar();\n",
			           "   }\n",
			           "}\n" };
	StringBuilder builder = new StringBuilder();
	Position pos = mergeCode(builder, codes);
	ICompilationUnit cu = pack1.createCompilationUnit("E.java", builder.toString(), false, null);

	WorkspaceEdit edit = getRenameEdit(cu, pos, "Newname");
	assertNotNull(edit);
	List<Either<TextDocumentEdit, ResourceOperation>> resourceChanges = edit.getDocumentChanges();

	assertEquals(resourceChanges.size(), 2);

	Either<TextDocumentEdit, ResourceOperation> change = resourceChanges.get(1);
	RenameFile resourceChange = (RenameFile) change.getRight();
	assertEquals(JDTUtils.toURI(cu), resourceChange.getOldUri());
	assertEquals(JDTUtils.toURI(cu).replaceFirst("(?s)E(?!.*?E)", "Newname"), resourceChange.getNewUri());

	List<TextEdit> testChanges = new LinkedList<>();
	testChanges.addAll(resourceChanges.get(0).getLeft().getEdits());

	String expected = "package test1;\n" +
					  "public class Newname {\n" +
					  "   public Newname() {\n" +
					  "   }\n" +
					  "   public int bar() {\n" +
					  "   }\n" +
					  "   public int foo() {\n" +
					  "		this.bar();\n" +
					  "   }\n" +
					  "}\n";

	assertEquals(expected, TextEditUtil.apply(builder.toString(), testChanges));
}
 
Example #11
Source File: RenameHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testRenamePackage() throws JavaModelException, BadLocationException {
	when(clientPreferences.isResourceOperationSupported()).thenReturn(true);

	IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
	IPackageFragment pack2 = sourceFolder.createPackageFragment("parent.test2", false, null);

	String[] codes1= {
			"package test1;\n",
			"import parent.test2.B;\n",
			"public class A {\n",
			"   public void foo(){\n",
			"		B b = new B();\n",
			"		b.foo();\n",
			"	}\n",
			"}\n"
	};

	String[] codes2 = {
			"package parent.test2|*;\n",
			"public class B {\n",
			"	public B() {}\n",
			"   public void foo() {}\n",
			"}\n"
	};
	StringBuilder builderA = new StringBuilder();
	mergeCode(builderA, codes1);
	ICompilationUnit cuA = pack1.createCompilationUnit("A.java", builderA.toString(), false, null);

	StringBuilder builderB = new StringBuilder();
	Position pos = mergeCode(builderB, codes2);
	ICompilationUnit cuB = pack2.createCompilationUnit("B.java", builderB.toString(), false, null);

	WorkspaceEdit edit = getRenameEdit(cuB, pos, "parent.newpackage");
	assertNotNull(edit);

	List<Either<TextDocumentEdit, ResourceOperation>> resourceChanges = edit.getDocumentChanges();

	assertEquals(5, resourceChanges.size());

	List<TextEdit> testChangesA = new LinkedList<>();
	testChangesA.addAll(resourceChanges.get(0).getLeft().getEdits());

	List<TextEdit> testChangesB = new LinkedList<>();
	testChangesB.addAll(resourceChanges.get(1).getLeft().getEdits());

	String expectedA =
			"package test1;\n" +
			"import parent.newpackage.B;\n" +
			"public class A {\n" +
			"   public void foo(){\n" +
			"		B b = new B();\n" +
			"		b.foo();\n" +
			"	}\n" +
			"}\n";

	String expectedB =
			"package parent.newpackage;\n" +
			"public class B {\n" +
			"	public B() {}\n" +
			"   public void foo() {}\n" +
			"}\n";
	assertEquals(expectedA, TextEditUtil.apply(builderA.toString(), testChangesA));
	assertEquals(expectedB, TextEditUtil.apply(builderB.toString(), testChangesB));

	//moved package
	CreateFile resourceChange = (CreateFile) resourceChanges.get(2).getRight();
	assertEquals(ResourceUtils.fixURI(pack2.getResource().getRawLocationURI()).replaceFirst("test2[/]?", "newpackage/.temp"), resourceChange.getUri());

	//moved class B
	RenameFile resourceChange2 = (RenameFile) resourceChanges.get(3).getRight();
	assertEquals(ResourceUtils.fixURI(cuB.getResource().getRawLocationURI()), resourceChange2.getOldUri());
	assertEquals(ResourceUtils.fixURI(cuB.getResource().getRawLocationURI()).replace("test2", "newpackage"), resourceChange2.getNewUri());
}
 
Example #12
Source File: MoveHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMoveFile() throws JavaModelException, BadLocationException {
	IPackageFragment pack1 = sourceFolder.createPackageFragment("jdtls.test1", false, null);
	//@formatter:off
	ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package jdtls.test1;\r\n" +
			"import jdtls.test2.B;\r\n" +
			"\r\n" +
			"public class A {\r\n" +
			"	private B b = new B();\r\n" +
			"}", true, null);
	//@formatter:on

	IPackageFragment pack2 = sourceFolder.createPackageFragment("jdtls.test2", false, null);
	//@formatter:off
	ICompilationUnit unitB = pack2.createCompilationUnit("B.java", "package jdtls.test2;\r\n" +
			"\r\n" +
			"public class B {\r\n" +
			"}", true, null);
	//@formatter:on

	IPackageFragment pack3 = sourceFolder.createPackageFragment("jdtls.test3", false, null);
	String packageUri = JDTUtils.getFileURI(pack3.getResource());
	RefactorWorkspaceEdit refactorEdit = MoveHandler.move(new MoveParams("moveResource", new String[] { JDTUtils.toURI(unitB) }, packageUri, true), new NullProgressMonitor());
	assertNotNull(refactorEdit);
	assertNotNull(refactorEdit.edit);
	List<Either<TextDocumentEdit, ResourceOperation>> changes = refactorEdit.edit.getDocumentChanges();
	assertEquals(4, changes.size());

	//@formatter:off
	String expected = "package jdtls.test1;\r\n" +
			"import jdtls.test3.B;\r\n" +
			"\r\n" +
			"public class A {\r\n" +
			"	private B b = new B();\r\n" +
			"}";
	//@formatter:on
	TextDocumentEdit textEdit = changes.get(0).getLeft();
	assertNotNull(textEdit);
	assertEquals(expected, TextEditUtil.apply(unitA.getSource(), textEdit.getEdits()));

	//@formatter:off
	expected = "package jdtls.test3;\r\n" +
			"\r\n" +
			"public class B {\r\n" +
			"}";
	//@formatter:on
	textEdit = changes.get(1).getLeft();
	assertNotNull(textEdit);
	List<TextEdit> edits = new ArrayList<>(textEdit.getEdits());
	textEdit = changes.get(2).getLeft();
	assertNotNull(textEdit);
	edits.addAll(textEdit.getEdits());
	assertEquals(expected, TextEditUtil.apply(unitB.getSource(), edits));

	RenameFile renameFile = (RenameFile) changes.get(3).getRight();
	assertNotNull(renameFile);
	assertEquals(JDTUtils.toURI(unitB), renameFile.getOldUri());
	assertEquals(ResourceUtils.fixURI(unitB.getResource().getRawLocationURI()).replace("test2", "test3"), renameFile.getNewUri());
}
 
Example #13
Source File: MoveHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testMoveMultiFiles() throws JavaModelException, BadLocationException {
	IPackageFragment pack1 = sourceFolder.createPackageFragment("jdtls.test1", false, null);
	//@formatter:off
	ICompilationUnit unitA = pack1.createCompilationUnit("A.java", "package jdtls.test1;\r\n" +
			"\r\n" +
			"public class A {\r\n" +
			"	private B b = new B();\r\n" +
			"}", true, null);
	//@formatter:on

	//@formatter:off
	ICompilationUnit unitB = pack1.createCompilationUnit("B.java", "package jdtls.test1;\r\n" +
			"\r\n" +
			"public class B {\r\n" +
			"}", true, null);
	//@formatter:on

	IPackageFragment pack2 = sourceFolder.createPackageFragment("jdtls.test2", false, null);
	String packageUri = JDTUtils.getFileURI(pack2.getResource());
	RefactorWorkspaceEdit refactorEdit = MoveHandler.move(new MoveParams("moveResource", new String[] { JDTUtils.toURI(unitA), JDTUtils.toURI(unitB) }, packageUri, true), new NullProgressMonitor());
	assertNotNull(refactorEdit);
	assertNotNull(refactorEdit.edit);
	List<Either<TextDocumentEdit, ResourceOperation>> changes = refactorEdit.edit.getDocumentChanges();
	assertEquals(6, changes.size());

	//@formatter:off
	String expected = "package jdtls.test2;\r\n" +
			"\r\n" +
			"public class A {\r\n" +
			"	private B b = new B();\r\n" +
			"}";
	//@formatter:on
	TextDocumentEdit textEdit = changes.get(0).getLeft();
	assertNotNull(textEdit);
	List<TextEdit> edits = new ArrayList<>(textEdit.getEdits());
	textEdit = changes.get(4).getLeft();
	assertNotNull(textEdit);
	edits.addAll(textEdit.getEdits());
	assertEquals(expected, TextEditUtil.apply(unitA.getSource(), edits));

	//@formatter:off
	expected = "package jdtls.test2;\r\n" +
			"\r\n" +
			"public class B {\r\n" +
			"}";
	//@formatter:on
	textEdit = changes.get(1).getLeft();
	assertNotNull(textEdit);
	edits = new ArrayList<>(textEdit.getEdits());
	textEdit = changes.get(2).getLeft();
	assertNotNull(textEdit);
	edits.addAll(textEdit.getEdits());
	assertEquals(expected, TextEditUtil.apply(unitB.getSource(), edits));

	RenameFile renameFileB = (RenameFile) changes.get(3).getRight();
	assertNotNull(renameFileB);
	assertEquals(JDTUtils.toURI(unitB), renameFileB.getOldUri());
	assertEquals(ResourceUtils.fixURI(unitB.getResource().getRawLocationURI()).replace("test1", "test2"), renameFileB.getNewUri());

	RenameFile renameFileA = (RenameFile) changes.get(5).getRight();
	assertNotNull(renameFileA);
	assertEquals(JDTUtils.toURI(unitA), renameFileA.getOldUri());
	assertEquals(ResourceUtils.fixURI(unitA.getResource().getRawLocationURI()).replace("test1", "test2"), renameFileA.getNewUri());
}
 
Example #14
Source File: ResourceOperationTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
InnerResourceOperationTypeAdapter(TypeAdapterFactory factory, Gson gson) {
	createFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(CreateFile.class));
	deleteFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(DeleteFile.class));
	renameFileAdapter = gson.getDelegateAdapter(factory, TypeToken.get(RenameFile.class));
}