Search in sources :

Example 16 with IContainer

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

the class DefaultGlobalScopeProvider method getVisibleContainers.

protected List<IContainer> getVisibleContainers(Resource resource) {
    IResourceDescription description = descriptionManager.getResourceDescription(resource);
    IResourceDescriptions resourceDescriptions = getResourceDescriptions(resource);
    String cacheKey = getCacheKey("VisibleContainers", resource.getResourceSet());
    OnChangeEvictingCache.CacheAdapter cache = new OnChangeEvictingCache().getOrCreate(resource);
    List<IContainer> result = null;
    result = cache.get(cacheKey);
    if (result == null) {
        result = containerManager.getVisibleContainers(description, resourceDescriptions);
        // container manager, but it is not aware of a CacheAdapter
        if (resourceDescriptions instanceof IResourceDescription.Event.Source) {
            IResourceDescription.Event.Source eventSource = (Source) resourceDescriptions;
            DelegatingEventSource delegatingEventSource = new DelegatingEventSource(eventSource);
            delegatingEventSource.addListeners(Lists.newArrayList(Iterables.filter(result, IResourceDescription.Event.Listener.class)));
            delegatingEventSource.initialize();
            cache.addCacheListener(delegatingEventSource);
        }
        cache.set(cacheKey, result);
    }
    return result;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) Source(org.eclipse.xtext.resource.IResourceDescription.Event.Source) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) IContainer(org.eclipse.xtext.resource.IContainer) Source(org.eclipse.xtext.resource.IResourceDescription.Event.Source)

Example 17 with IContainer

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

the class ProjectDescriptionBasedContainerManager method createContainer.

protected IContainer createContainer(final IResourceDescriptions resourceDescriptions, final ChunkedResourceDescriptions chunkedResourceDescriptions, final String projectName) {
    IContainer _xifexpression = null;
    if ((resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions)) {
        _xifexpression = new LiveShadowedChunkedContainer(((LiveShadowedChunkedResourceDescriptions) resourceDescriptions), projectName);
    } else {
        ResourceDescriptionsData _elvis = null;
        ResourceDescriptionsData _container = chunkedResourceDescriptions.getContainer(projectName);
        if (_container != null) {
            _elvis = _container;
        } else {
            Set<IResourceDescription> _emptySet = CollectionLiterals.<IResourceDescription>emptySet();
            ResourceDescriptionsData _resourceDescriptionsData = new ResourceDescriptionsData(_emptySet);
            _elvis = _resourceDescriptionsData;
        }
        _xifexpression = new ResourceDescriptionsBasedContainer(_elvis);
    }
    return _xifexpression;
}
Also used : ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) LiveShadowedChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ResourceDescriptionsBasedContainer(org.eclipse.xtext.resource.impl.ResourceDescriptionsBasedContainer) IContainer(org.eclipse.xtext.resource.IContainer) LiveShadowedChunkedContainer(org.eclipse.xtext.resource.containers.LiveShadowedChunkedContainer)

Example 18 with IContainer

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

the class ProjectDescriptionBasedContainerManager method getContainer.

@Override
public IContainer getContainer(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
    final ChunkedResourceDescriptions chunkedResourceDescriptions = this.getChunkedResourceDescriptions(resourceDescriptions);
    if ((chunkedResourceDescriptions == null)) {
        String _name = ChunkedResourceDescriptions.class.getName();
        String _plus = ("expected " + _name);
        throw new IllegalArgumentException(_plus);
    }
    final ResourceSet resourceSet = chunkedResourceDescriptions.getResourceSet();
    final ProjectDescription projectDescription = ProjectDescription.findInEmfObject(resourceSet);
    final IContainer container = this.createContainer(resourceDescriptions, chunkedResourceDescriptions, projectDescription.getName());
    return container;
}
Also used : LiveShadowedChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 19 with IContainer

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

the class ProjectDescriptionBasedContainerManager method getVisibleContainers.

@Override
public List<IContainer> getVisibleContainers(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
    final ChunkedResourceDescriptions chunkedResourceDescriptions = this.getChunkedResourceDescriptions(resourceDescriptions);
    if ((chunkedResourceDescriptions == null)) {
        String _name = ChunkedResourceDescriptions.class.getName();
        String _plus = ("expected " + _name);
        throw new IllegalArgumentException(_plus);
    }
    final ResourceSet resourceSet = chunkedResourceDescriptions.getResourceSet();
    final ProjectDescription projectDescription = ProjectDescription.findInEmfObject(resourceSet);
    final ArrayList<IContainer> allContainers = CollectionLiterals.<IContainer>newArrayList();
    allContainers.add(this.createContainer(resourceDescriptions, chunkedResourceDescriptions, projectDescription.getName()));
    List<String> _dependencies = projectDescription.getDependencies();
    for (final String name : _dependencies) {
        allContainers.add(this.createContainer(resourceDescriptions, chunkedResourceDescriptions, name));
    }
    return allContainers;
}
Also used : LiveShadowedChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 20 with IContainer

use of org.eclipse.xtext.resource.IContainer in project xtext-eclipse by eclipse.

the class StateBasedContainerManagerTest method testGetVisibleContainers_02.

@Test
public void testGetVisibleContainers_02() {
    IFile file = getFile(project1, "doesNotExist");
    URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
    IResourceDescription description = new URIBasedTestResourceDescription(uri);
    List<IContainer> visibleContainers = containerManager.getVisibleContainers(description, this);
    assertEquals(2, visibleContainers.size());
    assertEquals(3, Iterables.size(visibleContainers.get(0).getResourceDescriptions()));
    assertEquals(1, Iterables.size(visibleContainers.get(1).getResourceDescriptions()));
    assertNotNull(visibleContainers.get(0).getResourceDescription(uri));
    assertNotNull(visibleContainers.get(0).getResourceDescription(uri1));
    assertNotNull(visibleContainers.get(0).getResourceDescription(uri2));
    assertNotNull(visibleContainers.get(1).getResourceDescription(uri3));
}
Also used : URIBasedTestResourceDescription(org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription) IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

IContainer (org.eclipse.xtext.resource.IContainer)25 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)13 URI (org.eclipse.emf.common.util.URI)7 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)7 Test (org.junit.Test)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 URIBasedTestResourceDescription (org.eclipse.xtext.junit4.util.URIBasedTestResourceDescription)4 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)4 IScope (org.eclipse.xtext.scoping.IScope)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)3 LiveShadowedChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.LiveShadowedChunkedResourceDescriptions)3 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2 EObject (org.eclipse.emf.ecore.EObject)2 QualifiedName (org.eclipse.xtext.naming.QualifiedName)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 ChunkedResourceDescriptions (org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions)2 ProjectDescription (org.eclipse.xtext.resource.impl.ProjectDescription)2