Search in sources :

Example 1 with IResolutionAcceptor

use of org.eclipse.n4js.ide.imports.ReferenceResolutionFinder.IResolutionAcceptor in project n4js by eclipse.

the class ImportHelper method findResolutionsForAllUnresolvedReferences.

/**
 * Searches the entire AST for unresolved references and searches possible resolutions for each. Returns the
 * resolutions of those unresolved references that are unambiguous, i.e. that have only a single possible
 * resolution.
 *
 * @see ReferenceResolutionFinder#findResolutions(N4JSWorkspaceConfigSnapshot, ReferenceDescriptor, boolean,
 *      boolean, Predicate, Predicate, IResolutionAcceptor)
 */
public List<ReferenceResolution> findResolutionsForAllUnresolvedReferences(Script script, CancelIndicator cancelIndicator) {
    triggerProxyResolution(script, cancelIndicator);
    N4JSWorkspaceConfigSnapshot wc = workspaceAccess.getWorkspaceConfig(script);
    List<ReferenceResolution> result = new ArrayList<>();
    Set<String> donePrefixes = new HashSet<>();
    Iterator<EObject> iter = script.eAllContents();
    while (iter.hasNext()) {
        operationCanceledManager.checkCanceled(cancelIndicator);
        EObject curr = iter.next();
        ReferenceDescriptor reference = getUnresolvedReferenceForASTNode(curr);
        if (reference != null && donePrefixes.add(reference.text)) {
            ResolutionAcceptor acceptor = new ResolutionAcceptor(2, cancelIndicator);
            referenceResolutionFinder.findResolutions(wc, reference, true, true, Predicates.alwaysFalse(), Predicates.alwaysTrue(), acceptor);
            // only add a found resolution if we have exactly one resolution (i.e. if reference is unambiguous)
            List<ReferenceResolution> resolutions = acceptor.getResolutions();
            if (resolutions.size() == 1) {
                result.add(resolutions.get(0));
            }
        }
    }
    return result;
}
Also used : N4JSWorkspaceConfigSnapshot(org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot) EObject(org.eclipse.emf.ecore.EObject) IResolutionAcceptor(org.eclipse.n4js.ide.imports.ReferenceResolutionFinder.IResolutionAcceptor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 IResolutionAcceptor (org.eclipse.n4js.ide.imports.ReferenceResolutionFinder.IResolutionAcceptor)1 N4JSWorkspaceConfigSnapshot (org.eclipse.n4js.workspace.N4JSWorkspaceConfigSnapshot)1