So what I am trying to do is to filter my ReferenceSearch so that it only retrieves PsiReferences of a PsiElement within a specific method.
Usually, I do
references = ReferencesSearch.search(element).findAll();
to find all the references in my .java class.
Now I want to get the references of a specific method. How can I do that? I tried
references = ReferencesSearch.search(variable, method.getUseScope()).findAll();
but this does not seem to work.
How can I filter this search? Or, as a workaround, how can I conveniently filter the references afterwards to make sure they are located within a certain method? However, the first variant would be prefered.