Java 类org.eclipse.xtext.resource.IReferenceDescription 实例源码

项目:n4js    文件:BuilderUtil.java   
/***/
public static Set<IReferenceDescription> getIncomingReferences(URI uri) {
    Set<IReferenceDescription> desc = Sets.newHashSet();
    Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
    for (IResourceDescription res : descriptions) {
        Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
        for (IReferenceDescription ref : descriptions2) {
            if (uri.hasFragment()) {
                if (ref.getTargetEObjectUri().equals(uri))
                    desc.add(ref);
            } else {
                if (ref.getTargetEObjectUri().trimFragment().equals(uri.trimFragment()))
                    desc.add(ref);
            }
        }
    }
    return desc;
}
项目:n4js    文件:BuilderUtil.java   
/***/
public static Set<IReferenceDescription> getContainedReferences(URI uri) {
    Set<IReferenceDescription> desc = Sets.newHashSet();
    Iterable<IResourceDescription> descriptions = getAllResourceDescriptions();
    for (IResourceDescription res : descriptions) {
        Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
        for (IReferenceDescription ref : descriptions2) {
            if (uri.hasFragment()) {
                if (ref.getSourceEObjectUri().equals(uri))
                    desc.add(ref);
            } else {
                if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment()))
                    desc.add(ref);
            }
        }
    }
    return desc;
}
项目:n4js    文件:N4JSReferenceQueryExecutor.java   
/**
 * Returns <code>true</code> if the reference should be presented to the user.
 */
@Override
protected boolean isRelevantToUser(IReferenceDescription referenceDescription) {
    if (referenceDescription instanceof LabelledReferenceDescription) {
        EObject source = ((LabelledReferenceDescription) referenceDescription).getSource();
        if (source.eContainer() instanceof JSXElementName && source.eContainer()
                .eContainingFeature() == N4JSPackage.eINSTANCE.getJSXElement_JsxClosingName()) {
            // Do not show JSX element's closing tag
            return false;
        } else {
            return true;
        }
    } else {
        return super.isRelevantToUser(referenceDescription);
    }
}
项目:n4js    文件:LabellingReferenceFinder.java   
@Override
protected Acceptor toAcceptor(IAcceptor<IReferenceDescription> acceptor) {
    return new ReferenceAcceptor(acceptor, getResourceServiceProviderRegistry()) {

        @Override
        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy,
                URI targetURI) {
            // Check if we should ignore named import specifier
            if (N4JSReferenceQueryExecutor.ignoreNamedImportSpecifier && source instanceof NamedImportSpecifier)
                return;

            EObject displayObject = calculateDisplayEObject(source);
            String logicallyQualifiedDisplayName = N4JSHierarchicalNameComputerHelper
                    .calculateLogicallyQualifiedDisplayName(displayObject, labelProvider, false);
            ICompositeNode srcNode = NodeModelUtils.getNode(source);
            int line = srcNode.getStartLine();
            LabelledReferenceDescription description = new LabelledReferenceDescription(source, displayObject,
                    sourceURI,
                    targetOrProxy,
                    targetURI,
                    eReference, index, logicallyQualifiedDisplayName, line);
            accept(description);
        }
    };
}
项目:n4js    文件:HeadlessReferenceFinder.java   
/**
 * Find all references to the given target with its resource set as working environment.
 *
 * @param target
 *            the object to look for.
 * @param monitor
 *            the progress monitor.
 * @return the list of reference descriptions.
 */
