Extract searchLocalFunction() method
This commit is contained in:
+45
-33
@@ -74,46 +74,18 @@ public class KotlinFindFunctionUsagesHandler extends KotlinFindUsagesHandler<Jet
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean searchReferences(
|
public boolean searchReferences(
|
||||||
@NotNull final PsiElement element,
|
@NotNull PsiElement element,
|
||||||
@NotNull final Processor<UsageInfo> processor,
|
@NotNull final Processor<UsageInfo> processor,
|
||||||
@NotNull FindUsagesOptions options
|
@NotNull FindUsagesOptions options
|
||||||
) {
|
) {
|
||||||
|
JetNamedFunction function = (JetNamedFunction) element;
|
||||||
|
|
||||||
final KotlinMethodFindUsagesOptions kotlinOptions = (KotlinMethodFindUsagesOptions) options;
|
final KotlinMethodFindUsagesOptions kotlinOptions = (KotlinMethodFindUsagesOptions) options;
|
||||||
SearchScope searchScope = kotlinOptions.searchScope;
|
SearchScope searchScope = kotlinOptions.searchScope;
|
||||||
|
|
||||||
JetElement blockForLocalDeclaration = JetPsiUtil.getEnclosingBlockForLocalDeclaration((JetNamedFunction) element);
|
JetElement blockForLocalDeclaration = JetPsiUtil.getEnclosingBlockForLocalDeclaration(function);
|
||||||
if (blockForLocalDeclaration != null && kotlinOptions.isUsages) {
|
if (blockForLocalDeclaration != null && kotlinOptions.isUsages) {
|
||||||
BindingContext bindingContext =
|
return searchLocalFunction(element, processor, function, kotlinOptions, blockForLocalDeclaration);
|
||||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
|
||||||
|
|
||||||
final List<PsiReference> result = new ArrayList<PsiReference>();
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final PsiMethod lightMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
final PsiMethod lightMethod = ApplicationManager.getApplication().runReadAction(new Computable<PsiMethod>() {
|
||||||
@@ -176,6 +148,46 @@ public class KotlinFindFunctionUsagesHandler extends KotlinFindUsagesHandler<Jet
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean searchLocalFunction(
|
||||||
|
final PsiElement element,
|
||||||
|
Processor<UsageInfo> processor,
|
||||||
|
final JetNamedFunction function,
|
||||||
|
final KotlinMethodFindUsagesOptions kotlinOptions,
|
||||||
|
JetElement blockForLocalDeclaration
|
||||||
|
) {
|
||||||
|
BindingContext bindingContext =
|
||||||
|
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||||
|
|
||||||
|
final List<PsiReference> result = new ArrayList<PsiReference>();
|
||||||
|
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
|
@Override
|
||||||
protected boolean isSearchForTextOccurencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) {
|
protected boolean isSearchForTextOccurencesAvailable(@NotNull PsiElement psiElement, boolean isSingleFile) {
|
||||||
if (isSingleFile) return false;
|
if (isSingleFile) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user