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 c0bbe6495cbe..ddcdd6ada2a6 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 @@ -110,51 +110,46 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor' in useScope - Set candidateFiles = getFilesWithFunctionalExpressionsScope(project, useScope); - if (candidateFiles.size() < 5) { - return searchInFiles(aClass, consumer, candidateFiles, expectedFunExprParamsCount); - } + final LinkedHashSet filesToProcess = ContainerUtil.newLinkedHashSet(); + //collect all files with '::' and '->' in useScope + Set candidateFiles = getFilesWithFunctionalExpressionsScope(project, useScope); 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); + if (candidateFiles.size() < 5) { + filesToProcess.addAll(candidateFiles); + } else { + //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 - for (final PsiMethod psiMethod : methodCandidates) { - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - if (!psiMethod.isValid()) return; - final int parametersCount = psiMethod.getParameterList().getParametersCount(); - final boolean varArgs = psiMethod.isVarArgs(); - final PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); - final GlobalSearchScope methodUseScope = modulesScope.intersectWith(convertToGlobalScope(project, psiMethod.getUseScope())); - fileBasedIndex.processValues(JavaFunctionalExpressionIndex.JAVA_FUNCTIONAL_EXPRESSION_INDEX_ID, psiMethod.getName(), null, - //functional expressions checker: number and type of parameters at call site should correspond to - //candidate method currently check - new SuitableFilesProcessor(filesToProcess, - expectedFunExprParamsCount, - parametersCount, - varArgs, - parameters), - useScope.intersectWith(methodUseScope)); - } - }); + final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); + + //find all usages of method candidates in files with functional expressions + for (final PsiMethod psiMethod : methodCandidates) { + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + if (!psiMethod.isValid()) return; + final int parametersCount = psiMethod.getParameterList().getParametersCount(); + final boolean varArgs = psiMethod.isVarArgs(); + final PsiParameter[] parameters = psiMethod.getParameterList().getParameters(); + final GlobalSearchScope methodUseScope = modulesScope.intersectWith(convertToGlobalScope(project, psiMethod.getUseScope())); + fileBasedIndex.processValues(JavaFunctionalExpressionIndex.JAVA_FUNCTIONAL_EXPRESSION_INDEX_ID, psiMethod.getName(), null, + //functional expressions checker: number and type of parameters at call site should correspond to + //candidate method currently check + new SuitableFilesProcessor(filesToProcess, + expectedFunExprParamsCount, + parametersCount, + varArgs, + parameters), + useScope.intersectWith(methodUseScope)); + } + }); + } } //search for functional expressions in non-call contexts collectFilesWithTypeOccurrencesAndFieldAssignments(aClass, filesScope, filesToProcess); - return searchInFiles(aClass, consumer, filesToProcess, expectedFunExprParamsCount); - } - - private static boolean searchInFiles(final PsiClass aClass, - final Processor consumer, - Set filesToProcess, final int expectedFunExprParamsCount) { LOG.info("#usage files: " + filesToProcess.size()); return ContainerUtil.process(filesToProcess, new ReadActionProcessor() { @Override