public List<IReferenceDescription> findReferencesTo(EObject target, IProgressMonitor monitor) {
    final TargetURIs targetURIs = getTargetURIs(target);
    final ResourceSet resourceSet = target.eResource().getResourceSet();
    final List<IReferenceDescription> result = Lists.newArrayList();
    IReferenceFinder.IResourceAccess resourceAccess = new SimpleResourceAccess(resourceSet);
    IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() {

        @Override
        public void accept(IReferenceDescription description) {
            result.add(description);
        }

        @Override
        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy,
                URI targetURI) {
            accept(new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, null));
        }
    };
    referenceFinder.findAllReferences(targetURIs, resourceAccess,
            resourceDescriptionsProvider.getResourceDescriptions(resourceSet),
            acceptor, monitor);
    return result;
}
项目:xtext-extras    文件:XbaseResourceDescriptionStrategyTest.java   
@Test
public void testNoReferenceDescriptionsForPackageFragments() {
  try {
    final XExpression expression = this.expression("java::lang::String::valueOf(\"\")");
    final Resource resource = expression.eResource();
    final IResourceDescription description = this.resourceDescriptionManager.getResourceDescription(resource);
    final Function1<IReferenceDescription, String> _function = (IReferenceDescription it) -> {
      return it.getTargetEObjectUri().toString();
    };
    final Set<String> referenceDescriptions = IterableExtensions.<String>toSet(IterableExtensions.<IReferenceDescription, String>map(description.getReferenceDescriptions(), _function));
    Assert.assertEquals(2, referenceDescriptions.size());
    final Set<String> expectation = Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet("java:/Objects/java.lang.String#java.lang.String", "java:/Objects/java.lang.String#java.lang.String.valueOf(java.lang.Object)"));
    Assert.assertEquals(expectation, referenceDescriptions);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:DefaultResourceDescription.java   
protected List<IReferenceDescription> computeReferenceDescriptions() {
    final List<IReferenceDescription> referenceDescriptions = Lists.newArrayList();
    IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
        @Override
        public void accept(IReferenceDescription referenceDescription) {
            referenceDescriptions.add(referenceDescription);
        }
    };
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
    TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(this.resource, true);
    while (contents.hasNext()) {
        EObject eObject = contents.next();
        URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
        if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, acceptor))
            contents.prune();
    }
    return referenceDescriptions;
}
项目:xtext-core    文件:ResourceStorageWritable.java   
protected void convertExternalURIsToPortableURIs(final SerializableResourceDescription description, final StorageAwareResource resource) {
  Iterable<IReferenceDescription> _referenceDescriptions = description.getReferenceDescriptions();
  for (final IReferenceDescription ref : _referenceDescriptions) {
    URI _trimFragment = ref.getTargetEObjectUri().trimFragment();
    URI _uRI = resource.getURI();
    boolean _notEquals = (!Objects.equal(_trimFragment, _uRI));
    if (_notEquals) {
      URI _elvis = null;
      URI _portableURI = resource.getPortableURIs().toPortableURI(resource, ref.getTargetEObjectUri());
      if (_portableURI != null) {
        _elvis = _portableURI;
      } else {
        URI _targetEObjectUri = ref.getTargetEObjectUri();
        _elvis = _targetEObjectUri;
      }
      ((SerializableReferenceDescription) ref).setTargetEObjectUri(_elvis);
    }
  }
}
项目:xtext-core    文件:DefaultReferenceDescriptionTest.java   
@Test public void testgetReferenceDescriptions() throws Exception {
    with(new LangATestLanguageStandaloneSetup());
    XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
    EObject typeC = targetResource.getContents().get(0).eContents().get(0);
    XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
    resource.load(new StringInputStream("type A extends C type B extends A"), null);
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
    Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
    Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
    assertEquals(1,collection.size());
    IReferenceDescription refDesc = descriptions.iterator().next();
    Main m = (Main) resource.getParseResult().getRootASTElement();
    assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(),false));
    assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(),false));
    assertEquals(-1,refDesc.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS,refDesc.getEReference());
}
项目:xtext-core    文件:DefaultReferenceDescriptionTest.java   
@Test public void testgetReferenceDescriptionForMultiValue() throws Exception {
    with(new LangATestLanguageStandaloneSetup());
    XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
    EObject typeC = targetResource.getContents().get(0).eContents().get(0);
    EObject typeD = targetResource.getContents().get(0).eContents().get(1);
    XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
    resource.load(new StringInputStream("type A implements B,C,D type B"), null);
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
    Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
    Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
    assertEquals(2,collection.size());
    Iterator<IReferenceDescription> iterator = descriptions.iterator();
    IReferenceDescription refDesc1 = iterator.next();
    IReferenceDescription refDesc2 = iterator.next();
    Main m = (Main) resource.getParseResult().getRootASTElement();
    assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(),false));
    assertEquals(typeC,resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(),false));
    assertEquals(1,refDesc1.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc1.getEReference());
    assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(),false));
    assertEquals(typeD,resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(),false));
    assertEquals(2,refDesc2.getIndexInList());
    assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc2.getEReference());
}
项目:xtext-core    文件:DocumentSymbolService.java   
public List<? extends Location> getReferences(final XtextResource resource, final int offset, final IReferenceFinder.IResourceAccess resourceAccess, final IResourceDescriptions indexData, final CancelIndicator cancelIndicator) {
  final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
  if ((element == null)) {
    return CollectionLiterals.<Location>emptyList();
  }
  final ArrayList<Location> locations = CollectionLiterals.<Location>newArrayList();
  final TargetURIs targetURIs = this.collectTargetURIs(element);
  final IAcceptor<IReferenceDescription> _function = (IReferenceDescription reference) -> {
    final Procedure1<EObject> _function_1 = (EObject obj) -> {
      final Location location = this._documentExtensions.newLocation(obj, reference.getEReference(), reference.getIndexInList());
      if ((location != null)) {
        locations.add(location);
      }
    };
    this.doRead(resourceAccess, reference.getSourceEObjectUri(), _function_1);
  };
  ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(this.resourceServiceProviderRegistry, _function);
  CancelIndicatorProgressMonitor _cancelIndicatorProgressMonitor = new CancelIndicatorProgressMonitor(cancelIndicator);
  this.referenceFinder.findAllReferences(targetURIs, resourceAccess, indexData, _referenceAcceptor, _cancelIndicatorProgressMonitor);
  return locations;
}
项目:xtext-core    文件:DefaultCallHierarchyBuilder.java   
@Override
public Collection<IHierarchyNode> buildChildren(final IHierarchyNode parent, final IProgressMonitor monitor) {
  boolean _mayHaveChildren = parent.mayHaveChildren();
  boolean _not = (!_mayHaveChildren);
  if (_not) {
    return CollectionLiterals.<IHierarchyNode>emptyList();
  }
  final LinkedHashMap<URI, IHierarchyNode> children = CollectionLiterals.<URI, IHierarchyNode>newLinkedHashMap();
  final Procedure2<IEObjectDescription, IReferenceDescription> _function = (IEObjectDescription declaration, IReferenceDescription reference) -> {
    final IHierarchyNode childNode = this.createChild(children, declaration, parent);
    if ((childNode != null)) {
      final IHierarchyNodeReference nodeReference = this.createNodeReference(reference);
      if ((nodeReference != null)) {
        Collection<IHierarchyNodeReference> _references = childNode.getReferences();
        _references.add(nodeReference);
      }
    }
  };
  this.findDeclarations(parent, monitor, _function);
  return children.values();
}
项目:xtext-core    文件:DefaultCallHierarchyBuilder.java   
protected void findTargetDeclarations(final URI sourceDeclarationURI, final IProgressMonitor monitor, final Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
  final IUnitOfWork<Object, EObject> _function = (EObject sourceDeclaration) -> {
    Object _xblockexpression = null;
    {
      IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry();
      final IAcceptor<IReferenceDescription> _function_1 = (IReferenceDescription reference) -> {
        boolean _filterReference = this.filterReference(reference);
        if (_filterReference) {
          IEObjectDescription _findTargetDeclaration = null;
          if (reference!=null) {
            _findTargetDeclaration=this.findTargetDeclaration(reference);
          }
          final IEObjectDescription targetDeclaration = _findTargetDeclaration;
          acceptor.apply(targetDeclaration, reference);
        }
      };
      ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function_1);
      this.getReferenceFinder().findAllReferences(sourceDeclaration, _referenceAcceptor, monitor);
      _xblockexpression = null;
    }
    return _xblockexpression;
  };
  this.<Object>readOnly(sourceDeclarationURI, _function);
}
项目:xtext-core    文件:DefaultCallHierarchyBuilder.java   
protected void findSourceDeclarations(final URI targetDeclarationURI, final IProgressMonitor monitor, final Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
  final TargetURIs targetURIs = this.collectTargetURIs(targetDeclarationURI);
  IResourceServiceProvider.Registry _resourceServiceProviderRegistry = this.getResourceServiceProviderRegistry();
  final IAcceptor<IReferenceDescription> _function = (IReferenceDescription reference) -> {
    boolean _filterReference = this.filterReference(reference);
    if (_filterReference) {
      IEObjectDescription _findSourceDeclaration = null;
      if (reference!=null) {
        _findSourceDeclaration=this.findSourceDeclaration(reference);
      }
      final IEObjectDescription sourceDeclaration = _findSourceDeclaration;
      acceptor.apply(sourceDeclaration, reference);
    }
  };
  ReferenceAcceptor _referenceAcceptor = new ReferenceAcceptor(_resourceServiceProviderRegistry, _function);
  this.getReferenceFinder().findAllReferences(targetURIs, 
    this.getResourceAccess(), 
    this.getIndexData(), _referenceAcceptor, monitor);
}
项目:dsl-devkit    文件:ResourceDescription2.java   
@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();
}
项目:dsl-devkit    文件:FastReferenceSearchResultContentProvider.java   
@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);
      }
    }
  }
}
项目:dsl-devkit    文件:FastReferenceSearchResultContentProvider.java   
/**
 * Adds the given reference to the contents.
 *
 * @param referenceDescription
 *          reference to add
 */
