Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ protected Resource loadAndWatchResource(ResourceRelocationChange change) {
changeSerializer.addModification(original, (Resource it) -> original.setURI(change.getToURI()));
return original;
case COPY:
Resource copy = resourceSet.createResource(change.getFromURI());
Resource copy = resourceSet.createResource(change.getToURI());
try {
copy.load(resourceSet.getURIConverter().createInputStream(change.getFromURI()), null);
} catch (IOException e) {
Exceptions.sneakyThrow(e);
}
copy.setURI(change.getToURI());
return copy;
default:
return null;
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.xtext.ui.tests/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.xtext.ui;bundle-version="2.43.0",
org.eclipse.ui.workbench.texteditor;bundle-version="3.19.400",
org.eclipse.ui.ide;bundle-version="3.22.800",
org.eclipse.jdt.core;bundle-version="3.44.0",
org.eclipse.jdt.core.manipulation;bundle-version="1.23.200",
org.eclipse.jdt.launching;bundle-version="3.24.0",
org.eclipse.xtext;bundle-version="2.43.0",
org.eclipse.xtext.testing;bundle-version="2.43.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/**
* Copyright (c) 2026 TypeFox GmbH (http://www.typefox.io) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.ui.tests.refactoring;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this could me moved to ide tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to move the following related classes to org.eclipse.xtext.ide.tests:

  • AbstractResourceRelocationTest,
  • ProgressReportingTest,
  • ResourceCopyTest,
  • ResourceMoveTest,
  • ResourceRenameTest,

but this would require the following additional dependencies:

  • org.eclipse.core.resources,
  • org.eclipse.jdt.core,
  • org.eclipse.jdt.core.manipulation,
  • org.eclipse.ltk.core.refactoring,
  • org.eclipse.xtext.testlanguages.ui,
  • org.eclipse.xtext.ui.testing.

Would you still like me to move the classes and add the additional dependencies?

Copy link
Copy Markdown
Contributor

@cdietrich cdietrich Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought based on a lsp test or xtext.ide.tests this could be done without any of these dependencies....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(e.g. renameTestLanguage)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick look at the lsp server implementation and Xtext does not seem to support any copy resource refactoring via lsp, since it handles neither willCreateFiles nor didCreateFiles from org.eclipse.lsp4j.services.WorkspaceService?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmmm. thats bad. is there really no way to avoid the new internal deps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I could also create a mock copy processor to avoid the internal deps?


import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.ICopyPolicy;
import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgDestinationFactory;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm internal imports ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely dep in manifest also missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm internal imports ...

There is, unfortunetaly, no generic copy processor for resources, so the test currently uses internal classes from JDT for that purpose. I could also create a mock copy processor to avoid the internal imports?

Likely dep in manifest also missing.

I have added the missing dependency for org.eclipse.jdt.core.manipulation in the manifest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szarnekow @LorenzoBettini i really dislike the new big bunch of internal deps but also have no better idea
for a more isolated tests we seem to miss a ton of infra in ide.tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For tests it might acceptable. Otherwise, he suggested to use a mock avoiding the internal stuff

import org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory;
import org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.eclipse.xtext.testlanguages.fileAware.ui.tests.FileAwareTestLanguageUiInjectorProvider;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author koehnlein - Initial contribution and API
Comment thread
mx990 marked this conversation as resolved.
* @author mx990 - adapted from ResourceMoveTest
*/
@InjectWith(FileAwareTestLanguageUiInjectorProvider.class)
@RunWith(XtextRunner.class)
public class ResourceCopyTest extends AbstractResourceRelocationTest {
@Test
public void testCopyFile() throws Exception {
String model1 =
"package foo.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
IFile x = file("foo/bar/X.fileawaretestlanguage", model1);
String model2 =
"package foo\n" +
"element Y {\n" +
" ref bar.X\n" +
"}\n";
file("foo/Y.fileawaretestlanguage", model2);
performCopy(folder("foo/baz"), x);
Assert.assertTrue(x.exists());
assertFileContents("foo/bar/X.fileawaretestlanguage", model1);
assertFileContents("foo/Y.fileawaretestlanguage", model2);
String expectation1 =
"package foo.baz\n" +
"element X {\n" +
" ref X\n" +
"}\n";
assertFileContents("foo/baz/X.fileawaretestlanguage", expectation1);
}

@Test
public void testCopyFile_2() throws Exception {
String model1 =
"package foo.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
file("foo/bar/X.fileawaretestlanguage", model1);
String model2 =
"package foo\n" +
"element Y {\n" +
" ref bar.X\n" +
"}\n";
IFile y = file("foo/Y.fileawaretestlanguage", model2);
performCopy(folder("foo/baz"), y);
Assert.assertTrue(y.exists());
assertFileContents("foo/bar/X.fileawaretestlanguage", model1);
assertFileContents("foo/Y.fileawaretestlanguage", model2);
String expectation1 =
"package foo.baz\n" +
"element Y {\n" +
" ref foo.bar.X\n" +
"}\n";
assertFileContents("foo/baz/Y.fileawaretestlanguage", expectation1);
}

@Test
public void testCopyFiles() throws Exception {
String model1 =
"package foo.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
IFile x = file("foo/X.fileawaretestlanguage", model1);
String model2 =
"package foo\n" +
"element Y {\n" +
" ref bar.X\n" +
"}\n";
IFile y = file("foo/Y.fileawaretestlanguage", model2);
performCopy(folder("foo/baz"), x, y);
Assert.assertTrue(y.exists());
assertFileContents("foo/X.fileawaretestlanguage", model1);
assertFileContents("foo/Y.fileawaretestlanguage", model2);
String expectation1 =
"package foo.baz\n" +
"element X {\n" +
" ref X\n" +
"}\n";
assertFileContents("foo/baz/X.fileawaretestlanguage", expectation1);
String expectation2 =
"package foo.baz\n" +
"element Y {\n" +
" ref X\n" +
"}\n";
assertFileContents("foo/baz/Y.fileawaretestlanguage", expectation2);
}

@Test
public void testCopyDirectory() throws Exception {
String model1 =
"package foo.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
IFile x = file("foo/bar/X.fileawaretestlanguage", model1);
String model2 =
"package foo\n" +
"element Y {\n" +
" ref bar.X\n" +
"}\n";
file("foo/Y.fileawaretestlanguage", model2);
performCopy(folder("foo/baz"), x.getParent());
Assert.assertTrue(x.exists());
assertFileContents("foo/bar/X.fileawaretestlanguage", model1);
assertFileContents("foo/Y.fileawaretestlanguage", model2);
String expectation1 =
"package foo.baz.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
assertFileContents("foo/baz/bar/X.fileawaretestlanguage", expectation1);
}

@Test
public void testCopyDirectoryToRoot() throws Exception {
String model1 =
"package foo.bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
IFile x = file("foo/bar/X.fileawaretestlanguage", model1);
String model2 =
"package foo\n" +
"element Y {\n" +
" ref bar.X\n" +
"}\n";
file("foo/Y.fileawaretestlanguage", model2);
performCopy(project, x.getParent());
Assert.assertTrue(x.exists());
assertFileContents("foo/bar/X.fileawaretestlanguage", model1);
assertFileContents("foo/Y.fileawaretestlanguage", model2);
String expectation1 =
"package bar\n" +
"element X {\n" +
" ref X\n" +
"}\n";
assertFileContents("bar/X.fileawaretestlanguage", expectation1);
}

@SuppressWarnings("restriction")
protected void performCopy(IContainer theDestination, IResource... theResources) throws Exception {
ICopyPolicy copyPolicy = ReorgPolicyFactory.createCopyPolicy(theResources, new IJavaElement[0]);
copyPolicy.setDestination(ReorgDestinationFactory.createDestination(theDestination));
performRefactoring(((RefactoringChangeDescriptor) copyPolicy.getDescriptor()).getRefactoringDescriptor());
}
}
Loading