diff --git a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindFunctionUsagesHandler.java b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindFunctionUsagesHandler.java index b41eab70ef2..aac72b4bfe4 100644 --- a/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindFunctionUsagesHandler.java +++ b/idea/src/org/jetbrains/jet/plugin/findUsages/handlers/KotlinFindFunctionUsagesHandler.java @@ -74,46 +74,18 @@ public class KotlinFindFunctionUsagesHandler extends KotlinFindUsagesHandler processor, @NotNull FindUsagesOptions options ) { + JetNamedFunction function = (JetNamedFunction) element; + final KotlinMethodFindUsagesOptions kotlinOptions = (KotlinMethodFindUsagesOptions) options; SearchScope searchScope = kotlinOptions.searchScope; - JetElement blockForLocalDeclaration = JetPsiUtil.getEnclosingBlockForLocalDeclaration((JetNamedFunction) element); + JetElement blockForLocalDeclaration = JetPsiUtil.getEnclosingBlockForLocalDeclaration(function); if (blockForLocalDeclaration != null && kotlinOptions.isUsages) { - BindingContext bindingContext = - AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext(); - - final List result = new ArrayList(); - CalleeReferenceVisitorBase visitor = new CalleeReferenceVisitorBase(bindingContext, true) { - private boolean isAcceptable(PsiElement declaration) { - if (kotlinOptions.isIncludeOverloadUsages) { - //noinspection ConstantConditions - return declaration instanceof JetNamedFunction && - ((JetNamedFunction) element).getName() - .equals(((JetNamedFunction) declaration).getName()); - } - - return declaration.equals(element); - } - - @Override - protected void processDeclaration(JetReferenceExpression reference, PsiElement declaration) { - if (isAcceptable(declaration)) { - result.add(reference.getReference()); - } - } - }; - - blockForLocalDeclaration.accept(visitor); - - for (PsiReference ref : result) { - if (!processUsage(processor, ref, kotlinOptions)) return false; - } - - return true; + return searchLocalFunction(element, processor, function, kotlinOptions, blockForLocalDeclaration); } final PsiMethod lightMethod = ApplicationManager.getApplication().runReadAction(new Computable() { @@ -176,6 +148,46 @@ public class KotlinFindFunctionUsagesHandler extends KotlinFindUsagesHandler processor, + final JetNamedFunction function, + final KotlinMethodFindUsagesOptions kotlinOptions, + JetElement blockForLocalDeclaration + ) { + BindingContext bindingContext = + AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext(); + + final List result = new ArrayList(); + CalleeReferenceVisitorBase visitor = new CalleeReferenceVisitorBase(bindingContext, true) { + private boolean isAcceptable(PsiElement declaration) { + if (kotlinOptions.isIncludeOverloadUsages) { + //noinspection ConstantConditions + return declaration instanceof JetNamedFunction && + function.getName() + .equals(((JetNamedFunction) declaration).getName()); + } + + return declaration.equals(element); + } + + @Override + protected void processDeclaration(JetReferenceExpression reference, PsiElement declaration) { + if (isAcceptable(declaration)) { + result.add(reference.getReference()); + } + } + }; + + blockForLocalDeclaration.accept(visitor); + + for (PsiReference ref : result) { + if (!processUsage(processor, ref, kotlinOptions)) return false; + } + + return true; + } + @Override protected boolean isSearchForTextOccurencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) { if (isSingleFile) return false;