use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class ResourceDescriptionsProvider method getResourceDescriptions.
/**
* Provides the proper resource descriptions according to the context in which the resource set is used.
*
* The context is indicated by the {@link ResourceSet#getLoadOptions() load options} of the resource set. Supported
* options are:
*
* <ol>
* <li>{@link #NAMED_BUILDER_SCOPE}</li>
* <li>{@link #LIVE_SCOPE}</li>
* <li>{@link #PERSISTED_DESCRIPTIONS}</li>
* <li>If no such option is present the dirty editors are taken into account to contribute their contents to the
* index</li>
* </ol>
*
* The result is never <code>null</code>.
*
* @param resourceSet
* the resource set that is currently used.
* @return the {@link IResourceDescriptions} according to the usage context.
*
* @since 2.1
*/
/* @NonNull */
@Override
public IResourceDescriptions getResourceDescriptions(/* @NonNull */
ResourceSet resourceSet) {
String flag = getFlagFromLoadOptions(resourceSet);
IResourceDescriptions result;
if (NAMED_BUILDER_SCOPE.equals(flag)) {
result = createBuilderScopeResourceDescriptions();
} else if (LIVE_SCOPE.equals(flag)) {
result = createLiveScopeResourceDescriptions();
} else if (PERSISTED_DESCRIPTIONS.equals(flag)) {
result = createPersistedResourceDescriptions();
} else {
result = ChunkedResourceDescriptions.findInEmfObject(resourceSet);
if (result == null) {
result = createResourceDescriptions();
}
}
if (result instanceof IResourceDescriptions.IContextAware) {
((IResourceDescriptions.IContextAware) result).setContext(resourceSet);
}
return result;
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class PortableURIs method getPortableURIFragment.
/**
* @return a portable URI fragment, or <code>null</code> if the give EObject isn't itself or is not contained in an
* exported EObjectDescription
*/
protected String getPortableURIFragment(EObject obj) {
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(obj.eResource());
IResourceDescription desc = descriptions.getResourceDescription(obj.eResource().getURI());
if (desc == null) {
return null;
}
return Streams.stream(desc.getExportedObjects()).filter(description -> {
EObject possibleContainer = EcoreUtil.resolve(description.getEObjectOrProxy(), obj.eResource());
return EcoreUtil.isAncestor(obj, possibleContainer);
}).map(containerDesc -> {
PortableFragmentDescription fragmentDescription = createPortableFragmentDescription(containerDesc, obj);
return toFragmentString(fragmentDescription);
}).findFirst().orElse(null);
}
use of org.eclipse.xtext.resource.IResourceDescriptions 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;
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class PartialLinkingTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
IQualifiedNameConverter nameConverter = new IQualifiedNameConverter.DefaultImpl();
IQualifiedNameProvider nameProvider = new DefaultDeclarativeQualifiedNameProvider();
ImportUriGlobalScopeProvider globalScopeProvider = new ImportUriGlobalScopeProvider();
globalScopeProvider.setImportResolver(new ImportUriResolver());
globalScopeProvider.setCache(IResourceScopeCache.NullImpl.INSTANCE);
final ResourceDescriptionsProvider provider = new ResourceDescriptionsProvider();
provider.setResourceDescriptions(new Provider<IResourceDescriptions>() {
@Override
public IResourceDescriptions get() {
return new IResourceDescriptions.NullImpl();
}
});
globalScopeProvider.setResourceDescriptionsProvider(provider);
globalScopeProvider.setLoadOnDemandDescriptions(new Provider<LoadOnDemandResourceDescriptions>() {
@Override
public LoadOnDemandResourceDescriptions get() {
return PartialLinkingTest.this.get(LoadOnDemandResourceDescriptions.class);
}
});
CaseInsensitivityHelper caseInsensitivityHelper = new CaseInsensitivityHelper();
globalScopeProvider.setCaseInsensitivityHelper(caseInsensitivityHelper);
scopeProvider = new ImportedNamespaceAwareLocalScopeProvider(globalScopeProvider, nameProvider, nameConverter, caseInsensitivityHelper);
modelAsText = "spielplatz 1 {\n" + " kind( Bommel1 1)\n" + " kind( Bommel2 2)\n" + " kind( Bommel3 3)\n" + " erwachsener( Bob 4)\n" + " erwachsener( Joe 5)\n" + " familie( Familienname Bob Joe Bommel2 )\n" + "}";
resource = getResourceFromString(modelAsText);
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
model = resource.getParseResult().getRootASTElement();
final Iterator<EObject> iter = model.eAllContents();
while (iter.hasNext() && context == null) {
final EObject candidate = iter.next();
final String className = candidate.eClass().getName();
if (className.endsWith("Familie"))
context = candidate;
}
reference = (EReference) context.eClass().getEStructuralFeature("kinder");
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-core by eclipse.
the class AbstractLiveContainerTest method testContainerAddRemove.
@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()));
}
Aggregations