make DumbService.runReadActionInSmartMode work in read action in dumb mode, add some invocations

This commit is contained in:
peter
2016-06-16 17:31:59 +02:00
parent 45cf4b1873
commit 36fc41902e
6 changed files with 55 additions and 63 deletions
@@ -22,6 +22,7 @@ package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
@@ -78,8 +79,7 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(project);
for (final String name : names) {
ProgressIndicatorProvider.checkCanceled();
final PsiClass[] classes = MethodUsagesSearcher.resolveInReadAction(project, () -> cache.getClassesByName(name, scope));
for (PsiClass psiClass : classes) {
for (PsiClass psiClass : DumbService.getInstance(project).runReadActionInSmartMode(() -> cache.getClassesByName(name, scope))) {
ProgressIndicatorProvider.checkCanceled();
if (!processor.process(psiClass)) {
return false;
@@ -92,7 +92,7 @@ public class AllClassesSearchExecutor implements QueryExecutor<PsiClass, AllClas
public static Project processClassNames(final Project project, final GlobalSearchScope scope, final Consumer<String> consumer) {
final ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
MethodUsagesSearcher.resolveInReadAction(project, new Computable<Void>() {
DumbService.getInstance(project).runReadActionInSmartMode(new Computable<Void>() {
@Override
public Void compute() {
PsiShortNamesCache.getInstance(project).processAllClassNames(new Processor<String>() {
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.search;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.TextRange;
@@ -59,7 +60,7 @@ public class ConstructorReferencesSearchHelper {
final boolean[] isEnum = new boolean[1];
final boolean[] isUnder18 = new boolean[1];
MethodUsagesSearcher.resolveInReadAction(project, new Computable<Void>() {
DumbService.getInstance(project).runReadActionInSmartMode(new Computable<Void>() {
@Override
public Void compute() {
constructorCanBeCalledImplicitly[0] = constructor.getParameterList().getParametersCount() == 0;
@@ -103,10 +104,10 @@ public class ConstructorReferencesSearchHelper {
}
// search usages like "this(..)"
if (!MethodUsagesSearcher.resolveInReadAction(project,
() -> processSuperOrThis(containingClass, constructor, constructorCanBeCalledImplicitly[0], searchScope, project,
isStrictSignatureSearch,
PsiKeyword.THIS, processor))) {
if (!DumbService.getInstance(project).runReadActionInSmartMode(
() -> processSuperOrThis(containingClass, constructor, constructorCanBeCalledImplicitly[0], searchScope, project,
isStrictSignatureSearch,
PsiKeyword.THIS, processor))) {
return false;
}
@@ -127,7 +128,7 @@ public class ConstructorReferencesSearchHelper {
@NotNull final PsiMethod constructor,
@NotNull final Project project,
@NotNull final PsiClass aClass) {
return MethodUsagesSearcher.resolveInReadAction(project, () -> {
return DumbService.getInstance(project).runReadActionInSmartMode(() -> {
for (PsiField field : aClass.getFields()) {
if (field instanceof PsiEnumConstant) {
PsiReference reference = field.getReference();
@@ -149,7 +150,7 @@ public class ConstructorReferencesSearchHelper {
return ReferencesSearch.search(aClass, searchScope).forEach(reference -> {
final PsiElement element = reference.getElement();
if (element != null) {
return MethodUsagesSearcher.resolveInReadAction(project, () -> {
return DumbService.getInstance(project).runReadActionInSmartMode(() -> {
final PsiElement parent = element.getParent();
if (parent instanceof PsiMethodReferenceExpression &&
((PsiMethodReferenceExpression)parent).getReferenceNameElement() instanceof PsiKeyword) {
@@ -219,7 +220,8 @@ public class ConstructorReferencesSearchHelper {
@NotNull final Project project,
@NotNull final PsiClass containingClass) {
if (containingClass instanceof PsiAnonymousClass) return true;
boolean same = MethodUsagesSearcher.resolveInReadAction(project, () -> myManager.areElementsEquivalent(constructor.getContainingClass(), containingClass.getSuperClass()));
boolean same = DumbService.getInstance(project).runReadActionInSmartMode(
() -> myManager.areElementsEquivalent(constructor.getContainingClass(), containingClass.getSuperClass()));
if (!same) {
return true;
}
@@ -17,9 +17,9 @@ package com.intellij.psi.impl.search;
import com.intellij.concurrency.JobLauncher;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
@@ -176,9 +176,10 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
@NotNull PsiClass baseClass,
@NotNull String baseClassName,
@NotNull SearchScope useScope) {
GlobalSearchScope globalUseScope = ReadAction.compute(() -> StubHierarchyInheritorSearcher.restrictScope(toGlobal(useScope, project)));
DumbService dumbService = DumbService.getInstance(project);
GlobalSearchScope globalUseScope = dumbService.runReadActionInSmartMode(() -> StubHierarchyInheritorSearcher.restrictScope(toGlobal(useScope, project)));
Collection<PsiReferenceList> candidates =
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
dumbService.runReadActionInSmartMode(() -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
// memory/speed optimisation: it really is a map(string -> PsiClass or List<PsiClass>)
final Map<String, Object> classes = new HashMap<>();
@@ -227,11 +228,11 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
Collection<PsiAnonymousClass> anonymousCandidates =
MethodUsagesSearcher.resolveInReadAction(project, () -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
dumbService.runReadActionInSmartMode(() -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
processConcurrentlyIfTooMany(anonymousCandidates,
candidate-> {
boolean isInheritor = MethodUsagesSearcher.resolveInReadAction(project, () -> candidate.isInheritor(baseClass, false));
boolean isInheritor = dumbService.runReadActionInSmartMode(() -> candidate.isInheritor(baseClass, false));
if (isInheritor) {
synchronized (result) {
result.add(candidate);
@@ -15,11 +15,8 @@
*/
package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.QueryExecutorBase;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
@@ -46,7 +43,7 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
final boolean[] needStrictSignatureSearch = new boolean[1];
final boolean strictSignatureSearch = p.isStrictSignatureSearch();
final PsiClass aClass = resolveInReadAction(p.getProject(), () -> {
final PsiClass aClass = DumbService.getInstance(p.getProject()).runReadActionInSmartMode(() -> {
PsiClass aClass1 = method.getContainingClass();
if (aClass1 == null) return null;
isConstructor[0] = method.isConstructor();
@@ -66,7 +63,7 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
final SearchRequestCollector collector = p.getOptimizer();
final SearchScope searchScope = resolveInReadAction(p.getProject(), () -> p.getEffectiveSearchScope());
final SearchScope searchScope = DumbService.getInstance(p.getProject()).runReadActionInSmartMode(() -> p.getEffectiveSearchScope());
if (searchScope == GlobalSearchScope.EMPTY_SCOPE) {
return;
}
@@ -90,30 +87,23 @@ public class MethodUsagesSearcher extends QueryExecutorBase<PsiReference, Method
return;
}
resolveInReadAction(p.getProject(), new Computable<Void>() {
@Override
public Void compute() {
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(methodName[0], false);
SearchScope accessScope = methods[0].getUseScope();
for (int i = 1; i < methods.length; i++) {
PsiMethod method1 = methods[i];
accessScope = accessScope.union(method1.getUseScope());
}
SearchScope restrictedByAccessScope = searchScope.intersectWith(accessScope);
short searchContext = UsageSearchContext.IN_CODE | UsageSearchContext.IN_COMMENTS | UsageSearchContext.IN_FOREIGN_LANGUAGES;
collector.searchWord(methodName[0], restrictedByAccessScope, searchContext, true, method,
getTextOccurrenceProcessor(methods, aClass, strictSignatureSearch));
SimpleAccessorReferenceSearcher.addPropertyAccessUsages(method, restrictedByAccessScope, collector);
return null;
DumbService.getInstance(p.getProject()).runReadActionInSmartMode(()-> {
final PsiMethod[] methods = strictSignatureSearch ? new PsiMethod[]{method} : aClass.findMethodsByName(methodName[0], false);
SearchScope accessScope = methods[0].getUseScope();
for (int i = 1; i < methods.length; i++) {
PsiMethod method1 = methods[i];
accessScope = accessScope.union(method1.getUseScope());
}
});
}
static <T> T resolveInReadAction(@NotNull Project p, @NotNull Computable<T> computable) {
return ApplicationManager.getApplication().isReadAccessAllowed() ? computable.compute() : DumbService.getInstance(p).runReadActionInSmartMode(computable);
SearchScope restrictedByAccessScope = searchScope.intersectWith(accessScope);
short searchContext = UsageSearchContext.IN_CODE | UsageSearchContext.IN_COMMENTS | UsageSearchContext.IN_FOREIGN_LANGUAGES;
collector.searchWord(methodName[0], restrictedByAccessScope, searchContext, true, method,
getTextOccurrenceProcessor(methods, aClass, strictSignatureSearch));
SimpleAccessorReferenceSearcher.addPropertyAccessUsages(method, restrictedByAccessScope, collector);
return null;
});
}
protected MethodTextOccurrenceProcessor getTextOccurrenceProcessor(PsiMethod[] methods, PsiClass aClass, boolean strictSignatureSearch) {