Search in sources :

Example 46 with XtextResourceSet

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) AbstractIncrementalBuilderTest(org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest) Test(org.junit.Test)

Example 47 with XtextResourceSet

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);
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) IFormattableDocument(org.eclipse.xtext.formatting2.IFormattableDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) IDList(org.eclipse.xtext.formatting2.internal.formattertestlanguage.IDList) ITextRegionExtensions(org.eclipse.xtext.formatting2.regionaccess.ITextRegionExtensions) Extension(org.eclipse.xtext.xbase.lib.Extension) GenericFormatter(org.eclipse.xtext.formatting2.internal.GenericFormatter) EList(org.eclipse.emf.common.util.EList) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) FormatterRequest(org.eclipse.xtext.formatting2.FormatterRequest) Test(org.junit.Test)

Example 48 with XtextResourceSet

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()));
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 49 with XtextResourceSet

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()));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Example 50 with XtextResourceSet

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)));
}
Also used : ResourceSetBasedResourceDescriptions(org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)72 XtextResource (org.eclipse.xtext.resource.XtextResource)61 Test (org.junit.Test)44 StringInputStream (org.eclipse.xtext.util.StringInputStream)36 URI (org.eclipse.emf.common.util.URI)24 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)19 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)12 EObject (org.eclipse.emf.ecore.EObject)11 File (java.io.File)10 AbstractResourceSetTest (org.eclipse.xtext.resource.AbstractResourceSetTest)10 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)8 Issue (org.eclipse.xtext.validation.Issue)8 Grammar (org.eclipse.xtext.Grammar)7 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)7 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)7 ArrayList (java.util.ArrayList)5 ClasspathTypeProvider (org.eclipse.xtext.common.types.access.impl.ClasspathTypeProvider)5 Before (org.junit.Before)5 Injector (com.google.inject.Injector)4