Searching the method usages the same way IntelliJ does
Hello,
I'm developing a custom IntelliJ plugin to improve code analysis and navigation within the IDE for Java codebases. One of the essential features I'm working on is a "Find Usages" functionality, similar to IntelliJ's built-in feature.
Here's what I've accomplished so far:
Collection<PsiReference> allReferences = ReferencesSearch.search(method).findAll();
for (PsiClass anInterface : method.getContainingClass().getInterfaces()) {
PsiMethod methodBySignature = anInterface.findMethodBySignature(method, false);
if (methodBySignature != null) {
allReferences.addAll(ReferencesSearch.search(methodBySignature).findAll());
}
}
The code above allows me to search for references to a target method within its containing class and its implemented interfaces. However, I've encountered a performance issue where the ReferencesSearch.search
operation can be quite slow, sometimes leading to prolonged searches with messages like "Searching for xx in 6072 files" that never seem to complete.
How does IntelliJ internally handle the "Find Usages" feature to find usages or usages of the base method in all places?
Thank you for your time and support.
请先登录再写评论。
Hi Emre,
I don’t understand your use case. You can consider using
Query.forEach
or other methods instead ofQuery.findAll()
.If it doesn’t help, I suggest debugging the platform code to understand what is happening under the hood. The starting point for this case can be https://github.com/JetBrains/intellij-community/blob/master/java/java-impl/src/com/intellij/find/findUsages/JavaFindUsagesHandler.java#L126
Condition
myFactory.getFindMethodOptions().isSearchForBaseMethod
causes searching for a base method if a user selects it in the search options dialog.Hello! Have you found a solution to your problem? I'm facing the same