SearchScope (@NotNull PsiElement element, boolean restrictToCodeUsageScope) { SearchScope scope = PsiSearchScopeUtil.USE_SCOPE_KEY.get(element.getContainingFile()); if (scope != null) return scope; scope = element.getUseScope(); for (UseScopeEnlarger enlarger : UseScopeEnlarger.EP_NAME.getExtensionList()) { ProgressManager.checkCanceled(); SearchScope additionalScope = null; try { additionalScope = enlarger.getAdditionalUseScope(element); } catch (IndexNotReadyException pce) { LOG.debug("ProcessCanceledException thrown while getUseScope() calculation", pce); } if (additionalScope != null) { scope = scope.union(additionalScope); } } scope = restrictScope(scope, USE_SCOPE_OPTIMIZER_EP_NAME.getExtensionList(), element); if (restrictToCodeUsageScope) { scope = restrictScope(scope, CODE_USAGE_SCOPE_OPTIMIZER_EP_NAME.getExtensionList(), element); } return scope; }