allow reentrant ReferencesSearch & MethodReferencesSearch

This commit is contained in:
peter
2010-06-15 16:57:53 +04:00
parent 01e51ee0a7
commit 480dc2ef2b
3 changed files with 22 additions and 21 deletions
@@ -16,10 +16,9 @@ import org.jetbrains.annotations.NotNull;
* @author max
*/
public class MethodUsagesSearcher extends SearchRequestor implements QueryExecutor<PsiReference, MethodReferencesSearch.SearchParameters> {
private static final ThreadLocal<Boolean> ourProcessing = new ThreadLocal<Boolean>();
public boolean execute(final MethodReferencesSearch.SearchParameters p, final Processor<PsiReference> consumer) {
if (ourProcessing.get() != null) {
if (p instanceof MySearchParameters) {
return true;
}
@@ -48,13 +47,7 @@ public class MethodUsagesSearcher extends SearchRequestor implements QueryExecut
contributeSearchTargets(method, options, collector, strictSignatureSearch);
collector.searchCustom(new Processor<Processor<PsiReference>>() {
public boolean process(Processor<PsiReference> processor) {
ourProcessing.set(true);
try {
return MethodReferencesSearch.search(method, options.searchScope, strictSignatureSearch).forEach(processor);
}
finally {
ourProcessing.set(null);
}
return MethodReferencesSearch.search(new MySearchParameters(method, options, strictSignatureSearch)).forEach(processor);
}
});
}
@@ -105,4 +98,9 @@ public class MethodUsagesSearcher extends SearchRequestor implements QueryExecut
collector.searchWord(textToSearch, restrictedByAccess, searchContext, true, new MethodTextOccurenceProcessor(aClass, strictSignatureSearch, methods));
}
private static class MySearchParameters extends MethodReferencesSearch.SearchParameters {
public MySearchParameters(PsiMethod method, FindUsagesOptions options, boolean strictSignatureSearch) {
super(method, options.searchScope, strictSignatureSearch);
}
}
}
@@ -55,8 +55,12 @@ public class MethodReferencesSearch extends ExtensibleQueryFactory<PsiReference,
private MethodReferencesSearch() {}
public static Query<PsiReference> search(final PsiMethod method, SearchScope scope, final boolean strictSignatureSearch) {
return search(new SearchParameters(method, scope, strictSignatureSearch));
}
public static Query<PsiReference> search(final SearchParameters parameters) {
//noinspection unchecked
return INSTANCE.createUniqueResultsQuery(new SearchParameters(method, scope, strictSignatureSearch), TObjectHashingStrategy.CANONICAL, ReferenceDescriptor.MAPPER);
return INSTANCE.createUniqueResultsQuery(parameters, TObjectHashingStrategy.CANONICAL, ReferenceDescriptor.MAPPER);
}
public static Query<PsiReference> search(final PsiMethod method, final boolean strictSignatureSearch) {
@@ -25,10 +25,9 @@ import org.jetbrains.annotations.NotNull;
* @author max
*/
public class CachesBasedRefSearcher extends SearchRequestor implements QueryExecutor<PsiReference, ReferencesSearch.SearchParameters> {
private static final ThreadLocal<Boolean> ourProcessing = new ThreadLocal<Boolean>();
public boolean execute(final ReferencesSearch.SearchParameters p, final Processor<PsiReference> consumer) {
if (ourProcessing.get() != null) {
if (p instanceof MySearchParameters) {
return true;
}
@@ -48,20 +47,14 @@ public class CachesBasedRefSearcher extends SearchRequestor implements QueryExec
@Override
public void contributeRequests(@NotNull final PsiElement refElement,
@NotNull FindUsagesOptions options,
@NotNull SearchRequestCollector collector) {
@NotNull FindUsagesOptions options,
@NotNull SearchRequestCollector collector) {
final boolean ignoreAccessScope = false;
final SearchScope scope = options.searchScope;
contributeSearchTargets(refElement, options, collector, ignoreAccessScope, scope);
collector.searchCustom(new Processor<Processor<PsiReference>>() {
public boolean process(Processor<PsiReference> consumer) {
ourProcessing.set(true);
try {
return ReferencesSearch.search(refElement, scope, ignoreAccessScope).forEach(consumer);
}
finally {
ourProcessing.set(null);
}
return ReferencesSearch.search(new MySearchParameters(refElement, scope, ignoreAccessScope)).forEach(consumer);
}
});
}
@@ -100,4 +93,10 @@ public class CachesBasedRefSearcher extends SearchRequestor implements QueryExec
collector.searchWord(text, searchScope, refElement.getLanguage().isCaseSensitive(), refElement);
}
}
private static class MySearchParameters extends ReferencesSearch.SearchParameters {
public MySearchParameters(PsiElement refElement, SearchScope scope, boolean ignoreAccessScope) {
super(refElement, scope, ignoreAccessScope);
}
}
}