org.eclipse.xtext.resource.IContainer Java Examples

The following examples show how to use org.eclipse.xtext.resource.IContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleResourceDescriptionsBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
		return delegate.getContainer(desc, resourceDescriptions);
	}
	ResourceDescriptionsBasedContainer result = new ResourceDescriptionsBasedContainer(resourceDescriptions) {
		// this used to be the default implementation, which is wrong.
		// we fixed the orginal and moved the wrong impl here since old clients might see much worse performance with the new impl. 
		@Override
		public boolean hasResourceDescription(URI uri) {
			return true;
		}
	};
	result.setUriToDescriptionCacheEnabled(false);
	return result;
}
 
Example #2
Source File: AbstractLiveContainerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testContainerAddRemove() throws Exception {
	ResourceSet resourceSet = new XtextResourceSet();
	Resource res = parse("local", resourceSet).eResource();
	parse("other", 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, other", format(container.getExportedObjects()));

	Resource foo = parse("foo", resourceSet).eResource();
	assertEquals("foo, local, other", format(container.getExportedObjects()));

	resourceSet.getResources().remove(foo);
	assertEquals("local, other", format(container.getExportedObjects()));
}
 
Example #3
Source File: StateBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
		return delegate.getVisibleContainers(desc, resourceDescriptions);
	}
	String root = internalGetContainerHandle(desc, resourceDescriptions);
	if (root == null) {
		if (log.isDebugEnabled())
			log.debug("Cannot find IContainer for: " + desc.getURI());
		return Collections.emptyList();
	}
	List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);
	List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
	if (!result.isEmpty()) {
		IContainer first = result.get(0);
		if (!first.hasResourceDescription(desc.getURI())) {
			first = new DescriptionAddingContainer(desc, first);
			result.set(0, first);
		}
	}
	return result;
}
 
Example #4
Source File: StateBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
		return delegate.getContainer(desc, resourceDescriptions);
	}
	String root = internalGetContainerHandle(desc, resourceDescriptions);
	if (root == null) {
		if (log.isDebugEnabled())
			log.debug("Cannot find IContainer for: " + desc.getURI());
		return IContainer.NULL_CONTAINER;
	}
	IContainer result = createContainer(root, resourceDescriptions);
	if (!result.hasResourceDescription(desc.getURI())) {
		// desc has not been saved -> merge containers
		result = new DescriptionAddingContainer(desc, result);
	}
	return result;
}
 
Example #5
Source File: UserDataAwareScope.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Factory method to produce a scope. The factory pattern allows to bypass the explicit object creation if the
 * produced scope would be empty.
 *
 * @param canLoadFromDescriptionHelper
 *            utility to decide if a resource must be loaded from source or may be loaded from the index.
 */
public static IScope createScope(
		IScope outer,
		ISelectable selectable,
		Predicate<IEObjectDescription> filter,
		EClass type, boolean ignoreCase,
		ResourceSet resourceSet,
		CanLoadFromDescriptionHelper canLoadFromDescriptionHelper,
		IContainer container) {
	if (selectable == null || selectable.isEmpty())
		return outer;
	IScope scope = new UserDataAwareScope(outer, selectable, filter, type, ignoreCase, resourceSet,
			canLoadFromDescriptionHelper,
			container);
	return scope;
}
 
Example #6
Source File: DefaultUniqueNameContext.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) {
	List<IContainer> containers = containerManager.getVisibleContainers(candidate, context);
	for (IResourceDescription.Delta delta : deltas) {
		if (delta.getNew() == null) {
			if (intersects(delta.getOld(), candidate, true)) {
				return true;
			}
		} else {
			containers: for (IContainer container : containers) {
				if (container.getResourceDescription(delta.getUri()) != null) {
					if (isAffected(delta, candidate, true)) {
						return true;
					}
					break containers;
				}
			}
		}
	}
	return false;
}
 
