Search in sources :

Example 1 with ChunkedResourceDescriptions

use of org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions in project xtext-eclipse by eclipse.

the class AbstractIncrementalBuilderTest method newBuildRequest.

protected BuildRequest newBuildRequest(final Procedure1<? super BuildRequest> init) {
    BuildRequest _buildRequest = new BuildRequest();
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        final ResourceDescriptionsData newIndex = this.indexState.getResourceDescriptions().copy();
        it.setBaseDir(this.uri(""));
        XtextResourceSet _get = this.resourceSetProvider.get();
        final Procedure1<XtextResourceSet> _function_1 = (XtextResourceSet it_1) -> {
            it_1.getURIConverter().getURIHandlers().clear();
            EList<URIHandler> _uRIHandlers = it_1.getURIConverter().getURIHandlers();
            _uRIHandlers.add(this.inMemoryURIHandler);
            it_1.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
            ProjectDescription _projectDescription = new ProjectDescription();
            final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it_2) -> {
                it_2.setName("test-project");
            };
            final ProjectDescription projectDescription = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function_2);
            projectDescription.attachToEmfObject(it_1);
            Map<String, ResourceDescriptionsData> _emptyMap = CollectionLiterals.<String, ResourceDescriptionsData>emptyMap();
            final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_emptyMap, it_1);
            index.setContainer(projectDescription.getName(), newIndex);
        };
        XtextResourceSet _doubleArrow = ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function_1);
        it.setResourceSet(_doubleArrow);
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Iterables.<Issue>addAll(this.issues, issues);
            return IterableExtensions.isEmpty(issues);
        };
        it.setAfterValidate(_function_2);
        final Procedure1<URI> _function_3 = (URI it_1) -> {
            this.deleted.add(it_1);
        };
        it.setAfterDeleteFile(_function_3);
        final Procedure2<URI, URI> _function_4 = (URI source, URI target) -> {
            this.generated.put(source, target);
        };
        it.setAfterGenerateFile(_function_4);
        Source2GeneratedMapping _copy = this.indexState.getFileMappings().copy();
        IndexState _indexState = new IndexState(newIndex, _copy);
        it.setState(_indexState);
    };
    final BuildRequest result = ObjectExtensions.<BuildRequest>operator_doubleArrow(_buildRequest, _function);
    init.apply(result);
    return result;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Source2GeneratedMapping(org.eclipse.xtext.build.Source2GeneratedMapping) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) IndexState(org.eclipse.xtext.build.IndexState) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) URIHandler(org.eclipse.emf.ecore.resource.URIHandler) InMemoryURIHandler(org.eclipse.xtext.junit4.util.InMemoryURIHandler) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 2 with ChunkedResourceDescriptions

use of org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions in project xtext-core by eclipse.

the class ProjectManager method createNewResourceSet.

public XtextResourceSet createNewResourceSet(final ResourceDescriptionsData newIndex) {
    XtextResourceSet _get = this.resourceSetProvider.get();
    final Procedure1<XtextResourceSet> _function = (XtextResourceSet it) -> {
        this.projectDescription.attachToEmfObject(it);
        ProjectConfigAdapter.install(it, this.projectConfig);
        Map<String, ResourceDescriptionsData> _get_1 = this.indexProvider.get();
        final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_get_1, it);
        index.setContainer(this.projectDescription.getName(), newIndex);
        this.externalContentSupport.configureResourceSet(it, this.openedDocumentsContentProvider);
    };
    return ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function);
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) Map(java.util.Map)

Example 3 with ChunkedResourceDescriptions

use of org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions in project xtext-core by eclipse.

the class ImportTestHelper method createResourceSet.