private void addReference(final IReferenceDescription referenceDescription) {
  URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
  final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
  IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
  if (resourceDescription != null) {
    ReferenceSearchViewTreeNode resourceNode = resourceNode(resourceDescription);
    new DynamicReferenceSearchViewTreeNode(resourceNode, referenceDescription, new Supplier<Object>() {
      @Override
      public Object get() {
        InternalEObject dummyProxy = (InternalEObject) EcoreFactory.eINSTANCE.createEObject();
        dummyProxy.eSetProxyURI(eObjectURI);
        Iterator<IEObjectDescription> sourceObjects = resourceDescriptions.getExportedObjectsByObject(dummyProxy).iterator();
        return sourceObjects.hasNext() ? sourceObjects.next() : referenceDescription;
      }
    });
  }
}
项目:bts    文件:ReferenceSearchResultContentProvider.java   
public void inputChanged(final Viewer viewer, Object oldInput, Object newInput) {
    synchronized (viewer) {
        if (rootNodes != null) {
            rootNodes.clear();
        }
        if (oldInput instanceof ReferenceSearchResult) {
            ((ReferenceSearchResult) oldInput).removeListener(this);
        }
        if (newInput instanceof ReferenceSearchResult && viewer instanceof TreeViewer) {
            ((ReferenceSearchResult) newInput).addListener(this);
            this.viewer = (TreeViewer) viewer;
            for (IReferenceDescription referenceDescription : ((ReferenceSearchResult) newInput)
                    .getMatchingReferences()) {
                addReference(referenceDescription, false);
            }
        }
    }
}
项目:bts    文件:ReferenceSearchResultContentProvider.java   
private void addReference(IReferenceDescription referenceDescription, boolean isUpdateViewer) {
    URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
    final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri()
            : containerEObjectURI;
    IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI
            .trimFragment());
    if (resourceDescription != null) {
        ReferenceSearchViewTreeNode resourceNode = resourceNode(resourceDescription, isUpdateViewer);
        ReferenceSearchViewTreeNode referenceNode = null;
        for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
            if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
                referenceNode = new ReferenceSearchViewTreeNode(resourceNode, referenceDescription,
                        eObjectDescription);
                break;
            }
        }
        if (referenceNode == null && resourceNode != null)
            new ReferenceSearchViewTreeNode(resourceNode, referenceDescription, referenceDescription);
    }
}
项目:bts    文件:ReferenceSearchViewPage.java   
protected void handleOpen(OpenEvent openEvent) {
    ISelection selection = openEvent.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Iterator<?> i = structuredSelection.iterator(); i.hasNext();) {
            Object selectedObject = i.next();
            if (selectedObject instanceof ReferenceSearchViewTreeNode) {
                ReferenceSearchViewTreeNode treeNode = (ReferenceSearchViewTreeNode) selectedObject;
                Object description = treeNode.getDescription();
                if (description instanceof IReferenceDescription) {
                    IReferenceDescription referenceDescription = (IReferenceDescription) description;
                    uriEditorOpener.open(referenceDescription.getSourceEObjectUri(),
                            referenceDescription.getEReference(), referenceDescription.getIndexInList(), true);
                } else if (description instanceof IResourceDescription) {
                    uriEditorOpener.open(((IResourceDescription) description).getURI(), true);
                }
            }
        }
    }
}
项目:bts    文件:DefaultReferenceFinder.java   
public void findReferences(Iterable<URI> targetURIs, final Iterable<URI> sourceResourceURIs,
        ILocalResourceAccess localResourceAccess, IAcceptor<IReferenceDescription> referenceAcceptor,
        IProgressMonitor monitor) {
    SubMonitor subMonitor = SubMonitor.convert(monitor, 2);
    if (!isEmpty(targetURIs) && !isEmpty(sourceResourceURIs)) {
        if (localResourceAccess != null) {
            Iterable<URI> localTargetURIs = filter(targetURIs, new Predicate<URI>() {
                public boolean apply(URI input) {
                    return contains(sourceResourceURIs, input.trimFragment());
                }
            });
            findLocalReferences(localTargetURIs, localResourceAccess, referenceAcceptor, subMonitor.newChild(1));
        }
        Set<URI> targetURIsAsSet = newLinkedHashSet(targetURIs);
        subMonitor.setWorkRemaining(targetURIsAsSet.size());
        for (URI sourceResourceURI : sourceResourceURIs) {
            IResourceDescription resourceDescription = indexData.getResourceDescription(sourceResourceURI);
            if (resourceDescription != null)
                findReferences(targetURIsAsSet, resourceDescription, referenceAcceptor,
                        subMonitor.newChild(1), localResourceAccess);
        }
    }
}
项目:bts    文件:DefaultReferenceFinder.java   
/**
 * @since 2.4
 */