Example #7
Source File: CachingStateBasedContainerManager.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected synchronized IContainer createContainer(final String handle, final IResourceDescriptions resourceDescriptions) {
  final IResourceDescriptions descriptionsKey = resourceDescriptions instanceof CurrentDescriptions2.ResourceSetAware
      ? ((CurrentDescriptions2.ResourceSetAware) resourceDescriptions).getDelegate()
      : resourceDescriptions;

  Map<String, WeakReference<IContainer>> containersMap = descriptionsContainersCache.get(descriptionsKey);
  if (containersMap == null) {
    containersMap = new HashMap<String, WeakReference<IContainer>>();
    descriptionsContainersCache.put(descriptionsKey, containersMap);
  }

  WeakReference<IContainer> containerRef = containersMap.get(handle);
  IContainer container = containerRef != null ? containerRef.get() : null;
  if (container == null) {
    final IContainerState containerState = new ContainerState(handle, getStateProvider().get(descriptionsKey));
    container = new StateBasedContainerWithHandle(descriptionsKey, containerState, handle);
    new CacheInvalidator(descriptionsKey, handle, containerState);
    containerRef = new WeakReference<IContainer>(container);
    containersMap.put(handle, containerRef);
  }

  return container;
}
 
Example #8
Source File: DefaultUniqueNameContext.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isAffected(Collection<IResourceDescription.Delta> deltas, IResourceDescription candidate,
		IResourceDescriptions context) {
	IContainer container = containerManager.getContainer(candidate, context);
	for (IResourceDescription.Delta delta : deltas) {
		if (delta.getNew() == null) {
			if (intersects(delta.getOld(), candidate, true)) {
				return true;
			}
		} else if (container.getResourceDescription(delta.getUri()) != null) {
			if (isAffected(delta, candidate, true)) {
				return true;
			}
		}
	}
	return false;
}
 
Example #9
Source File: AbstractPolymorphicScopeProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Return the visible containers given a resource.
 *
 * @param resource
 *          the resource. Must not be {@code null}
 * @return The list of visible containers.
 */
protected List<IContainer> getVisibleContainers(final XtextResource resource) {
  URI uri = resource.getURI();
  List<IContainer> result = null;
  final ResourceCache<URI, List<IContainer>> cache = CacheManager.getInstance().getOrCreateResourceCache("AbstractPolymorphicScopeProvider#visibleContainers", resource); //$NON-NLS-1$
  if (cache != null) {
    result = cache.get(uri);
    if (result != null) {
      return result;
    }
  }

  final IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider();
  final IResourceDescription.Manager descriptionManager = resourceServiceProvider.getResourceDescriptionManager();
  final IContainer.Manager containerManager = resourceServiceProvider.getContainerManager();

  final IResourceDescription description = descriptionManager.getResourceDescription(resource);
  final IResourceDescriptions resourceDescriptions = getResourceDescriptions(resource);
  result = containerManager.getVisibleContainers(description, resourceDescriptions);
  if (cache != null) {
    cache.set(uri, result);
  }
  return result;
}
 
Example #10
Source File: JavaSourceLanguageRuntimeModule.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
	bind(Resource.Factory.class).to(JavaResource.Factory.class);
	bind(IResourceValidator.class).toInstance(IResourceValidator.NULL);
	bind(IGenerator.class).to(IGenerator.NullGenerator.class);
	bind(IEncodingProvider.class).to(IEncodingProvider.Runtime.class);
	bind(IResourceServiceProvider.class).to(JavaResourceServiceProvider.class);
	bind(IContainer.Manager.class).to(SimpleResourceDescriptionsBasedContainerManager.class);
	bind(IResourceDescription.Manager.class).to(JavaResourceDescriptionManager.class);
	bind(IQualifiedNameProvider.class).to(JvmIdentifiableQualifiedNameProvider.class);
	bind(String.class).annotatedWith(Names.named(Constants.FILE_EXTENSIONS)).toInstance("java");
	bind(String.class).annotatedWith(Names.named(Constants.LANGUAGE_NAME))
			.toInstance("org.eclipse.xtext.java.Java");
	bind(IJvmTypeProvider.Factory.class).to(ClasspathTypeProviderFactory.class);
	bind(ClassLoader.class).toInstance(JavaSourceLanguageRuntimeModule.class.getClassLoader());
	bind(IReferableElementsUnloader.class).to(IReferableElementsUnloader.GenericUnloader.class);
	bind(IResourceDescriptionsProvider.class)
			.toInstance((ResourceSet rs) -> ChunkedResourceDescriptions.findInEmfObject(rs));
}
 
