mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
let ScopeOptimizer use restricted scope instead of scope to exclude
This commit is contained in:
@@ -35,6 +35,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public interface ScopeOptimizer {
|
||||
|
||||
/**
|
||||
* Please use {@link ScopeOptimizer#getScopeToRestrict(PsiElement)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable("is null when given optimizer can't provide a scope to exclude")
|
||||
GlobalSearchScope getScopeToExclude(@NotNull PsiElement element);
|
||||
|
||||
@Nullable("is null when given optimizer can't provide a scope to restrict")
|
||||
default SearchScope getScopeToRestrict(@NotNull PsiElement element) {
|
||||
GlobalSearchScope scopeToExclude = getScopeToExclude(element);
|
||||
|
||||
return scopeToExclude == null ? null : GlobalSearchScope.notScope(scopeToExclude);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,15 +81,15 @@ public class SearchRequestCollector {
|
||||
searchScope instanceof GlobalSearchScope &&
|
||||
((searchContext & UsageSearchContext.IN_CODE) != 0 || searchContext == UsageSearchContext.ANY)) {
|
||||
for (ScopeOptimizer optimizer : CODE_USAGE_SCOPE_OPTIMIZER_EP_NAME.getExtensions()) {
|
||||
final GlobalSearchScope optimizedCodeUsageSearchScope = optimizer.getScopeToExclude(searchTarget);
|
||||
if (optimizedCodeUsageSearchScope != null) {
|
||||
final SearchScope restrictedCodeUsageSearchScope = optimizer.getScopeToRestrict(searchTarget);
|
||||
if (restrictedCodeUsageSearchScope != null) {
|
||||
short exceptCodeSearchContext = searchContext == UsageSearchContext.ANY
|
||||
? UsageSearchContext.IN_COMMENTS |
|
||||
UsageSearchContext.IN_STRINGS |
|
||||
UsageSearchContext.IN_FOREIGN_LANGUAGES |
|
||||
UsageSearchContext.IN_PLAIN_TEXT
|
||||
: (short)(searchContext ^ UsageSearchContext.IN_CODE);
|
||||
GlobalSearchScope searchCodeUsageEffectiveScope = ((GlobalSearchScope)searchScope).intersectWith(GlobalSearchScope.notScope(optimizedCodeUsageSearchScope));
|
||||
SearchScope searchCodeUsageEffectiveScope = searchScope.intersectWith(restrictedCodeUsageSearchScope);
|
||||
requests = ContainerUtil.list(new PsiSearchRequest(searchCodeUsageEffectiveScope, word, UsageSearchContext.IN_CODE, caseSensitive, containerName, processor),
|
||||
new PsiSearchRequest(searchScope, word, exceptCodeSearchContext, caseSensitive, containerName, processor));
|
||||
break;
|
||||
|
||||
@@ -89,9 +89,9 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
|
||||
}
|
||||
for (ScopeOptimizer optimizer : USE_SCOPE_OPTIMIZER_EP_NAME.getExtensions()) {
|
||||
ProgressManager.checkCanceled();
|
||||
final GlobalSearchScope scopeToExclude = optimizer.getScopeToExclude(element);
|
||||
if (scopeToExclude != null) {
|
||||
scope = scope.intersectWith(GlobalSearchScope.notScope(scopeToExclude));
|
||||
final SearchScope scopeToRestrict = optimizer.getScopeToRestrict(element);
|
||||
if (scopeToRestrict != null) {
|
||||
scope = scope.intersectWith(scopeToRestrict);
|
||||
}
|
||||
}
|
||||
return scope;
|
||||
|
||||
Reference in New Issue
Block a user