“Find usages” functionality as an IntelliJ plugin

亡梦爱人 提交于 2019-12-01 14:06:06

You can get the true PsiMethod by JavaPsiFacade.getInstance(...).findClass("java.lang.String", ...allScope(...)).findsMethodByName("concat", false)[0]. This method can then be passed to MethodReferenceSearch.

I am presuming that you can't guarantee that you have a usage of concat easily available (for example, at the user's cursor position in an open document).

A hacky way to do it would be to create a small, correct, self-contained java class in a String, like below:

class Nothing { String s = "a".concat("b"); }

Then, there is a way (if I remember correctly) to use IntelliJ to parse the class contained in this String, thereby giving you a PsiReference to the method you want to find usages on (in this case, concat).

Would this approach be useful to you?

If so, I can dig out a code example on how this can be done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!