protected void findAllIndexedReferences(IAcceptor<IReferenceDescription> referenceAcceptor, SubMonitor subMonitor,
        Set<URI> targetURIsAsSet, ILocalResourceAccess localResourceAccess) {
    subMonitor.setWorkRemaining(size(indexData.getAllResourceDescriptions()));
    for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) {
        IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceDescription.getURI());
        if (serviceProvider != null) {
            IReferenceFinder referenceFinder = serviceProvider.get(IReferenceFinder.class);
            if (referenceFinder instanceof IReferenceFinderExtension1) {
                IReferenceFinderExtension1 extension1 = (IReferenceFinderExtension1) referenceFinder;
                extension1.findReferences(targetURIsAsSet, resourceDescription, referenceAcceptor, subMonitor.newChild(1), localResourceAccess);
            } else {
                // don't use the language specific reference finder here for backwards compatibility reasons
                findReferences(targetURIsAsSet, resourceDescription, referenceAcceptor, subMonitor.newChild(1), localResourceAccess);
            }
        }
    }
}
项目:bts    文件:DefaultReferenceFinder.java   
protected void findLocalReferences(Iterable<URI> localTargets, ILocalResourceAccess localResourceAccess,
        final IAcceptor<IReferenceDescription> acceptor, IProgressMonitor monitor) {
    if ((monitor != null && monitor.isCanceled()))
        return;
    final Multimap<URI, URI> resource2target = LinkedHashMultimap.create();
    for (URI targetURI : localTargets) {
        resource2target.put(targetURI.trimFragment(), targetURI);
    }
    final SubMonitor subMonitor = SubMonitor.convert(monitor, resource2target.keySet().size());
    for (final URI resourceURI : resource2target.keySet()) {
        if (subMonitor.isCanceled())
            return;
        localResourceAccess.readOnly(resourceURI, new IUnitOfWork.Void<ResourceSet>() {
            @Override
            public void process(ResourceSet resourceSet) throws Exception {
                Resource resource = resourceSet.getResource(resourceURI, true);
                findLocalReferencesInResource(resource2target.get(resourceURI), resource, acceptor);
            }
        });
        subMonitor.worked(1);
    }
}
项目:bts    文件:AbstractReferenceUpdater.java   
public void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
        Iterable<IReferenceDescription> referenceDescriptions, IRefactoringUpdateAcceptor updateAcceptor,
        IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    progress.beginTask("Sort references by project", 1);
    Multimap<IProject, IReferenceDescription> project2references = sorter.sortByProject(referenceDescriptions);
    SubMonitor allProjectsProgress = progress.newChild(98).setWorkRemaining(project2references.keySet().size());
    for (IProject project : project2references.keySet()) {
        if (allProjectsProgress.isCanceled())
            break;
        Multimap<URI, IReferenceDescription> resource2references = sorter.sortByResource(project2references
                .get(project));
        ResourceSet resourceSet = resourceSetProvider.get(project);
        StatusWrapper status = updateAcceptor.getRefactoringStatus();
        createClusteredReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor,
                status, allProjectsProgress.newChild(1));
    }
}
项目:bts    文件:AbstractReferenceUpdater.java   
protected void createReferenceUpdatesForCluster(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, StatusWrapper status, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, 100);
    List<URI> unloadableResources = loadReferringResources(resourceSet, resource2references.keySet(), status,
            progress.newChild(10));
    for (URI unloadableResouce : unloadableResources)
        resource2references.removeAll(unloadableResouce);
    List<IReferenceDescription> unresolvableReferences = resolveReferenceProxies(resourceSet,
            resource2references.values(), status, progress.newChild(10));
    for (IReferenceDescription unresolvableReference : unresolvableReferences) {
        URI unresolvableReferringResource = unresolvableReference.getSourceEObjectUri().trimFragment();
        resource2references.remove(unresolvableReferringResource, unresolvableReference);
    }
    elementRenameArguments.getRenameStrategy().applyDeclarationChange(elementRenameArguments.getNewName(),
            resourceSet);
    createReferenceUpdates(elementRenameArguments, resource2references, resourceSet, updateAcceptor,
            progress.newChild(80));
    elementRenameArguments.getRenameStrategy().revertDeclarationChange(resourceSet);
}
项目:bts    文件:DefaultReferenceUpdater.java   
@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Creating reference updates", resource2references.keySet()
            .size());
    for (URI referringResourceURI : resource2references.keySet()) {
        if (progress.isCanceled())
            return;
        Resource referringResource = resourceSet.getResource(referringResourceURI, false);
        if (!(referringResource instanceof XtextResource)) {
            updateAcceptor.getRefactoringStatus().add(ERROR, "Resource {0} is not an XtextResource.",
                    referringResource.getURI(), resourceSet);
        } else {
            Iterable<IReferenceDescription> referenceDescriptions = resource2references.get(referringResourceURI);
            processReferringResource(referringResource, referenceDescriptions, elementRenameArguments,
                    updateAcceptor);
        }
        progress.worked(1);
    }
}
项目:bts    文件:ReferenceUpdaterDispatcher.java   
public void createReferenceUpdates(ElementRenameArguments elementRenameArguments, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Updating references", 100);
    ResourceAccess resourceAccess = resourceAccessProvider.get();
    resourceAccess.registerResourceSet(resourceSet);

    ReferenceDescriptionAcceptor referenceDescriptionAcceptor = createFindReferenceAcceptor(updateAcceptor);
    referenceFinder.findAllReferences(elementRenameArguments.getRenamedElementURIs(), 
            resourceAccess,
            referenceDescriptionAcceptor, progress.newChild(2));
    Multimap<IReferenceUpdater, IReferenceDescription> updater2descriptions = referenceDescriptionAcceptor
            .getReferenceUpdater2ReferenceDescriptions();
    SubMonitor updaterProgress = progress.newChild(98).setWorkRemaining(updater2descriptions.keySet().size());
    for (IReferenceUpdater referenceUpdater : updater2descriptions.keySet()) {
        createReferenceUpdates(referenceUpdater, elementRenameArguments,
                updater2descriptions.get(referenceUpdater), updateAcceptor, updaterProgress);
    }
}
项目:bts    文件:EmfResourceReferenceUpdater.java   
@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments,
        Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet,
        IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, "Updating EMF References", resource2references.keySet()
            .size());
    for (URI referringResourceURI : resource2references.keySet()) {
        try {
            if (progress.isCanceled())
                break;
            Resource referringResource = resourceSet.getResource(referringResourceURI, false);
            EObject refactoredElement = resourceSet.getEObject(elementRenameArguments.getNewElementURI(elementRenameArguments.getTargetElementURI()), true);
            if(refactoredElement != null && refactoredElement instanceof EClassifier){
                for(IReferenceDescription reference : resource2references.get(referringResourceURI)){
                    EObject referringEReference = referringResource.getEObject(reference.getSourceEObjectUri().fragment()).eContainer();
                    if(referringEReference != null && referringEReference instanceof EReference)
                    ((EReference)referringEReference).setEType((EClassifier)refactoredElement);
                }
            }
            changeUtil.addSaveAsUpdate(referringResource, updateAcceptor);
            progress.worked(1);
        } catch (Exception exc) {
            throw new WrappedException(exc);
        }
    }
}
项目:n4js    文件:LabellingReferenceQueryExecutor.java   
/**
 * Filter references that should not be revealed in the UI.
 */
