use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class IncrementalBuilderTest method testDeleteClearsReusedResourceSet.
@Test
public void testDeleteClearsReusedResourceSet() {
final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("foo {");
_builder.newLine();
_builder.append(" ");
_builder.append("entity A {foo.B references}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
URI _minus = this.operator_minus("src/A.indextestlanguage", _builder.toString());
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("foo {");
_builder_1.newLine();
_builder_1.append(" ");
_builder_1.append("entity B");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
URI _minus_1 = this.operator_minus("src/B.indextestlanguage", _builder_1.toString());
it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_minus, _minus_1)));
};
final BuildRequest req = this.newBuildRequest(_function);
final XtextResourceSet resourceSet = req.getResourceSet();
this.build(req);
final AtomicBoolean validateCalled = new AtomicBoolean(false);
final Procedure1<BuildRequest> _function_1 = (BuildRequest it) -> {
URI _uri = this.uri("src/B.indextestlanguage");
it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(_uri)));
final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
Assert.assertEquals(this.uri("src/A.indextestlanguage"), uri);
String _string = issues.toString();
Assert.assertTrue(_string, ((!IterableExtensions.isEmpty(issues)) && IterableExtensions.<Issue>head(issues).getMessage().contains("Couldn\'t resolve reference to Type \'foo.B\'")));
validateCalled.set(true);
return false;
};
it.setAfterValidate(_function_2);
it.setResourceSet(resourceSet);
final ChunkedResourceDescriptions desc = ChunkedResourceDescriptions.findInEmfObject(it.getResourceSet());
desc.setContainer("test-project", it.getState().getResourceDescriptions());
};
this.build(this.newBuildRequest(_function_1));
Assert.assertTrue(validateCalled.get());
Assert.assertNull(resourceSet.getResource(this.uri("src/B.indextestlanguage"), false));
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class FormatterReplacementsTest method testUndefinedIdentityEditsAreNotFiltered.
@Test
public void testUndefinedIdentityEditsAreNotFiltered() {
final GenericFormatter<IDList> _function = new GenericFormatter<IDList>() {
@Override
protected void format(final IDList model, @Extension final ITextRegionExtensions regions, @Extension final IFormattableDocument document) {
final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
it_1.setSpace("");
};
document.prepend(it, _function_1);
};
regions.regionFor(model).ruleCallsTo(FormatterReplacementsTest.this._formatterTestLanguageGrammarAccess.getIDRule()).forEach(_function);
}
};
final GenericFormatter<IDList> formatter = _function;
IDList _createIDList = this.fact.createIDList();
final Procedure1<IDList> _function_1 = (IDList it) -> {
EList<String> _ids = it.getIds();
_ids.add("a");
};
final IDList model = ObjectExtensions.<IDList>operator_doubleArrow(_createIDList, _function_1);
Resource _createResource = this.resFact.createResource(URI.createURI("foo.ext"));
final Procedure1<Resource> _function_2 = (Resource it) -> {
EList<Resource> _resources = new XtextResourceSet().getResources();
_resources.add(it);
EList<EObject> _contents = it.getContents();
_contents.add(model);
};
ObjectExtensions.<Resource>operator_doubleArrow(_createResource, _function_2);
final FormatterRequest request = this.requestProvider.get();
request.setAllowIdentityEdits(false);
request.setTextRegionAccess(this.serializer.serializeToRegions(model));
final List<ITextReplacement> replacements = formatter.format(request);
final Function1<ITextReplacement, String> _function_3 = (ITextReplacement it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"");
String _text = it.getText();
_builder.append(_text);
_builder.append("\" -> \"");
String _replacementText = it.getReplacementText();
_builder.append(_replacementText);
_builder.append("\"");
_builder.append("\n");
return _builder.toString();
};
final String actual = IterableExtensions.join(ListExtensions.<ITextReplacement, String>map(replacements, _function_3));
StringConcatenation _builder = new StringConcatenation();
_builder.append("\"\" -> \"\"");
_builder.newLine();
_builder.append("\"\" -> \"\"");
_builder.newLine();
_builder.append("\"\" -> \"\"");
_builder.newLine();
final String expected = _builder.toString();
Assert.assertEquals(expected, actual);
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testGlobalScope.
@Test
public void testGlobalScope() throws Exception {
EReference ref = createRefToRoot();
ResourceSet resourceSet = new XtextResourceSet();
Resource res = parse("local", resourceSet).eResource();
parse("other", resourceSet);
assertEquals("other", format(scopeProvider.getScope(res, ref).getAllElements()));
Resource foo = parse("foo", resourceSet).eResource();
assertEquals("foo, other", format(scopeProvider.getScope(res, ref).getAllElements()));
resourceSet.getResources().remove(foo);
assertEquals("other", format(scopeProvider.getScope(res, ref).getAllElements()));
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testContainerLoadUnload.
@Test
public void testContainerLoadUnload() throws Exception {
ResourceSet resourceSet = new XtextResourceSet();
Resource res = parse("local", resourceSet).eResource();
Resource foo = resourceSet.createResource(computeUnusedUri(resourceSet));
IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
assertEquals(1, containers.size());
IContainer container = containers.get(0);
// assertEquals("local", format(container.getExportedObjects()));
foo.load(new StringInputStream("foo"), null);
assertEquals("foo, local", format(container.getExportedObjects()));
// foo.unload();
// assertEquals("local", format(container.getExportedObjects()));
}
use of org.eclipse.xtext.resource.XtextResourceSet in project xtext-core by eclipse.
the class LiveShadowedAllContainerStateTest method testContainsURI.
@Test
public void testContainsURI() {
String fileExtension = fep.getPrimaryFileExtension();
XtextResourceSet xtextResourceSet1 = rsp.get();
xtextResourceSet1.createResource(URI.createURI("/a/x." + fileExtension));
xtextResourceSet1.createResource(URI.createURI("/b/x1." + fileExtension));
ResourceSetBasedResourceDescriptions liveState = new ResourceSetBasedResourceDescriptions();
liveState.setContext(xtextResourceSet1);
liveState.setRegistry(registry);
Multimap<String, URI> container2Uris = ArrayListMultimap.create();
container2Uris.put("a", URI.createURI("/a/x." + fileExtension));
container2Uris.put("a", URI.createURI("/a/y." + fileExtension));
container2Uris.put("b", URI.createURI("/b/x1." + fileExtension));
container2Uris.put("b", URI.createURI("/b/x2." + fileExtension));
IAllContainersState containersState = containerStateProvider.get(liveState, new FakeAllContainerState(container2Uris));
assertTrue(containersState.containsURI("a", URI.createURI("/a/x." + fileExtension)));
assertTrue(containersState.containsURI("a", URI.createURI("/a/y." + fileExtension)));
assertFalse(containersState.containsURI("b", URI.createURI("/a/x." + fileExtension)));
assertFalse(containersState.containsURI("b", URI.createURI("/a/y." + fileExtension)));
assertTrue(containersState.containsURI("b", URI.createURI("/b/x1." + fileExtension)));
assertTrue(containersState.containsURI("b", URI.createURI("/b/x2." + fileExtension)));
assertFalse(containersState.containsURI("a", URI.createURI("/b/x1." + fileExtension)));
assertFalse(containersState.containsURI("a", URI.createURI("/b/x2." + fileExtension)));
}
Aggregations