mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
implicit to string search: check method before search
This commit is contained in:
@@ -182,7 +182,7 @@ public class JavaFindUsagesHelper {
|
||||
FunctionalExpressionSearch.search(psiMethod, methodOptions.searchScope).forEach(new PsiElementProcessorAdapter<>(
|
||||
expression -> addResult(expression, options, processor)));
|
||||
}
|
||||
if (methodOptions.isImplicitToString) {
|
||||
if (ImplicitToStringSearch.isToStringMethod(psiMethod) && methodOptions.isImplicitToString) {
|
||||
ImplicitToStringSearch.search(psiMethod, methodOptions.searchScope).forEach(new PsiElementProcessorAdapter<>(ref -> addResult(ref, options, processor)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,21 +68,6 @@ public class ImplicitToStringSearcher extends QueryExecutorBase<PsiExpression, I
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isToStringMethod(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiMethod)) {
|
||||
return false;
|
||||
}
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
if (!"toString".equals(method.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (method.getParameters().length != 0) {
|
||||
return false;
|
||||
}
|
||||
PsiType returnType = method.getReturnType();
|
||||
return returnType != null && returnType.equalsToText(CommonClassNames.JAVA_LANG_STRING);
|
||||
}
|
||||
|
||||
private static boolean processFile(VirtualFile file,
|
||||
int[] offsets,
|
||||
PsiManager manager,
|
||||
|
||||
+16
-2
@@ -1,8 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.psi.search.searches;
|
||||
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.util.Query;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,4 +33,19 @@ public class ImplicitToStringSearch extends ExtensibleQueryFactory<PsiExpression
|
||||
public static Query<PsiExpression> search(@NotNull PsiMethod targetMethod, @NotNull SearchScope scope) {
|
||||
return INSTANCE.createUniqueResultsQuery(new SearchParameters(targetMethod, scope));
|
||||
}
|
||||
|
||||
public static boolean isToStringMethod(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiMethod)) {
|
||||
return false;
|
||||
}
|
||||
PsiMethod method = (PsiMethod)element;
|
||||
if (!"toString".equals(method.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (method.getParameters().length != 0) {
|
||||
return false;
|
||||
}
|
||||
PsiType returnType = method.getReturnType();
|
||||
return returnType != null && returnType.equalsToText(CommonClassNames.JAVA_LANG_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user