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;
}
Aggregations