summaryrefslogtreecommitdiff
path: root/java/java-indexing-impl/src/com/intellij/psi/impl/search
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-indexing-impl/src/com/intellij/psi/impl/search')
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java8
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java90
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaAllOverridingMethodsSearcher.java19
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaDirectInheritorsSearcher.java46
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java125
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodDeepestSuperSearcher.java26
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodSuperSearcher.java42
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/PsiAnnotationMethodReferencesSearcher.java39
-rw-r--r--java/java-indexing-impl/src/com/intellij/psi/impl/search/SimpleAccessorReferenceSearcher.java1
9 files changed, 268 insertions, 128 deletions
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java
index dec2dccb341e..53fa2eb48604 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedElementsSearcher.java
@@ -18,7 +18,6 @@ package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
-import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.LocalSearchScope;
@@ -50,7 +49,12 @@ public class AnnotatedElementsSearcher implements QueryExecutor<PsiModifierListO
});
assert annotationFQN != null;
- final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
+ final PsiManager psiManager = ApplicationManager.getApplication().runReadAction(new Computable<PsiManager>() {
+ @Override
+ public PsiManager compute() {
+ return annClass.getManager();
+ }
+ });
final SearchScope useScope = p.getScope();
final Class<? extends PsiModifierListOwner>[] types = p.getTypes();
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java
index 4437b3f49e51..51565a81e5f4 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/AnnotatedPackagesSearcher.java
@@ -19,15 +19,15 @@
*/
package com.intellij.psi.impl.search;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
+import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
-import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiSearchHelper;
-import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AnnotatedPackagesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Processor;
@@ -44,49 +44,67 @@ public class AnnotatedPackagesSearcher implements QueryExecutor<PsiPackage, Anno
final PsiClass annClass = p.getAnnotationClass();
assert annClass.isAnnotationType() : "Annotation type should be passed to annotated packages search";
- final String annotationFQN = annClass.getQualifiedName();
+ final String annotationFQN = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
+ @Override
+ public String compute() {
+ return annClass.getQualifiedName();
+ }
+ });
assert annotationFQN != null;
- final PsiManagerImpl psiManager = (PsiManagerImpl)annClass.getManager();
- final SearchScope useScope = p.getScope();
+ final PsiManager psiManager = ApplicationManager.getApplication().runReadAction(new Computable<PsiManager>() {
+ @Override
+ public PsiManager compute() {
+ return annClass.getManager();
+ }
+ });
+ final GlobalSearchScope useScope = (GlobalSearchScope)p.getScope();
- final String annotationShortName = annClass.getName();
+ final String annotationShortName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
+ @Override
+ public String compute() {
+ return annClass.getName();
+ }
+ });
assert annotationShortName != null;
- final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : null;
-
- final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().get(annotationShortName, psiManager.getProject(), scope);
- for (PsiAnnotation annotation : annotations) {
- PsiModifierList modlist = (PsiModifierList)annotation.getParent();
- final PsiElement owner = modlist.getParent();
- if (!(owner instanceof PsiClass)) continue;
- PsiClass candidate = (PsiClass)owner;
- if (!"package-info".equals(candidate.getName())) continue;
-
- LOG.assertTrue(candidate.isValid());
-
- final PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
- if (ref == null) continue;
-
- if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) continue;
- if (useScope instanceof GlobalSearchScope &&
- !((GlobalSearchScope)useScope).contains(candidate.getContainingFile().getVirtualFile())) {
- continue;
- }
- final String qname = candidate.getQualifiedName();
- if (qname != null && !consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(
- qname.substring(0, qname.lastIndexOf('.'))))) {
- return false;
- }
+ final Collection<PsiAnnotation> annotations = JavaAnnotationIndex.getInstance().get(annotationShortName, psiManager.getProject(),
+ useScope);
+
+ for (final PsiAnnotation annotation : annotations) {
+ boolean accepted = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>(){
+ @Override
+ public Boolean compute() {
+ PsiModifierList modlist = (PsiModifierList)annotation.getParent();
+ final PsiElement owner = modlist.getParent();
+ if ((owner instanceof PsiClass)) {
+ PsiClass candidate = (PsiClass)owner;
+ if ("package-info".equals(candidate.getName())) {
+ LOG.assertTrue(candidate.isValid());
+ final PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
+ if (ref != null && psiManager.areElementsEquivalent(ref.resolve(), annClass) &&
+ useScope.contains(candidate.getContainingFile().getVirtualFile())) {
+ final String qname = candidate.getQualifiedName();
+ if (qname != null && !consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(
+ qname.substring(0, qname.lastIndexOf('.'))))) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+ });
+ if (!accepted) return false;
}
PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(psiManager.getProject());
final GlobalSearchScope infoFilesFilter = new PackageInfoFilesOnly();
GlobalSearchScope infoFiles =
- useScope instanceof GlobalSearchScope ? ((GlobalSearchScope)useScope).intersectWith(infoFilesFilter) : infoFilesFilter;
+ useScope.intersectWith(infoFilesFilter);
- final boolean[] wantmore = {true};
+ final boolean[] wantMore = {true};
helper.processAllFilesWithWord(annotationShortName, infoFiles, new Processor<PsiFile>() {
@Override
public boolean process(final PsiFile psiFile) {
@@ -103,12 +121,12 @@ public class AnnotatedPackagesSearcher implements QueryExecutor<PsiPackage, Anno
if (!psiManager.areElementsEquivalent(ref.resolve(), annClass)) return true;
- wantmore[0] = consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(stmt.getPackageName()));
- return wantmore[0];
+ wantMore[0] = consumer.process(JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(stmt.getPackageName()));
+ return wantMore[0];
}
}, true);
- return wantmore[0];
+ return wantMore[0];
}
private static class PackageInfoFilesOnly extends GlobalSearchScope {
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaAllOverridingMethodsSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaAllOverridingMethodsSearcher.java
index 35ec8b2800e7..f8f824b77c95 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaAllOverridingMethodsSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaAllOverridingMethodsSearcher.java
@@ -15,6 +15,8 @@
*/
package com.intellij.psi.impl.search;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.*;
import com.intellij.psi.search.SearchScope;
@@ -39,11 +41,18 @@ public class JavaAllOverridingMethodsSearcher implements QueryExecutor<Pair<PsiM
public boolean execute(@NotNull final AllOverridingMethodsSearch.SearchParameters p, @NotNull final Processor<Pair<PsiMethod, PsiMethod>> consumer) {
final PsiClass psiClass = p.getPsiClass();
- PsiMethod[] methodsArray = psiClass.getMethods();
- final List<PsiMethod> methods = new ArrayList<PsiMethod>(methodsArray.length);
- for (PsiMethod method : methodsArray) {
- if (PsiUtil.canBeOverriden(method)) methods.add(method);
- }
+ final List<PsiMethod> methods = ApplicationManager.getApplication().runReadAction(new Computable<List<PsiMethod>>() {
+ @Override
+ public List<PsiMethod> compute() {
+ PsiMethod[] methodsArray = psiClass.getMethods();
+ final List<PsiMethod> methods = new ArrayList<PsiMethod>(methodsArray.length);
+ for (PsiMethod method : methodsArray) {
+ if (PsiUtil.canBeOverriden(method)) methods.add(method);
+ }
+ return methods;
+ }
+ });
+
final SearchScope scope = p.getScope();
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaDirectInheritorsSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaDirectInheritorsSearcher.java
index fb012672660d..287d43f4cf2d 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaDirectInheritorsSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaDirectInheritorsSearcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,12 @@ package com.intellij.psi.impl.search;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.progress.ProgressIndicatorProvider;
+import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
-import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.java.stubs.index.JavaAnonymousClassBaseRefOccurenceIndex;
import com.intellij.psi.impl.java.stubs.index.JavaSuperClassNameOccurenceIndex;
import com.intellij.psi.search.EverythingGlobalScope;
@@ -31,6 +31,7 @@ import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.AllClassesSearch;
import com.intellij.psi.search.searches.DirectClassInheritorsSearch;
import com.intellij.psi.util.PsiUtil;
+import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import com.intellij.util.containers.ContainerUtil;
@@ -49,7 +50,6 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
@Override
public boolean execute(@NotNull final DirectClassInheritorsSearch.SearchParameters p, @NotNull final Processor<PsiClass> consumer) {
final PsiClass aClass = p.getClassToProcess();
- final PsiManagerImpl psiManager = (PsiManagerImpl)aClass.getManager();
final SearchScope useScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@Override
@@ -65,13 +65,13 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
}
});
+ final Project project = PsiUtilCore.getProjectInReadAction(aClass);
if (CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName)) {
//[pasynkov]: WTF?
//final SearchScope scope = useScope.intersectWith(GlobalSearchScope.notScope(GlobalSearchScope.getScopeRestrictedByFileTypes(
// GlobalSearchScope.allScope(psiManager.getProject()), StdFileTypes.JSP, StdFileTypes.JSPX)));
- final SearchScope scope = useScope;
- return AllClassesSearch.search(scope, aClass.getProject()).forEach(new Processor<PsiClass>() {
+ return AllClassesSearch.search(useScope, project).forEach(new Processor<PsiClass>() {
@Override
public boolean process(final PsiClass psiClass) {
if (psiClass.isInterface()) {
@@ -90,7 +90,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
});
}
- final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : new EverythingGlobalScope(psiManager.getProject());
+ final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : new EverythingGlobalScope(project);
final String searchKey = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
@@ -104,15 +104,20 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
Collection<PsiReferenceList> candidates = ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiReferenceList>>() {
@Override
public Collection<PsiReferenceList> compute() {
- return JavaSuperClassNameOccurenceIndex.getInstance().get(searchKey, psiManager.getProject(), scope);
+ return JavaSuperClassNameOccurenceIndex.getInstance().get(searchKey, project, scope);
}
});
Map<String, List<PsiClass>> classes = new HashMap<String, List<PsiClass>>();
- for (PsiReferenceList referenceList : candidates) {
+ for (final PsiReferenceList referenceList : candidates) {
ProgressIndicatorProvider.checkCanceled();
- final PsiClass candidate = (PsiClass)referenceList.getParent();
+ final PsiClass candidate = (PsiClass)ApplicationManager.getApplication().runReadAction(new Computable<PsiElement>() {
+ @Override
+ public PsiElement compute() {
+ return referenceList.getParent();
+ }
+ });
if (!checkInheritance(p, aClass, candidate)) continue;
String fqn = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@@ -137,7 +142,7 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
Collection<PsiAnonymousClass> anonymousCandidates = ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiAnonymousClass>>() {
@Override
public Collection<PsiAnonymousClass> compute() {
- return JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(searchKey, psiManager.getProject(), scope);
+ return JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(searchKey, project, scope);
}
});
@@ -148,7 +153,13 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
if (!consumer.process(candidate)) return false;
}
- if (aClass.isEnum()) {
+ boolean isEnum = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ return aClass.isEnum();
+ }
+ });
+ if (isEnum) {
// abstract enum can be subclassed in the body
PsiField[] fields = ApplicationManager.getApplication().runReadAction(new Computable<PsiField[]>() {
@Override
@@ -189,10 +200,10 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
// if there is a class from the same jar, prefer it
boolean sameJarClassFound = false;
- VirtualFile jarFile = PsiUtil.getJarFile(aClass);
+ VirtualFile jarFile = getJarFile(aClass);
if (jarFile != null) {
for (PsiClass sameNamedClass : sameNamedClasses) {
- boolean fromSameJar = Comparing.equal(PsiUtil.getJarFile(sameNamedClass), jarFile);
+ boolean fromSameJar = Comparing.equal(getJarFile(sameNamedClass), jarFile);
if (fromSameJar) {
sameJarClassFound = true;
if (!consumer.process(sameNamedClass)) return false;
@@ -202,4 +213,13 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
return sameJarClassFound || ContainerUtil.process(sameNamedClasses, consumer);
}
+
+ private static VirtualFile getJarFile(final PsiClass aClass) {
+ return ApplicationManager.getApplication().runReadAction(new Computable<VirtualFile>() {
+ @Override
+ public VirtualFile compute() {
+ return PsiUtil.getJarFile(aClass);
+ }
+ });
+ }
}
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java
index 2ee2cc2d8123..e7da21e37b51 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/JavaFunctionalExpressionSearcher.java
@@ -27,6 +27,7 @@ import com.intellij.psi.search.searches.FunctionalExpressionSearch;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiUtil;
+import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
import org.jetbrains.annotations.NotNull;
@@ -36,15 +37,15 @@ import java.util.Collection;
public class JavaFunctionalExpressionSearcher implements QueryExecutor<PsiFunctionalExpression, FunctionalExpressionSearch.SearchParameters> {
@Override
- public boolean execute(final @NotNull FunctionalExpressionSearch.SearchParameters queryParameters,
- final @NotNull Processor<PsiFunctionalExpression> consumer) {
+ public boolean execute(@NotNull final FunctionalExpressionSearch.SearchParameters queryParameters,
+ @NotNull final Processor<PsiFunctionalExpression> consumer) {
final PsiClass aClass = queryParameters.getElementToSearch();
- if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ if (ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
- return LambdaUtil.isFunctionalClass(aClass);
+ return !LambdaUtil.isFunctionalClass(aClass) || !PsiUtil.isLanguageLevel8OrHigher(aClass);
}
- }) || !PsiUtil.isLanguageLevel8OrHigher(aClass)) {
+ })) {
return true;
}
return collectFunctionalExpressions(aClass, ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
@@ -64,8 +65,13 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor<PsiFuncti
return aClass.getUseScope();
}
});
- final SearchScope useScope = searchScope.intersectWith(classScope);
- final Project project = aClass.getProject();
+ final SearchScope useScope = ApplicationManager.getApplication().runReadAction(new Computable<SearchScope>() {
+ @Override
+ public SearchScope compute() {
+ return searchScope.intersectWith(classScope);
+ }
+ });
+ final Project project = PsiUtilCore.getProjectInReadAction(aClass);
final GlobalSearchScope scope = useScope instanceof GlobalSearchScope ? (GlobalSearchScope)useScope : new EverythingGlobalScope(project);
final Collection<PsiMethod> lambdaCandidates = ApplicationManager.getApplication().runReadAction(new Computable<Collection<PsiMethod>>() {
@Override
@@ -76,16 +82,16 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor<PsiFuncti
}
});
for (PsiMethod psiMethod : lambdaCandidates) {
- for (PsiReference ref : MethodReferencesSearch.search(psiMethod, scope, false)) {
- final PsiElement refElement = ref.getElement();
- if (refElement != null) {
- final PsiElement candidateElement = refElement.getParent();
- if (candidateElement instanceof PsiCallExpression) {
- final PsiExpressionList argumentList = ((PsiCallExpression)candidateElement).getArgumentList();
- if (argumentList != null) {
- final Boolean accepted = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
- @Override
- public Boolean compute() {
+ for (final PsiReference ref : MethodReferencesSearch.search(psiMethod, scope, false)) {
+ boolean accepted = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ final PsiElement refElement = ref.getElement();
+ if (refElement != null) {
+ final PsiElement candidateElement = refElement.getParent();
+ if (candidateElement instanceof PsiCallExpression) {
+ final PsiExpressionList argumentList = ((PsiCallExpression)candidateElement).getArgumentList();
+ if (argumentList != null) {
final PsiExpression[] args = argumentList.getExpressions();
for (PsiExpression arg : args) {
if (arg instanceof PsiFunctionalExpression) {
@@ -96,57 +102,66 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor<PsiFuncti
}
}
}
- return true;
}
- });
- if (!accepted) return false;
+ }
}
+ return true;
}
- }
+ });
+ if (!accepted) return false;
}
}
- for (PsiReference reference : ReferencesSearch.search(aClass, scope)) {
- final PsiElement element = reference.getElement();
- if (element != null) {
- final PsiElement parent = element.getParent();
- if (parent instanceof PsiTypeElement) {
- final PsiElement gParent = parent.getParent();
- if (gParent instanceof PsiVariable) {
- final PsiExpression initializer = PsiUtil.skipParenthesizedExprDown(((PsiVariable)gParent).getInitializer());
- if (initializer instanceof PsiFunctionalExpression) {
- if (!consumer.process((PsiFunctionalExpression)initializer)) return false;
- }
- for (PsiReference varRef : ReferencesSearch.search(parent, scope)) {
- final PsiElement varElement = varRef.getElement();
- if (varElement != null) {
- final PsiElement varElementParent = varElement.getParent();
- if (varElementParent instanceof PsiAssignmentExpression &&
- ((PsiAssignmentExpression)varElementParent).getLExpression() == varElement) {
- final PsiExpression rExpression = PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)varElementParent).getRExpression());
- if (rExpression instanceof PsiFunctionalExpression) {
- if (!consumer.process((PsiFunctionalExpression)rExpression)) return false;
+ for (final PsiReference reference : ReferencesSearch.search(aClass, scope)) {
+ boolean accepted = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ final PsiElement element = reference.getElement();
+ if (element != null) {
+ final PsiElement parent = element.getParent();
+ if (parent instanceof PsiTypeElement) {
+ final PsiElement gParent = parent.getParent();
+ if (gParent instanceof PsiVariable) {
+ final PsiExpression initializer = PsiUtil.skipParenthesizedExprDown(((PsiVariable)gParent).getInitializer());
+ if (initializer instanceof PsiFunctionalExpression) {
+ if (!consumer.process((PsiFunctionalExpression)initializer)) return false;
+ }
+ for (PsiReference varRef : ReferencesSearch.search(parent, scope)) {
+ final PsiElement varElement = varRef.getElement();
+ if (varElement != null) {
+ final PsiElement varElementParent = varElement.getParent();
+ if (varElementParent instanceof PsiAssignmentExpression &&
+ ((PsiAssignmentExpression)varElementParent).getLExpression() == varElement) {
+ final PsiExpression rExpression = PsiUtil.skipParenthesizedExprDown(((PsiAssignmentExpression)varElementParent).getRExpression());
+ if (rExpression instanceof PsiFunctionalExpression) {
+ if (!consumer.process((PsiFunctionalExpression)rExpression)) return false;
+ }
+ }
}
}
- }
- }
- } else if (gParent instanceof PsiMethod) {
- final PsiReturnStatement[] returnStatements = ApplicationManager.getApplication().runReadAction(
- new Computable<PsiReturnStatement[]>() {
- @Override
- public PsiReturnStatement[] compute() {
- return PsiUtil.findReturnStatements((PsiMethod)gParent);
+ } else if (gParent instanceof PsiMethod) {
+ final PsiReturnStatement[] returnStatements = ApplicationManager.getApplication().runReadAction(
+ new Computable<PsiReturnStatement[]>() {
+ @Override
+ public PsiReturnStatement[] compute() {
+ return PsiUtil.findReturnStatements((PsiMethod)gParent);
+ }
+ });
+ for (PsiReturnStatement returnStatement : returnStatements) {
+ final PsiExpression returnValue = returnStatement.getReturnValue();
+ if (returnValue instanceof PsiFunctionalExpression) {
+ if (!consumer.process((PsiFunctionalExpression)returnValue)) return false;
+ }
}
- });
- for (PsiReturnStatement returnStatement : returnStatements) {
- final PsiExpression returnValue = returnStatement.getReturnValue();
- if (returnValue instanceof PsiFunctionalExpression) {
- if (!consumer.process((PsiFunctionalExpression)returnValue)) return false;
}
}
}
+
+ return true;
}
- }
+ });
+ if (!accepted) return false;
+
}
return true;
}
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodDeepestSuperSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodDeepestSuperSearcher.java
index ece2108b072c..933998344add 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodDeepestSuperSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodDeepestSuperSearcher.java
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.intellij.psi.impl.search;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiMethod;
import com.intellij.util.Processor;
import com.intellij.util.QueryExecutor;
@@ -23,12 +40,17 @@ public class MethodDeepestSuperSearcher implements QueryExecutor<PsiMethod, PsiM
return findDeepestSuperOrSelfSignature(method, methods, null, consumer);
}
- private static boolean findDeepestSuperOrSelfSignature(PsiMethod method,
+ private static boolean findDeepestSuperOrSelfSignature(final PsiMethod method,
Set<PsiMethod> set,
Set<PsiMethod> guard,
Processor<PsiMethod> processor) {
if (guard != null && !guard.add(method)) return true;
- PsiMethod[] supers = method.findSuperMethods();
+ PsiMethod[] supers = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod[]>() {
+ @Override
+ public PsiMethod[] compute() {
+ return method.findSuperMethods();
+ }
+ });
if (supers.length == 0 && set.add(method) && !processor.process(method)) {
return false;
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodSuperSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodSuperSearcher.java
index d65e80e7f997..acb5faae4947 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodSuperSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/MethodSuperSearcher.java
@@ -1,6 +1,23 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.intellij.psi.impl.search;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.search.searches.SuperMethodsSearch;
import com.intellij.psi.util.InheritanceUtil;
@@ -22,18 +39,23 @@ public class MethodSuperSearcher implements QueryExecutor<MethodSignatureBackedB
public boolean execute(@NotNull final SuperMethodsSearch.SearchParameters queryParameters, @NotNull final Processor<MethodSignatureBackedByPsiMethod> consumer) {
final PsiClass parentClass = queryParameters.getPsiClass();
final PsiMethod method = queryParameters.getMethod();
- HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature();
+ return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature();
- final boolean checkBases = queryParameters.isCheckBases();
- final boolean allowStaticMethod = queryParameters.isAllowStaticMethod();
- final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures();
- for (HierarchicalMethodSignature superSignature : supers) {
- if (MethodSignatureUtil.isSubsignature(superSignature, signature)) {
- if (!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) return false;
- }
- }
+ final boolean checkBases = queryParameters.isCheckBases();
+ final boolean allowStaticMethod = queryParameters.isAllowStaticMethod();
+ final List<HierarchicalMethodSignature> supers = signature.getSuperSignatures();
+ for (HierarchicalMethodSignature superSignature : supers) {
+ if (MethodSignatureUtil.isSubsignature(superSignature, signature)) {
+ if (!addSuperMethods(superSignature, method, parentClass, allowStaticMethod, checkBases, consumer)) return false;
+ }
+ }
- return true;
+ return true;
+ }
+ });
}
private static boolean addSuperMethods(final HierarchicalMethodSignature signature,
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/PsiAnnotationMethodReferencesSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/PsiAnnotationMethodReferencesSearcher.java
index 50f10caef9cb..b5a6fc58d425 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/PsiAnnotationMethodReferencesSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/PsiAnnotationMethodReferencesSearcher.java
@@ -1,5 +1,22 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.intellij.psi.impl.search;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.*;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiUtil;
@@ -16,10 +33,24 @@ public class PsiAnnotationMethodReferencesSearcher implements QueryExecutor<PsiR
@Override
public boolean execute(@NotNull final ReferencesSearch.SearchParameters p, @NotNull final Processor<PsiReference> consumer) {
final PsiElement refElement = p.getElementToSearch();
- if (PsiUtil.isAnnotationMethod(refElement)) {
- PsiMethod method = (PsiMethod)refElement;
- if (PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) && method.getParameterList().getParametersCount() == 0) {
- final Query<PsiReference> query = ReferencesSearch.search(method.getContainingClass(), p.getScope(), p.isIgnoreAccessScope());
+ boolean isAnnotation = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ return PsiUtil.isAnnotationMethod(refElement);
+ }
+ });
+ if (isAnnotation) {
+ final PsiMethod method = (PsiMethod)refElement;
+ PsiClass containingClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
+ @Override
+ public PsiClass compute() {
+ boolean isValueMethod =
+ PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME.equals(method.getName()) && method.getParameterList().getParametersCount() == 0;
+ return isValueMethod ? method.getContainingClass() : null;
+ }
+ });
+ if (containingClass != null) {
+ final Query<PsiReference> query = ReferencesSearch.search(containingClass, p.getScope(), p.isIgnoreAccessScope());
return query.forEach(createImplicitDefaultAnnotationMethodConsumer(consumer));
}
}
diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/SimpleAccessorReferenceSearcher.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/SimpleAccessorReferenceSearcher.java
index 16870688e738..e047db8b992a 100644
--- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/SimpleAccessorReferenceSearcher.java
+++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/SimpleAccessorReferenceSearcher.java
@@ -54,7 +54,6 @@ public class SimpleAccessorReferenceSearcher extends QueryExecutorBase<PsiRefere
for (CustomPropertyScopeProvider provider : Extensions.getExtensions(CustomPropertyScopeProvider.EP_NAME)) {
additional = additional.union(provider.getScope(method.getProject()));
}
- assert propertyName != null;
final SearchScope propScope = scope.intersectWith(method.getUseScope()).intersectWith(additional);
collector.searchWord(propertyName, propScope, UsageSearchContext.IN_FOREIGN_LANGUAGES, true, method);
}