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 26a26cf6dcb3..d9ed3258ec3e 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 @@ -33,6 +33,8 @@ import com.intellij.psi.impl.java.stubs.index.JavaMethodParameterTypesIndex; import com.intellij.psi.search.*; import com.intellij.psi.search.searches.FunctionalExpressionSearch; import com.intellij.psi.search.searches.ReferencesSearch; +import com.intellij.psi.stubs.StubIndex; +import com.intellij.psi.stubs.StubIndexKey; import com.intellij.psi.util.*; import com.intellij.util.CommonProcessors; import com.intellij.util.Function; @@ -42,10 +44,12 @@ import com.intellij.util.indexing.FileBasedIndex; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; import static com.intellij.util.containers.ContainerUtil.*; +import static com.intellij.util.containers.ContainerUtilRt.newHashSet; public class JavaFunctionalExpressionSearcher extends QueryExecutorBase { private static final Logger LOG = Logger.getInstance("#" + JavaFunctionalExpressionSearcher.class.getName()); @@ -67,7 +71,7 @@ public class JavaFunctionalExpressionSearcher extends QueryExecutorBase highLevelModules = getJava8Modules(project); if (highLevelModules.isEmpty()) return; - useScope = new ModulesScope(highLevelModules, project).intersectWith(convertToGlobalScope(project, queryParameters.getEffectiveSearchScope())); + useScope = new JavaSourceFilterScope(new ModulesScope(highLevelModules, project).intersectWith(convertToGlobalScope(project, queryParameters.getEffectiveSearchScope()))); final MethodSignature functionalInterfaceMethod = LambdaUtil.getFunction(aClass); LOG.assertTrue(functionalInterfaceMethod != null); @@ -83,10 +87,10 @@ public class JavaFunctionalExpressionSearcher extends QueryExecutorBase methodCandidates = getCandidateMethodsWithSuitableParams(aClass, project, useScope, candidateFiles); + final Collection methodCandidates = getCandidateMethodsWithSuitableParams(aClass, project, useScope, candidateFiles, candidateScope); final LinkedHashSet filesToProcess = new LinkedHashSet(); final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance(); @@ -114,7 +118,7 @@ public class JavaFunctionalExpressionSearcher extends QueryExecutorBase getCandidateMethodsWithSuitableParams(final PsiClass aClass, final Project project, final GlobalSearchScope useScope, - final Set candidateFiles) { + final Set candidateFiles, + final GlobalSearchScope candidateScope) { return ApplicationManager.getApplication().runReadAction(new Computable>() { @Override public Collection compute() { - GlobalSearchScope visibleFromCandidates = combineResolveScopes(project, candidateFiles); - JavaMethodParameterTypesIndex index = JavaMethodParameterTypesIndex.getInstance(); + if (!aClass.isValid()) return Collections.emptyList(); - LinkedHashSet methods = newLinkedHashSet(); - methods.addAll(index.get(aClass.getName(), project, useScope.intersectWith(visibleFromCandidates))); - methods.addAll(index.get(JavaMethodElementType.TYPE_PARAMETER_PSEUDO_NAME, project, visibleFromCandidates)); + GlobalSearchScope visibleFromCandidates = combineResolveScopes(project, candidateFiles); + + final Set usedMethodNames = newHashSet(); + FileBasedIndex.getInstance().processAllKeys(JavaFunctionalExpressionIndex.JAVA_FUNCTIONAL_EXPRESSION_INDEX_ID, + new CommonProcessors.CollectProcessor(usedMethodNames), candidateScope, null); + + final LinkedHashSet methods = newLinkedHashSet(); + Processor methodProcessor = new Processor() { + @Override + public boolean process(PsiMethod method) { + if (usedMethodNames.contains(method.getName())) { + methods.add(method); + } + return true; + } + }; + + StubIndexKey key = JavaMethodParameterTypesIndex.getInstance().getKey(); + StubIndex index = StubIndex.getInstance(); + index.processElements(key, aClass.getName(), project, useScope.intersectWith(visibleFromCandidates), PsiMethod.class, methodProcessor); + index.processElements(key, JavaMethodElementType.TYPE_PARAMETER_PSEUDO_NAME, project, visibleFromCandidates, PsiMethod.class, methodProcessor); LOG.info("#methods: " + methods.size()); return methods; } @@ -174,7 +196,7 @@ public class JavaFunctionalExpressionSearcher extends QueryExecutorBase resolveScopes = newLinkedHashSet(mapNotNull(candidateFiles, new Function() { @Override public GlobalSearchScope fun(VirtualFile file) { - PsiFile psiFile = psiManager.findFile(file); + PsiFile psiFile = file.isValid() ? psiManager.findFile(file) : null; return psiFile == null ? null : psiFile.getResolveScope(); } }));