Search in sources :

Example 1 with SimpleResourceAccess

use of org.eclipse.n4js.ts.findReferences.SimpleResourceAccess in project n4js by eclipse.

the class FindReferenceHelper method findReferences.

/**
 * @return all references to the given declaration. Respect editor states.
 */
public List<EObject> findReferences(EObject declaration) {
    declaration = getDeclaration(declaration);
    TargetURIs targets = getTargets(declaration);
    Resource eResource = declaration.eResource();
    SimpleResourceAccess resourceAccess = new SimpleResourceAccess(eResource.getResourceSet());
    IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(eResource);
    ReferenceAcceptor acceptor = new ReferenceAcceptor();
    referenceFinder.findAllReferences(targets, resourceAccess, index, acceptor, null);
    return acceptor.results;
}
Also used : SimpleResourceAccess(org.eclipse.n4js.ts.findReferences.SimpleResourceAccess) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs)

Example 2 with SimpleResourceAccess

use of org.eclipse.n4js.ts.findReferences.SimpleResourceAccess in project n4js by eclipse.

the class HeadlessReferenceFinder method findReferencesTo.

/**
 * 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;
}
Also used : TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) SimpleResourceAccess(org.eclipse.n4js.ts.findReferences.SimpleResourceAccess) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) EObject(org.eclipse.emf.ecore.EObject) DefaultReferenceDescription(org.eclipse.xtext.resource.impl.DefaultReferenceDescription) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 3 with SimpleResourceAccess

use of org.eclipse.n4js.ts.findReferences.SimpleResourceAccess in project n4js by eclipse.

the class ConcreteSyntaxAwareReferenceFinder method findReferences.

@Override
public void findReferences(Predicate<URI> targetURIs, Resource resource, Acceptor acceptor, IProgressMonitor monitor) {
    // make sure data is present
    keys.getData((TargetURIs) targetURIs, new SimpleResourceAccess(resource.getResourceSet()));
    EList<EObject> astContents;
    if (resource instanceof N4JSResource) {
        // In case of N4JSResource, we search only in the AST but NOT in TModule tree!
        Script script = (Script) ((N4JSResource) resource).getContents().get(0);
        astContents = new BasicEList<>();
        astContents.add(script);
    } else {
        astContents = resource.getContents();
    }
    for (EObject content : astContents) {
        findReferences(targetURIs, content, acceptor, monitor);
    }
}
Also used : Script(org.eclipse.n4js.n4JS.Script) SimpleResourceAccess(org.eclipse.n4js.ts.findReferences.SimpleResourceAccess) EObject(org.eclipse.emf.ecore.EObject) N4JSResource(org.eclipse.n4js.resource.N4JSResource)

Aggregations

SimpleResourceAccess (org.eclipse.n4js.ts.findReferences.SimpleResourceAccess)3 EObject (org.eclipse.emf.ecore.EObject)2 TargetURIs (org.eclipse.xtext.findReferences.TargetURIs)2 URI (org.eclipse.emf.common.util.URI)1 EReference (org.eclipse.emf.ecore.EReference)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 Script (org.eclipse.n4js.n4JS.Script)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 IReferenceFinder (org.eclipse.xtext.findReferences.IReferenceFinder)1 IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)1 IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)1 DefaultReferenceDescription (org.eclipse.xtext.resource.impl.DefaultReferenceDescription)1