Is it possible to use Find Usages on a java.lang.reflect.Method?

I want to programmatically invoke the `Find Usages` on a set of methods or class objects and return the same output that Find Usages would do in the IDE.

Is there some sort of IntelliJ.findUsages(Method method): List<Usages>  or something of that flavor?

How could I achieve this in a main method?

1
3 comments
Avatar
Permanently deleted user

Find Usages in IDEA works with PSI (see e.g. https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi_files.html)

If you need to process usages of some method in your plugin then

1. you have to get a PSI reference you want to search usages of 

2. you start the find usages by invoking e.g. com.intellij.psi.search.searches.ReferencesSearch

 

0
Avatar
Permanently deleted user

Hmmm... I can't seem to see any way to get a PSI in the main method. Is it possible to use this outside of a plugin type application?

0
Avatar
Permanently deleted user

If by "main method" you mean your own `"class HelloWorld { void main() { System.out.println("Where is my PSI?"); } }"` then no. Because IDEA has to know where your files are, load and parse them, build indices in order to Find Usages to work. The easiest way seems to be to write your plugin where register an action which has access to PSI context it was invoked from. Please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html and https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/creating_an_action.html

0

Please sign in to leave a comment.