From 98705046f5eb8542c2fb26ba7e26139cadd4e12a Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 29 Jul 2015 22:04:15 +0200 Subject: [PATCH] JavaFunctionalExpressionSearcher: in small scopes, don't bother with method stub index --- .../JavaFunctionalExpressionSearcher.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) 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 ffe84393350b..c0bbe6495cbe 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 @@ -101,13 +101,6 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor' in useScope - final GlobalSearchScope filesScope = getFilesWithFunctionalExpressionsScope(project, useScope); - - //collect all methods with parameter of functional interface or free type parameter type - final Collection methodCandidates = getCandidateMethodsWithSuitableParams(aClass, project, useScope); - - final LinkedHashSet filesToProcess = new LinkedHashSet(); final MethodSignature functionalInterfaceMethod = ApplicationManager.getApplication().runReadAction(new Computable() { @Override public MethodSignature compute() { @@ -116,6 +109,19 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor' in useScope + Set candidateFiles = getFilesWithFunctionalExpressionsScope(project, useScope); + if (candidateFiles.size() < 5) { + return searchInFiles(aClass, consumer, candidateFiles, expectedFunExprParamsCount); + } + + final GlobalSearchScope filesScope = GlobalSearchScope.filesScope(project, candidateFiles); + + //collect all methods with parameter of functional interface or free type parameter type + final Collection methodCandidates = getCandidateMethodsWithSuitableParams(aClass, project, useScope); + + final LinkedHashSet filesToProcess = new LinkedHashSet(); final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); //find all usages of method candidates in files with functional expressions @@ -143,6 +149,12 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor consumer, + Set filesToProcess, final int expectedFunExprParamsCount) { LOG.info("#usage files: " + filesToProcess.size()); return ContainerUtil.process(filesToProcess, new ReadActionProcessor() { @Override @@ -172,14 +184,13 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor getFilesWithFunctionalExpressionsScope(Project project, GlobalSearchScope useScope) { + final Set files = ContainerUtil.newLinkedHashSet(); final PsiSearchHelperImpl helper = (PsiSearchHelperImpl)PsiSearchHelper.SERVICE.getInstance(project); - final HashSet files = new HashSet(); final CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor(files); helper.processFilesWithText(useScope, UsageSearchContext.IN_CODE, true, "::", processor); helper.processFilesWithText(useScope, UsageSearchContext.IN_CODE, true, "->", processor); - - return GlobalSearchScope.filesScope(project, files); + return files; } @NotNull