Search in sources :

Example 1 with AbstractCachingResourceDescriptionManager

use of com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager in project dsl-devkit by dsldevkit.

the class MonitoredClusteringBuilderState method queueAffectedResources.

/**
 * {@inheritDoc}
 */
@Override
protected void queueAffectedResources(final Set<URI> allRemainingURIs, final IResourceDescriptions oldState, final CurrentDescriptions newState, final Collection<Delta> changedDeltas, final Collection<Delta> allDeltas, final BuildData buildData, final IProgressMonitor monitor) {
    if (allDeltas.isEmpty() || allRemainingURIs.isEmpty()) {
        return;
    }
    ImmutableListMultimap<Manager, URI> candidatesByManager = getUrisByManager(allRemainingURIs);
    FindReferenceCachingState cachingIndex = new FindReferenceCachingState((IResourceDescriptions2) newState);
    final SubMonitor progressMonitor = SubMonitor.convert(monitor, candidatesByManager.keySet().size());
    for (Manager manager : candidatesByManager.keySet()) {
        Collection<Delta> deltas = changedDeltas;
        if (manager instanceof IResourceDescription.Manager.AllChangeAware) {
            deltas = allDeltas;
        }
        try {
            if (manager instanceof AbstractCachingResourceDescriptionManager) {
                checkForCancellation(monitor);
                AbstractCachingResourceDescriptionManager bulkManager = (AbstractCachingResourceDescriptionManager) manager;
                Set<URI> candidates = Sets.newHashSet(candidatesByManager.get(bulkManager));
                candidates.retainAll(allRemainingURIs);
                Collection<URI> affected = bulkManager.getAffectedResources(deltas, candidates, cachingIndex);
                for (URI uri : affected) {
                    if (allRemainingURIs.remove(uri)) {
                        buildData.queueURI(uri);
                    }
                }
            } else {
                for (URI candidateURI : candidatesByManager.get(manager)) {
                    checkForCancellation(monitor);
                    if (allRemainingURIs.contains(candidateURI)) {
                        boolean affected = false;
                        if (manager instanceof IResourceDescription.Manager.AllChangeAware) {
                            affected = ((IResourceDescription.Manager.AllChangeAware) manager).isAffectedByAny(deltas, oldState.getResourceDescription(candidateURI), cachingIndex);
                        } else {
                            affected = manager.isAffected(deltas, oldState.getResourceDescription(candidateURI), cachingIndex);
                        }
                        if (affected) {
                            allRemainingURIs.remove(candidateURI);
                            buildData.queueURI(candidateURI);
                        }
                    }
                }
            }
        } catch (OperationCanceledException e) {
            throw e;
        // CHECKSTYLE:CHECK-OFF IllegalCatch - Failing here means the build fails completely
        } catch (Throwable t) {
            // CHECKSTYLE:CHECK-ON IllegalCatch
            // $NON-NLS-1$
            LOGGER.warn(manager.getClass().getSimpleName() + " failed to enqueue the affected resources", t);
        }
        progressMonitor.worked(1);
        if (allRemainingURIs.isEmpty()) {
            break;
        }
    }
}
Also used : AbstractCachingResourceDescriptionManager(com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) Manager(org.eclipse.xtext.resource.IResourceDescription.Manager) AbstractCachingResourceDescriptionManager(com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager) IXtextTargetPlatformManager(com.avaloq.tools.ddk.xtext.builder.layered.IXtextTargetPlatformManager) URI(org.eclipse.emf.common.util.URI) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) DefaultResourceDescriptionDelta(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)

Example 2 with AbstractCachingResourceDescriptionManager

use of com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager in project dsl-devkit by dsldevkit.

the class CheckCfgUtil method getAllLanguages.

/**
 * Gets the all languages available in the workbench.
 *
 * @return set of all languages
 */
public Set<String> getAllLanguages() {
    Set<String> languages = new HashSet<String>();
    for (String extension : Registry.INSTANCE.getExtensionToFactoryMap().keySet()) {
        final URI dummyUri = URI.createURI("foo:/foo." + extension);
        IResourceServiceProvider resourceServiceProvider = Registry.INSTANCE.getResourceServiceProvider(dummyUri);
        // By checking that description manager is AbstractCachingResourceDescriptionManager we exclude technical languages of the framework
        if (resourceServiceProvider != null && resourceServiceProvider.getResourceDescriptionManager() instanceof AbstractCachingResourceDescriptionManager) {
            try {
                IGrammarAccess grammarAccess = resourceServiceProvider.get(IGrammarAccess.class);
                if (grammarAccess != null && grammarAccess.getGrammar() != null) {
                    languages.add(grammarAccess.getGrammar().getName());
                }
            } catch (ConfigurationException e) {
            // Will happen if no binding for IGrammarAccess was present.
            }
        }
    }
    return languages;
}
Also used : AbstractCachingResourceDescriptionManager(com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) ConfigurationException(com.google.inject.ConfigurationException) URI(org.eclipse.emf.common.util.URI) HashSet(java.util.HashSet)

Aggregations

AbstractCachingResourceDescriptionManager (com.avaloq.tools.ddk.xtext.resource.AbstractCachingResourceDescriptionManager)2 URI (org.eclipse.emf.common.util.URI)2 IXtextTargetPlatformManager (com.avaloq.tools.ddk.xtext.builder.layered.IXtextTargetPlatformManager)1 ConfigurationException (com.google.inject.ConfigurationException)1 HashSet (java.util.HashSet)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 Delta (org.eclipse.xtext.resource.IResourceDescription.Delta)1 Manager (org.eclipse.xtext.resource.IResourceDescription.Manager)1 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)1 DefaultResourceDescriptionDelta (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionDelta)1 OperationCanceledManager (org.eclipse.xtext.service.OperationCanceledManager)1