@Override
protected Predicate<IReferenceDescription> getFilter(EObject primaryTarget) {
    return new Predicate<IReferenceDescription>() {

        @Override
        public boolean apply(IReferenceDescription input) {
            return isRelevantToUser(input);
        }

    };
}
项目:xtext-core    文件:DefaultResourceDescription.java   
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
    return cache.get(REFERENCE_DESCRIPTIONS_CACHE_KEY, getResource(), new Provider<List<IReferenceDescription>>(){
        @Override
        public List<IReferenceDescription> get() {
            return computeReferenceDescriptions();
        }});
}
项目:xtext-core    文件:ReferenceFinder.java   
protected void findReferencesInDescription(TargetURIs targetURIs, IResourceDescription resourceDescription,
        IResourceAccess resourceAccess, Acceptor acceptor, IProgressMonitor monitor) {
    for (IReferenceDescription referenceDescription : resourceDescription.getReferenceDescriptions()) {
        if (targetURIs.contains(referenceDescription.getTargetEObjectUri())) {
            acceptor.accept(referenceDescription);
        }
    }
}
项目:xtext-core    文件:SerializableResourceDescription.java   
private static SerializableReferenceDescription createCopy(final IReferenceDescription desc) {
  SerializableReferenceDescription _serializableReferenceDescription = new SerializableReferenceDescription();
  final Procedure1<SerializableReferenceDescription> _function = (SerializableReferenceDescription it) -> {
    it.setSourceEObjectUri(desc.getSourceEObjectUri());
    it.setTargetEObjectUri(desc.getTargetEObjectUri());
    it.setEReference(desc.getEReference());
    it.setIndexInList(desc.getIndexInList());
    it.setContainerEObjectURI(desc.getContainerEObjectURI());
  };
  return ObjectExtensions.<SerializableReferenceDescription>operator_doubleArrow(_serializableReferenceDescription, _function);
}
项目:xtext-core    文件:Indexer.java   
@Override
public Iterable<IReferenceDescription> getReferenceDescriptions() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("getReferenceDescriptions ");
  _builder.append(this.URI);
  IllegalStateException exception = new IllegalStateException(_builder.toString());
  Indexer.ResolvedResourceDescription.LOG.error(exception, exception);
  return CollectionLiterals.<IReferenceDescription>emptyList();
}
项目:xtext-core    文件:PortableURIsTest.java   
@Test
public void testPortableReferenceDescriptions() {
  try {
    final XtextResourceSet resourceSet = this.<XtextResourceSet>get(XtextResourceSet.class);
    Resource _createResource = resourceSet.createResource(URI.createURI("hubba:/bubba.langatestlanguage"));
    final StorageAwareResource resourceA = ((StorageAwareResource) _createResource);
    Resource _createResource_1 = resourceSet.createResource(URI.createURI("hubba:/bubba2.langatestlanguage"));
    final StorageAwareResource resourceB = ((StorageAwareResource) _createResource_1);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type B");
    _builder.newLine();
    resourceB.load(this.getAsStream(_builder.toString()), null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import \'hubba:/bubba2.langatestlanguage\'");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("type A extends B");
    _builder_1.newLine();
    resourceA.load(this.getAsStream(_builder_1.toString()), null);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    final ResourceStorageWritable writable = resourceA.getResourceStorageFacade().createResourceStorageWritable(bout);
    writable.writeResource(resourceA);
    byte[] _byteArray = bout.toByteArray();
    ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
    final ResourceStorageLoadable loadable = resourceA.getResourceStorageFacade().createResourceStorageLoadable(_byteArrayInputStream);
    Resource _createResource_2 = resourceSet.createResource(URI.createURI("hubba:/bubba3.langatestlanguage"));
    final StorageAwareResource resourceC = ((StorageAwareResource) _createResource_2);
    resourceC.loadFromStorage(loadable);
    final IReferenceDescription refDesc = IterableExtensions.<IReferenceDescription>head(resourceC.getResourceDescription().getReferenceDescriptions());
    EObject _head = IterableExtensions.<EObject>head(resourceB.getContents());
    Assert.assertSame(IterableExtensions.<Type>head(((Main) _head).getTypes()), resourceSet.getEObject(refDesc.getTargetEObjectUri(), false));
    EObject _head_1 = IterableExtensions.<EObject>head(resourceC.getContents());
    Assert.assertSame(IterableExtensions.<Type>head(((Main) _head_1).getTypes()), resourceSet.getEObject(refDesc.getSourceEObjectUri(), false));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:xtext-core    文件:DefaultCallHierarchyBuilder.java   
protected void findDeclarations(final IHierarchyNode parent, final IProgressMonitor monitor, final Procedure2<? super IEObjectDescription, ? super IReferenceDescription> acceptor) {
  final ICallHierarchyBuilder.CallHierarchyType hierarchyType = this.hierarchyType;
  if (hierarchyType != null) {
    switch (hierarchyType) {
      case CALLEE:
        this.findTargetDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor);
        break;
      default:
        this.findSourceDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor);
        break;
    }
  } else {
    this.findSourceDeclarations(parent.getElement().getEObjectURI(), monitor, acceptor);
  }
}
项目:xtext-core    文件:DefaultCallHierarchyBuilder.java   
/**
 * @return a hierarchy node reference for the given reference; cannot be <code>null</code>
 */
protected IHierarchyNodeReference createNodeReference(final IReferenceDescription reference) {
  final IUnitOfWork<DefaultHierarchyNodeReference, EObject> _function = (EObject sourceObject) -> {
    final ITextRegionWithLineInformation textRegion = this.getTextRegion(sourceObject, reference.getEReference(), reference.getIndexInList());
    final String text = this.getText(sourceObject, textRegion);
    return new DefaultHierarchyNodeReference(text, textRegion, reference);
  };
  return this.<DefaultHierarchyNodeReference>readOnly(reference.getSourceEObjectUri(), _function);
}
项目:dsl-devkit    文件:DirtyStateAwareResourceDescriptions2.java   
/**
 * determine whether a given resource description contains any reference to a set of other resources identified by their URIs.
 * 
 * @param desc
 *          Resource description to test
 * @param targetResources
 *          URIs of the target resources
 * @return true, if {@code desc} links to one of the {@code targetResources}.
 */
private boolean hasReferenceTo(final IResourceDescription desc, final Set<URI> targetResources) {
  if (desc == null || targetResources.contains(desc.getURI())) {
    return false;
  }
  return !Iterables.isEmpty(Iterables.filter(desc.getReferenceDescriptions(), new Predicate<IReferenceDescription>() {
    public boolean apply(final IReferenceDescription input) {
      return targetResources.contains(input.getTargetEObjectUri().trimFragment());
    }
  }));
}
项目:dsl-devkit    文件:AbstractResourceDescriptionStrategy.java   
/**
 * Creates all implicit reference descriptions and adds them to the acceptor.
 *
 * @param resource
 *          resource to create implicit references for
 * @param acceptor
 *          acceptor
 */
public void createImplicitReferenceDescriptions(final Resource resource, final IAcceptor<IReferenceDescription> acceptor) {
  ImplicitReferencesAdapter adapter = ImplicitReferencesAdapter.find(resource);
  if (adapter != null) {
    for (IReferenceDescription ref : adapter.getImplicitReferences()) {
      acceptor.accept(ref);
    }
  }
}
项目:dsl-devkit    文件:ResourceDescriptionsUtil.java   
/**
 * 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;
  });
}
项目:dsl-devkit    文件:ResourceDescriptionsUtil.java   
/**
 * Find all {@link IReferenceDescription}s of cross-references to a set of {@link org.eclipse.emf.ecore.EObject EObjects} identified by {@link URI}.
 *
 * @param descriptions
 *          {@link IResourceDescriptions} to find the references in.
 * @param targetObjects
 *          {@link URI} of the target object
 * @return An {@link Iterable} of all {@link IReferenceDescription}s of all cross-references that reference the given objects.
 */
public static Iterable<IReferenceDescription> findReferencesToObjects(final IResourceDescriptions descriptions, final Set<URI> targetObjects) {
  return Iterables.concat(Iterables.transform(descriptions.getAllResourceDescriptions(), new Function<IResourceDescription, Iterable<IReferenceDescription>>() {
    @Override
    public Iterable<IReferenceDescription> apply(final IResourceDescription from) {
      return Iterables.filter(from.getReferenceDescriptions(), new Predicate<IReferenceDescription>() {
        @Override
        public boolean apply(final IReferenceDescription input) {
          return targetObjects.contains(input.getTargetEObjectUri());
        }
      });
    }
  }));
}