mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
read action
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ public class MethodImplementationsSearch implements QueryExecutor<PsiElement, De
|
||||
})) {
|
||||
return false;
|
||||
}
|
||||
final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
List<PsiMethod> methods = new ArrayList<PsiMethod>();
|
||||
getOverridingMethods(psiMethod, methods, searchScope);
|
||||
return ContainerUtil.process(methods, consumer);
|
||||
}
|
||||
|
||||
+6
-2
@@ -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();
|
||||
|
||||
+53
-35
@@ -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(),
|
||||
useScope);
|
||||
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
|
||||
+14
-5
@@ -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();
|
||||
|
||||
|
||||
+25
-5
@@ -110,9 +110,14 @@ public class JavaDirectInheritorsSearcher implements QueryExecutor<PsiClass, Dir
|
||||
|
||||
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>() {
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+65
-55
@@ -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>() {
|
||||
@@ -65,7 +66,7 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor<PsiFuncti
|
||||
}
|
||||
});
|
||||
final SearchScope useScope = searchScope.intersectWith(classScope);
|
||||
final Project project = aClass.getProject();
|
||||
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 +77,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 +97,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);
|
||||
}
|
||||
});
|
||||
for (PsiReturnStatement returnStatement : returnStatements) {
|
||||
final PsiExpression returnValue = returnStatement.getReturnValue();
|
||||
if (returnValue instanceof PsiFunctionalExpression) {
|
||||
if (!consumer.process((PsiFunctionalExpression)returnValue)) 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);
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
+24
-2
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
+35
-4
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user