From 9ec258fb42234e70e857c786f03b85d03433d583 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 30 Jul 2015 08:37:16 +0200 Subject: [PATCH] JavaFunctionalExpressionSearcher: in small scopes, don't bother with method stub index non-call usages are included, don't search for them again --- .../JavaFunctionalExpressionSearcher.java | 63 ++++++++++--------- 1 file changed, 34 insertions(+), 29 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 ddcdd6ada2a6..89579a75c071 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,46 +110,51 @@ public class JavaFunctionalExpressionSearcher implements QueryExecutor filesToProcess = ContainerUtil.newLinkedHashSet(); - //collect all files with '::' and '->' in useScope Set candidateFiles = getFilesWithFunctionalExpressionsScope(project, useScope); + if (candidateFiles.size() < 5) { + return searchInFiles(aClass, consumer, candidateFiles, expectedFunExprParamsCount); + } + final GlobalSearchScope filesScope = GlobalSearchScope.filesScope(project, candidateFiles); - 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); + //collect all methods with parameter of functional interface or free type parameter type + final Collection methodCandidates = getCandidateMethodsWithSuitableParams(aClass, project, useScope); - final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); + 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)); - } - }); - } + //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