Example #11
Source File: AbstractLiveContainerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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()));
}
 
Example #12
Source File: BuilderIntegrationFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Set<Binding> getGuiceBindingsRt(Grammar grammar) {
	return new BindFactory()
	.addTypeToType(IContainer.Manager.class.getName(), StateBasedContainerManager.class.getName())
	.addTypeToType(IAllContainersState.Provider.class.getName(),
			org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.class.getName())
	.addConfiguredBinding(
				IResourceDescriptions.class.getName(),
				"binder.bind(" + IResourceDescriptions.class.getName() + ".class"
						+ ").to("
						+ ResourceSetBasedResourceDescriptions.class.getName() + ".class)")
		.addConfiguredBinding(
				IResourceDescriptions.class.getName() + "Persisted",
				"binder.bind("+ IResourceDescriptions.class.getName() + ".class"
						+ ").annotatedWith(com.google.inject.name.Names.named("
						+ "org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider.PERSISTED_DESCRIPTIONS)).to("
						+ ResourceSetBasedResourceDescriptions.class.getName() + ".class)")
		.getBindings();
}
 
Example #13
Source File: SGenGlobalScopeProvider.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Overidden to avoid scope nesting which comes with shadowing problems when
 * potential elements in scope have the same name
 */
@Override
protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
	IScope result = parent;
	if (context == null || context.getResourceSet() == null)
		return result;
	List<IContainer> containers = Lists.newArrayList(getVisibleContainers(context));
	Collections.reverse(containers);
	List<IEObjectDescription> objectDescriptions = new ArrayList<IEObjectDescription>();
	Iterator<IContainer> iter = containers.iterator();
	while (iter.hasNext()) {
		IContainer container = iter.next();
		result = createContainerScopeWithContext(context, IScope.NULLSCOPE, container, filter, type, ignoreCase);
		Iterables.addAll(objectDescriptions, result.getAllElements());
	}
	return new SimpleScope(objectDescriptions);
}
 
Example #14
Source File: DefaultGlobalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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);
		// SZ: I'ld like this dependency to be moved to the implementation of the
		// 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;
}
 
Example #15
Source File: DefaultGlobalScopeProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IScope getScope(IScope parent, final Resource context, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
	IScope result = parent;
	if (context == null || context.getResourceSet() == null)
		return result;
	List<IContainer> containers = Lists.newArrayList(getVisibleContainers(context));
	Collections.reverse(containers);
	Iterator<IContainer> iter = containers.iterator();
	while (iter.hasNext()) {
		IContainer container = iter.next();
		result = createContainerScopeWithContext(context, result, container, filter, type, ignoreCase);
	}
	return result;
}
 
Example #16
Source File: AbstractLiveContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
public void testNonNormalizedURIs() throws Exception {
	ResourceSet resourceSet = new XtextResourceSet();
	parser.parse("B", URI.createURI("a." + parser.fileExtension), resourceSet);
	parser.parse("B", URI.createURI("b." + parser.fileExtension), resourceSet);
	IResourceDescriptions index = descriptionsProvider.getResourceDescriptions(resourceSet);
	IResourceDescription rd = index.getResourceDescription(URI.createURI("a." + parser.fileExtension));
	List<IContainer> containers = containerManager.getVisibleContainers(rd, index);
	List<IEObjectDescription> objects = Lists.newArrayList();
	EClass type = (EClass) grammarAccess.getGrammar().getRules().get(0).getType().getClassifier();
	for (IContainer container : containers)
		Iterables.addAll(objects, container.getExportedObjects(type, QualifiedName.create("B"), false));
	assertEquals(2, objects.size());
}
 
Example #17
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc,
		IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	ProjectDescription projectDescription = ProjectDescription.findInEmfObject(descriptions.getResourceSet());
	List<IContainer> allContainers = new ArrayList<>();
	allContainers.add(createContainer(resourceDescriptions, descriptions, projectDescription.getName()));
	for (String name : projectDescription.getDependencies())
		allContainers.add(createContainer(resourceDescriptions, descriptions, name));
	return allContainers;
}
 
