ReferencesSearch.search return empty
I am having a problem with ReferencesSearch.search(). What I am doing is customing the Find Usages. I want to find where the Integer's valueOf method had been referenced in my project, below is my code:
public void actionPerformed(AnActionEvent e) {
// TODO: insert action logic here
Project project = e.getData(PlatformDataKeys.PROJECT);
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
PsiClass aClass = javaPsiFacade.findClass("java.lang.Integer", GlobalSearchScope.allScope(project));
PsiMethod[] valueOVES = aClass.findMethodsByName("valueOf", false);
for (int i = 0; i < valueOVES.length; i++) {
Query<PsiReference> search = ReferencesSearch.search(valueOVES[i], GlobalSearchScope.projectScope(project), false);
Collection<PsiReference> all = search.findAll();
}
}
The valueOVES's size is three, that's correct, But the all's size is 0.
And below is my test file JavaClass:
public class JavaClass {
class TestJava{
JavaClass javaClass;
public TestJava( ){
this.javaClass = new JavaClass();
Integer.valueOf("1223");
Integer.valueOf("1223");
Integer.valueOf("1223");
Integer.valueOf("1223");
Integer.valueOf("1223");
Integer.valueOf("1223");
}
}
}
Please help me, Thanks in advance!!
I have read https://intellij-support.jetbrains.com/hc/en-us/community/posts/206754855-ReferencesSearch-findAll-returns-Empty-Collection and https://intellij-support.jetbrains.com/hc/en-us/community/posts/207303915-Reference-Search-returning-empty-collection?input_string=ReferencesSearch.search%20return%20empty
But I can't get help from these reports. I am new to this. Can someone give me some documents or links? Thanks!
Please sign in to leave a comment.
Where is "JavaClass" located? Try replacing projectScope in ReferencesSearch.search invocation with GlobalSearchScope.allScope(project)