use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testNestedPackage.
@Test
public void testNestedPackage() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content1 = "package foo \n" + "element X {}\n";
importTestHelper.operator_add(fs, Pair.of("inmemory:/foo/X.fileawaretestlanguage", content1));
String content2 = "package foo.bar \n" + "element Y { ref foo.X }\n";
importTestHelper.operator_add(fs, Pair.of("inmemory:/foo/bar/Y.fileawaretestlanguage", content2));
ResourceSet rs = importTestHelper.createResourceSet(fs);
PackageDeclaration model1 = importTestHelper.contents(rs, "inmemory:/foo/X.fileawaretestlanguage", PackageDeclaration.class);
PackageDeclaration model2 = importTestHelper.contents(rs, "inmemory:/foo/bar/Y.fileawaretestlanguage", PackageDeclaration.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model1, (PackageDeclaration it) -> {
it.setName("foo2");
});
serializer.addModification(model2, (PackageDeclaration it) -> {
// was this way in the original test
it.setName("foo2.bar");
it.setName("foo2.bar");
});
Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "-------- inmemory:/foo/X.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:3|foo2> \n" + "element X {}\n" + "--------------------------------------------------------------------------------\n" + "8 3 \"foo\" -> \"foo2\"\n" + "------ inmemory:/foo/bar/Y.fileawaretestlanguage (syntax: <offset|text>) -------\n" + "package <8:7|foo2.bar> \n" + "<17:0|import foo2.X\n" + "\n" + ">element Y { ref <33:5|X> }\n" + "--------------------------------------------------------------------------------\n" + " 8 7 \"foo.bar\" -> \"foo2.bar\"\n" + "17 0 \"\" -> \"import foo2.X\\n" + "\\n" + "\"\n" + "33 5 \"foo.X\" -> \"X\"\n";
importTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class FileAwareTestLanguageImportTest method testRenameGlobal1.
@Test
public void testRenameGlobal1() {
InMemoryURIHandler fs = new InMemoryURIHandler();
String content1 = "package pkg1\n" + "\n" + "element Foo {\n" + "}\n";
importTestHelper.operator_add(fs, Pair.of("inmemory:/file1.fileawaretestlanguage", content1));
String content2 = "package pkg2\n" + "\n" + "import pkg1.Foo\n" + "\n" + "element Bar {\n" + " ref Foo\n" + "}\n";
importTestHelper.operator_add(fs, Pair.of("inmemory:/file2.fileawaretestlanguage", content2));
ResourceSet rs = importTestHelper.createResourceSet(fs);
PackageDeclaration model = importTestHelper.contents(rs, "inmemory:/file1.fileawaretestlanguage", PackageDeclaration.class);
ChangeSerializer serializer = serializerProvider.get();
serializer.addModification(model, (PackageDeclaration it) -> {
it.setName("newpackage");
});
Assert.assertEquals(1, model.eResource().getResourceSet().getResources().size());
Collection<IEmfResourceChange> changes = importTestHelper.endRecordChangesToTextDocuments(serializer);
String expectation = "-------- inmemory:/file1.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package <8:4|newpackage>\n" + "\n" + "element Foo {\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "8 4 \"pkg1\" -> \"newpackage\"\n" + "-------- inmemory:/file2.fileawaretestlanguage (syntax: <offset|text>) ---------\n" + "package pkg2\n" + "\n" + "import <21:8|newpackage.Foo>\n" + "\n" + "element Bar {\n" + " ref Foo\n" + "}\n" + "--------------------------------------------------------------------------------\n" + "21 8 \"pkg1.Foo\" -> \"newpackage.Foo\"\n";
importTestHelper.operator_tripleEquals(changes, expectation);
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class ChangeSerializerTestHelper method createResourceSet.
public ResourceSet createResourceSet(InMemoryURIHandler fs) {
XtextResourceSet idx = new XtextResourceSet();
idx.getURIConverter().getURIHandlers().add(0, fs);
for (InMemoryURIHandler.InMemFile f : fs.getFiles().values()) {
idx.getResource(f.getUri(), true);
}
EcoreUtil.resolveAll(idx);
for (Resource r : idx.getResources()) {
if (r instanceof XtextResource) {
validator.assertNoErrors(r);
}
}
List<IResourceDescription> rsd = new ArrayList<>();
for (Resource r : idx.getResources()) {
rsd.add(rdManager.getResourceDescription(r));
}
ResourceDescriptionsData data = new ResourceDescriptionsData(rsd);
XtextResourceSet r = new XtextResourceSet();
r.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE);
r.getURIConverter().getURIHandlers().add(0, fs);
ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(r, data);
return r;
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class AbstractIdeQuickfixTest method createInMemoryFile.
@SuppressWarnings("unchecked")
private <T> T createInMemoryFile(CharSequence content, EClass type) {
InMemoryURIHandler fs = new InMemoryURIHandler();
String fileName = "inmemory:/file1." + fileExtensionProvider.getPrimaryFileExtension();
quickFixTestHelper.operator_add(fs, Pair.of(fileName, content.toString()));
ResourceSet rs = quickFixTestHelper.createResourceSet(fs);
Map<String, ResourceDescriptionsData> dataMap = new HashMap<>();
dataMap.put("project", ResourceDescriptionsData.ResourceSetAdapter.findResourceDescriptionsData(rs));
new ChunkedResourceDescriptions(dataMap, rs);
return (T) quickFixTestHelper.findFirstOfTypeInFile(rs, fileName, type.getInstanceClass());
}
use of org.eclipse.xtext.testing.util.InMemoryURIHandler in project xtext-core by eclipse.
the class AbstractIncrementalBuilderTest method setUp.
@Before
@BeforeEach
public void setUp() {
clean();
inMemoryURIHandler = new InMemoryURIHandler();
}
Aggregations