简体   繁体   English

“查找用法”功能作为 IntelliJ 插件

[英]"Find usages" functionality as an IntelliJ plugin

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.我试图在 IntelliJ IDEA 中找到一种方法来查找特定项目中一些库方法调用和类的所有用法。

The goal is to compile a list of classes which make reference to these specific methods or classes.目标是编译引用这些特定方法或类的类列表。

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.我该如何解决这个问题,我可以看到有一个MethodReferencesSearch看起来可能会有所帮助,但是搜索方法需要 PsiMethod 的一个实例。

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如何创建与特定 lib 类中的方法匹配的 PSI 方法实例(假设我想在 Java 的String类中找到concat(...)方法的所有用法

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.例如,通过在库中查找某些方法调用来绘制一组路由的东西。 Ie 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.即,如果 A 类调用类型为 B 的 x(T),而类 B 调用类型为 C 的 x(T),我将有一个看起来像 A -> B -> C 等的图。查找用法很棒,它只是不能很好地满足我的需求。

You can get the true PsiMethod by JavaPsiFacade.getInstance(...).findClass("java.lang.String", ...allScope(...)).findsMethodByName("concat", false)[0].您可以通过 JavaPsiFacade.getInstance(...).findClass("java.lang.String", ...allScope(...)).findsMethodByName("concat", false)[0] 获得真正的 PsiMethod。 This method can then be passed to MethodReferenceSearch.然后可以将此方法传递给 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).我假设您不能保证您可以轻松使用concat (例如,在打开的文档中用户的光标位置)。

A hacky way to do it would be to create a small, correct, self-contained java class in a String, like below:一个hacky的方法是在字符串中创建一个小的、正确的、自包含的java类,如下所示:

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 ).然后,有一种方法(如果我没记错的话)使用 IntelliJ 来解析包含在这个 String 中的类,从而为您提供一个PsiReference到您要查找用法的方法(在本例中为concat )。

Would this approach be useful to you?这种方法对你有用吗?

If so, I can dig out a code example on how this can be done.如果是这样,我可以挖掘出一个关于如何做到这一点的代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Intellij从方法中按包查找用法 - Intellij find usages by package from method 在Intellij中找到lombok生成的getter / setter的用法 - Find usages of lombok generated getter/setter in Intellij 如何在 Intellij 中查找 Class.this 使用的接口的用法 - How to find usages of an Inteface used by Class.this in Intellij 如何在IntelliJ 12中为查找用法设置默认范围? - How can I set the default Scope in IntelliJ 12 for Find Usages? 在IntelliJ中,是否可以找到具有特定类型的类型化方法的用法? - In IntelliJ, is it possible to find usages of a typed method with a specific type? 如何创建可以模拟Ctrl + F(查找)功能的Intellij插件。 - How to create an Intellij Plugin which can simulate the Ctrl + F (find) functionality. intellij - 找不到 Lombok 插件 - intellij - cannot find Lombok Plugin Intellij:在项目文件中找不到任何用法 - Intellij: No usages found in Project Files 如何将Intellij查找用法的结果限制为仅特定类的结果? - How do I limit the results of Intellij Find Usages to only those of a specific class? 如何在IntelliJ Idea中找出方法的所有用法(直接用法,通过某些库的传递用法)? - How to find out all usages of a method (direct usage, transitive usage through some library) in IntelliJ Idea?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM