Search in sources :

Example 6 with OnChangeEvictingCache

use of org.eclipse.xtext.util.OnChangeEvictingCache 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 7 with OnChangeEvictingCache

use of org.eclipse.xtext.util.OnChangeEvictingCache in project xtext-core by eclipse.

the class KeywordInspectorTest method validateRule.

public void validateRule(AbstractRule rule) {
    assertNotNull("rule", rule);
    warnings.clear();
    KeywordInspector inspector = new KeywordInspector(this, new OnChangeEvictingCache());
    Iterator<Keyword> keywords = Iterators.filter(EcoreUtil.getAllContents(rule, true), Keyword.class);
    while (keywords.hasNext()) inspector.inspectKeywordHidesTerminalRule(keywords.next());
}
Also used : Keyword(org.eclipse.xtext.Keyword) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache)

Aggregations

OnChangeEvictingCache (org.eclipse.xtext.util.OnChangeEvictingCache)7 IResourceScopeCache (org.eclipse.xtext.util.IResourceScopeCache)4 EObject (org.eclipse.emf.ecore.EObject)2 ResourceDescription2 (com.avaloq.tools.ddk.xtext.resource.ResourceDescription2)1 List (java.util.List)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Grammar (org.eclipse.xtext.Grammar)1 Keyword (org.eclipse.xtext.Keyword)1 IDiagnosticConsumer (org.eclipse.xtext.diagnostics.IDiagnosticConsumer)1 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ParseResult (org.eclipse.xtext.parser.ParseResult)1 IContainer (org.eclipse.xtext.resource.IContainer)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 Source (org.eclipse.xtext.resource.IResourceDescription.Event.Source)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1