public ResourceSet createResourceSet(final InMemoryURIHandler fs) {
    final XtextResourceSet idx = new XtextResourceSet();
    idx.getURIConverter().getURIHandlers().add(0, fs);
    Collection<InMemoryURIHandler.InMemFile> _values = fs.getFiles().values();
    for (final InMemoryURIHandler.InMemFile f : _values) {
        idx.getResource(f.getUri(), true);
    }
    EcoreUtil.resolveAll(idx);
    final Consumer<XtextResource> _function = (XtextResource it) -> {
        this.validator.assertNoErrors(it);
    };
    Iterables.<XtextResource>filter(idx.getResources(), XtextResource.class).forEach(_function);
    final Function1<Resource, IResourceDescription> _function_1 = (Resource it) -> {
        return this.rdManager.getResourceDescription(it);
    };
    final List<IResourceDescription> rsd = ListExtensions.<Resource, IResourceDescription>map(idx.getResources(), _function_1);
    final ResourceDescriptionsData data = new ResourceDescriptionsData(rsd);
    final XtextResourceSet r = new XtextResourceSet();
    r.getLoadOptions().put(ResourceDescriptionsProvider.LIVE_SCOPE, Boolean.TRUE);
    r.getURIConverter().getURIHandlers().add(0, fs);
    ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(r, data);
    Pair<String, ResourceDescriptionsData> _mappedTo = Pair.<String, ResourceDescriptionsData>of("egal", data);
    new ChunkedResourceDescriptions(Collections.<String, ResourceDescriptionsData>unmodifiableMap(CollectionLiterals.<String, ResourceDescriptionsData>newHashMap(_mappedTo)), r);
    return r;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) InMemoryURIHandler(org.eclipse.xtext.testing.util.InMemoryURIHandler) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) XtextResource(org.eclipse.xtext.resource.XtextResource) TextRegionAccessToString(org.eclipse.xtext.formatting2.debug.TextRegionAccessToString) TextDocumentChangeToString(org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 4 with ChunkedResourceDescriptions

use of org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions in project xtext-core by eclipse.

the class LiveShadowedChunkedContainerTest method setUp.

@Before
public void setUp() {
    try {
        WorkspaceConfig _workspaceConfig = new WorkspaceConfig();
        this.workspaceConfig = _workspaceConfig;
        ProjectConfig _projectConfig = new ProjectConfig("foo", this.workspaceConfig);
        this.fooProject = _projectConfig;
        ProjectConfig _projectConfig_1 = new ProjectConfig("bar", this.workspaceConfig);
        this.barProject = _projectConfig_1;
        final XtextResourceSet rs0 = this.resourceSetProvider.get();
        this.fooURI = IterableExtensions.<SourceFolder>head(this.fooProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("foo.livecontainertestlanguage");
        this.barURI = IterableExtensions.<SourceFolder>head(this.barProject.getSourceFolders()).getPath().trimSegments(1).appendSegment("bar.livecontainertestlanguage");
        ResourceDescriptionsData _createResourceDescriptionData = this.createResourceDescriptionData(this._parseHelper.parse("foo", this.fooURI, rs0).eResource());
        Pair<String, ResourceDescriptionsData> _mappedTo = Pair.<String, ResourceDescriptionsData>of("foo", _createResourceDescriptionData);
        ResourceDescriptionsData _createResourceDescriptionData_1 = this.createResourceDescriptionData(this._parseHelper.parse("bar", this.barURI, rs0).eResource());
        Pair<String, ResourceDescriptionsData> _mappedTo_1 = Pair.<String, ResourceDescriptionsData>of("bar", _createResourceDescriptionData_1);
        final Map<String, ResourceDescriptionsData> chunks = Collections.<String, ResourceDescriptionsData>unmodifiableMap(CollectionLiterals.<String, ResourceDescriptionsData>newHashMap(_mappedTo, _mappedTo_1));
        this.rs1 = this.resourceSetProvider.get();
        new ChunkedResourceDescriptions(chunks, this.rs1);
        ProjectConfigAdapter.install(this.rs1, this.fooProject);
        this.liveShadowedChunkedResourceDescriptions = this.provider.get();
        this.liveShadowedChunkedResourceDescriptions.setContext(this.rs1);
        LiveShadowedChunkedContainer _liveShadowedChunkedContainer = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "foo");
        this.fooContainer = _liveShadowedChunkedContainer;
        LiveShadowedChunkedContainer _liveShadowedChunkedContainer_1 = new LiveShadowedChunkedContainer(this.liveShadowedChunkedResourceDescriptions, "bar");
        this.barContainer = _liveShadowedChunkedContainer_1;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : ProjectConfig(org.eclipse.xtext.resource.containers.ProjectConfig) SourceFolder(org.eclipse.xtext.resource.containers.SourceFolder) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) WorkspaceConfig(org.eclipse.xtext.workspace.WorkspaceConfig) LiveShadowedChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) LiveShadowedChunkedContainer(org.eclipse.xtext.resource.containers.LiveShadowedChunkedContainer) Before(org.junit.Before)

Example 5 with ChunkedResourceDescriptions

use of org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions 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)

Aggregations

ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)11 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)6 LiveShadowedChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions)5 ResourceDescriptionsData (org.eclipse.xtext.resource.impl.ResourceDescriptionsData)5 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)4 URI (org.eclipse.emf.common.util.URI)3 BuildRequest (org.eclipse.xtext.build.BuildRequest)3 Map (java.util.Map)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 URIHandler (org.eclipse.emf.ecore.resource.URIHandler)2 IndexState (org.eclipse.xtext.build.IndexState)2 Source2GeneratedMapping (org.eclipse.xtext.build.Source2GeneratedMapping)2 IContainer (org.eclipse.xtext.resource.IContainer)2 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)2 Issue (org.eclipse.xtext.validation.Issue)2 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)2 Procedure2 (org.eclipse.xtext.xbase.lib.Procedures.Procedure2)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1