“查找用法”作为IntelliJ插件的功能 [英] "Find usages" functionality as an IntelliJ plugin
问题描述
我正在尝试在IntelliJ IDEA中找到一种方法来查找特定项目中几个库方法调用和类的所有用法。
I'm trying to find a way in IntelliJ IDEA to find all the usages of a few library method calls and classes in a particular project.
目标是编译一个引用这些特定方法或类的类列表。
The goal is to compile a list of classes which make reference to these specific methods or classes.
我怎么能这样做,我可以看到有一个 MethodReferencesSearch
,看起来它可能会有所帮助,但是搜索方法需要PsiMethod的实例。
How can I go about this, I can see there is a MethodReferencesSearch
which looks like it could be helpful, however the search method requires an instance of PsiMethod.
如何创建与特定lib类中的方法匹配的PSI方法实例(假设我想找到的所有用法> concat(...)
Java中的方法字符串
类
How can I create an instance of PSI method that matches the method in a particular lib class (say I wanted to find all the usages of the concat(...)
method in Java's String
class
基本上我是尝试构建一个插件,它将从项目中生成某些方法调用的图形。例如,通过查找库中的某些方法调用来绘制一组路由的东西。即如果A类调用x(T)类型B类和B类用类C类调用x(T),我会有一个看起来像A - > B - > C等的图。找到用法很棒,它只是不能很好地满足我的需要。
Basically I'm trying to build a plugin that will generate a graph of certain method calls from within a project. For example something that would graph a set of routes by looking for certain method calls in a library. I.e. if Class A calls x(T) with type class B and class B calls x(T) with type of Class C, I would have a graph that looks like A -> B -> C etc. Find usages is great, it just doesnt work well for my needs.
推荐答案
您可以通过JavaPsiFacade.getInstance(...)获取真正的PsiMethod.findClass(java.lang.String,.. .allScope(...))。findsMethodByName(concat,false)[0]。然后可以将此方法传递给MethodReferenceSearch。
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.
这篇关于“查找用法”作为IntelliJ插件的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!