Example #18
Source File: StateBasedContainerManagerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetVisibleContainers_01() {
	IResourceDescription description = new URIBasedTestResourceDescription(uri1);
	List<IContainer> visibleContainers = containerManager.getVisibleContainers(description, this);
	assertEquals(2, visibleContainers.size());
	assertEquals(2, Iterables.size(visibleContainers.get(0).getResourceDescriptions()));
	assertEquals(1, Iterables.size(visibleContainers.get(1).getResourceDescriptions()));
	assertNotNull(visibleContainers.get(0).getResourceDescription(uri1));
	assertNotNull(visibleContainers.get(0).getResourceDescription(uri2));
	assertNotNull(visibleContainers.get(1).getResourceDescription(uri3));
}
 
Example #19
Source File: RuntimeServerModule.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    binder().bind(ExecutorService.class).toProvider(ExecutorServiceProvider.class);

    bind(UriExtensions.class).toInstance(new MappingUriExtensions(ConfigConstants.getConfigFolder()));
    bind(LanguageServer.class).to(LanguageServerImpl.class);
    bind(IResourceServiceProvider.Registry.class).toProvider(new RegistryProvider(scriptServiceUtil, scriptEngine));
    bind(IWorkspaceConfigFactory.class).to(ProjectWorkspaceConfigFactory.class);
    bind(IProjectDescriptionFactory.class).to(DefaultProjectDescriptionFactory.class);
    bind(IContainer.Manager.class).to(ProjectDescriptionBasedContainerManager.class);
    bind(ILanguageServerShutdownAndExitHandler.class).to(ILanguageServerShutdownAndExitHandler.NullImpl.class);
}
 
Example #20
Source File: BuilderIntegrationFragment.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Set<Binding> getGuiceBindingsRt(final Grammar grammar) {
  final Set<Binding> bindings = super.getGuiceBindingsRt(grammar);
  final BindFactory factory = new BindFactory();
  factory.addTypeToType(IContainer.Manager.class.getName(), "com.avaloq.tools.ddk.xtext.builder.CachingStateBasedContainerManager");
  factory.addTypeToType(LazyLinkingResource.class.getName(), LazyLinkingResource2.class.getName());
  factory.addTypeToType(LazyURIEncoder.class.getName(), FastLazyURIEncoder.class.getName());
  final Set<Binding> result = factory.getBindings();
  result.addAll(bindings);
  return result;
}
 
Example #21
Source File: ContainerQuery.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Run a query on a single container.
 *
 * @param container
 *          The container
 * @return The query result.
 */
public Iterable<IEObjectDescription> execute(final IContainer container) { // NOPMD NPathComplexity by WTH on 24.11.10 06:07
  if (domains != null && !domains.isEmpty() && domainMapper != null) {
    IDomain domain = domainMapper.map(container);
    if (domain != null && !domains.contains(domain.getName())) {
      // Query not applicable to this container.
      return ImmutableList.of();
    }
  }

  // Warning: we assume that our Containers and ResourceDescriptions from the index can handle name patterns.
  Iterable<IEObjectDescription> result = namePattern != null ? container.getExportedObjects(getType(), namePattern, doIgnoreCase)
      : container.getExportedObjectsByType(getType());

  if (getUserData() != null && !getUserData().isEmpty()) {
    final Map<String, String> userDataEquals = getUserData();
    final Predicate<IEObjectDescription> userDataPredicate = new Predicate<IEObjectDescription>() {
      @Override
      public boolean apply(final IEObjectDescription input) {
        for (final Entry<String, String> entry : userDataEquals.entrySet()) {
          if (!entry.getValue().equals(input.getUserData(entry.getKey()))) {
            return false;
          }
        }
        return true;
      }
    };
    result = Iterables.filter(result, userDataPredicate);
  }

  return result;
}
 
Example #22
Source File: SimpleResourceDescriptionsBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<IContainer> getVisibleContainers(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	if (delegate.shouldUseProjectDescriptionBasedContainers(resourceDescriptions)) {
		return delegate.getVisibleContainers(desc, resourceDescriptions);
	}
	return Collections.singletonList(getContainer(desc, resourceDescriptions));
}
 
