Search in sources :

Example 26 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.

the class DirtyStateAwareResourceDescriptions2 method findReferencesToObjects.

/**
 * {@inheritDoc}
 */
public Iterable<IReferenceDescription> findReferencesToObjects(final Set<URI> targetObjects) {
    final Set<URI> dirtyReferencingUris = Sets.newHashSet();
    Iterable<IReferenceDescription> dirtyReferences = Collections.emptyList();
    for (URI dirtyURI : dirtyResources) {
        IResourceDescription desc = dirtyStateManager.getDirtyResourceDescription(dirtyURI);
        if (desc == null) {
            continue;
        }
        Iterable<IReferenceDescription> local = Iterables.filter(desc.getReferenceDescriptions(), new Predicate<IReferenceDescription>() {

            public boolean apply(final IReferenceDescription input) {
                return targetObjects.contains(input.getTargetEObjectUri());
            }
        });
        if (!Iterables.isEmpty(local)) {
            dirtyReferences = Iterables.concat(dirtyReferences, local);
            dirtyReferencingUris.add(desc.getURI());
        }
    }
    return Iterables.concat(dirtyReferences, Iterables.filter(globalDescriptions.findReferencesToObjects(targetObjects), new Predicate<IReferenceDescription>() {

        public boolean apply(final IReferenceDescription input) {
            return !dirtyReferencingUris.contains(input.getSourceEObjectUri().trimQuery().trimFragment());
        }
    }));
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Predicate(com.google.common.base.Predicate)

Example 27 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.

the class FastReferenceSearchResultContentProvider method inputChanged.

@Override
public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) {
    synchronized (v) {
        rootNodes.clear();
        if (oldInput instanceof ReferenceSearchResult) {
            ((ReferenceSearchResult) oldInput).removeListener(this);
        }
        if (newInput instanceof ReferenceSearchResult && v instanceof TreeViewer) {
            ((ReferenceSearchResult) newInput).addListener(this);
            this.viewer = (TreeViewer) v;
            for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput).getMatchingReferences()) {
                addReference(referenceDescription);
            }
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ReferenceSearchResult(org.eclipse.xtext.ui.editor.findrefs.ReferenceSearchResult) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 28 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.

the class ReferenceFinder2 method findAllIndexedReferences.

/**
 * Uses IResourceDescriptions2 to find all indexed references.
 *
 * @param targetURIs
 *          the URIs to find references to, must not be {@code null}
 * @param indexData
 *          index to use when finding references, must not be {@code null}
 * @param referenceAcceptor
 *          the reference acceptor, must not be {@code null}
 * @param subMonitor
 *          the progress monitor, can be {@code null}
 */
protected void findAllIndexedReferences(final TargetURIs targetURIs, final IResourceDescriptions indexData, final Acceptor referenceAcceptor, final SubMonitor subMonitor) {
    IResourceDescriptions2 idx = (IResourceDescriptions2) indexData;
    List<IReferenceDescription> refs = uniqueReferences(Lists.newArrayList(idx.findReferencesToObjects(targetURIs.asSet())));
    final SubMonitor monitor = SubMonitor.convert(subMonitor, Messages.ReferenceQuery_monitor, refs.size());
    for (IReferenceDescription desc : refs) {
        if (monitor.isCanceled()) {
            return;
        }
        referenceAcceptor.accept(desc);
        monitor.worked(1);
    }
    monitor.done();
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) IResourceDescriptions2(com.avaloq.tools.ddk.xtext.resource.extensions.IResourceDescriptions2) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 29 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.

the class ResourceDescriptionsUtil method findExactReferencingResources.

/**
 * Utility implementation to find all exact references to a set of objects.
 *
 * @param descriptions
 *          context
 * @param targetObjects
 *          objects to find references to
 * @param matchPolicy
 *          match policy
 * @return all resources containing outgoing references to one of the objects
 */
@SuppressWarnings("PMD.NPathComplexity")
public static Iterable<IResourceDescription> findExactReferencingResources(final IResourceDescriptions descriptions, final Set<IEObjectDescription> targetObjects, final ReferenceMatchPolicy matchPolicy) {
    if (targetObjects.isEmpty()) {
        return ImmutableSet.of();
    }
    final Set<URI> targetUris = Sets.newHashSetWithExpectedSize(targetObjects.size());
    final Set<QualifiedName> exportedNames = Sets.newHashSet();
    for (IEObjectDescription obj : targetObjects) {
        targetUris.add(obj.getEObjectURI());
        if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES)) {
            exportedNames.add(obj.getName());
        }
        if (matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
            exportedNames.add(QualifiedNames.toUnresolvedName(obj.getName()));
        }
    }
    return Iterables.filter(descriptions.getAllResourceDescriptions(), input -> {
        if (matchPolicy.includes(ReferenceMatchPolicy.IMPORTED_NAMES) || matchPolicy.includes(ReferenceMatchPolicy.UNRESOLVED_IMPORTED_NAMES)) {
            for (QualifiedName name : input.getImportedNames()) {
                if (exportedNames.contains(name)) {
                    return true;
                }
            }
        }
        if (matchPolicy.includes(ReferenceMatchPolicy.REFERENCES)) {
            for (IReferenceDescription ref : input.getReferenceDescriptions()) {
                if (targetUris.contains(ref.getTargetEObjectUri())) {
                    return true;
                }
            }
        }
        return false;
    });
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 30 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project dsl-devkit by dsldevkit.

the class ResourceDescription2 method computeReferenceDescriptions.

@Override
protected List<IReferenceDescription> computeReferenceDescriptions() {
    final ImmutableList.Builder<IReferenceDescription> referenceDescriptions = ImmutableList.builder();
    EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl);
    Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
    TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(getResource(), true);
    while (contents.hasNext()) {
        EObject eObject = contents.next();
        URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
        if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, referenceDescriptions::add)) {
            contents.prune();
        }
    }
    if (strategy instanceof AbstractResourceDescriptionStrategy) {
        ((AbstractResourceDescriptionStrategy) strategy).createImplicitReferenceDescriptions(getResource(), referenceDescriptions::add);
    }
    return referenceDescriptions.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) EObject(org.eclipse.emf.ecore.EObject) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)42 URI (org.eclipse.emf.common.util.URI)18 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)17 EObject (org.eclipse.emf.ecore.EObject)12 Test (org.junit.Test)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)7 EReference (org.eclipse.emf.ecore.EReference)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Main (org.eclipse.xtext.linking.langATestLanguage.Main)3