Example #23
Source File: ContainerQuery.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Execute the query on a list of containers, in the order given.
 *
 * @param containers
 *          The containers.
 * @return The query result.
 */
public Iterable<IEObjectDescription> execute(final Iterable<IContainer> containers) {
  if (Iterables.size(containers) == 1) {
    return execute(containers.iterator().next());
  }

  return Iterables.concat(Iterables.transform(containers, new Function<IContainer, Iterable<IEObjectDescription>>() {
    @Override
    public Iterable<IEObjectDescription> apply(final IContainer container) {
      return execute(container);
    }
  }));
}
 
Example #24
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected IContainer createContainer(IResourceDescriptions resourceDescriptions,
		ChunkedResourceDescriptions chunkedResourceDescriptions, String projectName) {
	if (resourceDescriptions instanceof LiveShadowedChunkedResourceDescriptions) {
		return new LiveShadowedChunkedContainer((LiveShadowedChunkedResourceDescriptions) resourceDescriptions,
				projectName);
	} else {
		ResourceDescriptionsData container = chunkedResourceDescriptions.getContainer(projectName);
		return new ResourceDescriptionsBasedContainer(
				container != null ? container : new ResourceDescriptionsData(Collections.emptySet()));
	}
}
 
Example #25
Source File: StateBasedContainerManagerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testGetContainer_01() {
	IResourceDescription description = new URIBasedTestResourceDescription(uri1);
	IContainer container = containerManager.getContainer(description, this);
	assertEquals(2, Iterables.size(container.getResourceDescriptions()));
	assertNotNull(container.getResourceDescription(uri1));
	assertNotNull(container.getResourceDescription(uri2));
	assertNull(container.getResourceDescription(uri3));
}
 
Example #26
Source File: ProjectDescriptionBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IContainer getContainer(IResourceDescription desc, IResourceDescriptions resourceDescriptions) {
	ChunkedResourceDescriptions descriptions = getChunkedResourceDescriptions(resourceDescriptions);
	if (descriptions == null)
		throw new IllegalArgumentException("Expected " + ChunkedResourceDescriptions.class.getName());
	return createContainer(resourceDescriptions, descriptions,
			ProjectDescription.findInEmfObject(descriptions.getResourceSet()).getName());
}
 
Example #27
Source File: DefaultUniqueNameContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Context tryGetContext(Resource resource, CancelIndicator cancelIndicator) {
	IResourceDescriptions index = getIndex(resource);
	if (index == null) {
		return null;
	}
	IResourceDescription description = getResourceDescription(resource);
	if (description == null) {
		return null;
	}
	IContainer container = containerManager.getContainer(description, index);
	return new DefaultUniqueNameContext(description, container, getCaseInsensitivityHelper(), cancelIndicator);
}
 
Example #28
Source File: DefaultUniqueNameContext.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Context tryGetContext(Resource resource, CancelIndicator cancelIndicator) {
	IResourceDescriptions index = getIndex(resource);
	if (index == null) {
		return null;
	}
	IResourceDescription description = getResourceDescription(resource);
	if (description == null) {
		return null;
	}
	List<IContainer> containers = containerManager.getVisibleContainers(description, index);
	return new DefaultUniqueNameContext(description, new Selectable(containers), getCaseInsensitivityHelper(),
			cancelIndicator);
}
 
Example #29
Source File: StateBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected List<IContainer> getVisibleContainers(List<String> handles, IResourceDescriptions resourceDescriptions) {
	if (handles.isEmpty())
		return Collections.emptyList();
	List<IContainer> result = Lists.newArrayListWithExpectedSize(handles.size());
	for(String handle: handles) {
		IContainer container = createContainer(handle, resourceDescriptions);
		if (!container.isEmpty() || result.isEmpty())
			result.add(container);
	}
	return result;
}
 
Example #30
Source File: StateBasedContainerManager.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.20
 */
protected IContainer createContainer(IResourceDescriptions resourceDescriptions, IAllContainersState allContainerState, IContainerState containerState) {
	StateBasedContainer result = new StateBasedContainer(resourceDescriptions, containerState);
	
	if (allContainerState instanceof FlatResourceSetBasedAllContainersState)
		result.setUriToDescriptionCacheEnabled(false);
	
	return result;
}