使用IntelliJ查找具有特定参数类型的所有方法调用

Oli*_*ire 6 intellij-idea structural-search

我有这个相当大的代码库(+/- 500k行).我正在查找它以查找使用单个参数的所有方法调用,并且该参数是特定类型.

这意味着,我希望能够找到如下方法调用:

public class Foo { }
public class Bar { }

public class Doer{
  public void doSomethingFoo(Foo foo) {  }
  public void doSomethingObject(Object object) {  }
}

public class Usage {
  Doer doer = new Doer();
  public doSomething() {
    Foo anObject = new Foo();
    Bar bar = new Bar();

    doer.doSomethingFoo(anObject);
    doer.doSomethingObject(anObject);

    doer.doSomethingObject(bar);
  }
}
Run Code Online (Sandbox Code Playgroud)

由于两个doer.doSomethingFoo(anObject)doer.doSomethingObject(anObject)被称为,这两个声明,应搜索将返回.同样,doer.doSomethingObject(bar)不归还.当然,我不知道doer存在.

我正在尝试使用IntelliJ的结构搜索来执行此操作.我使用了以下模板$Instance$.$Method$($Parameter$),其中包含以下参数:

$Instance$  -> Text/regexp   = .*
$Method$    -> Text/regexp   = .*
$Parameter$ -> Text/regexp   = Foo
               Minimum count = 1     // Minimum one Foo parameter
               Maximum count = 1     // Maximum one Foo parameter
Run Code Online (Sandbox Code Playgroud)

这将返回具有命名参数的所有内容foo(不区分大小写,显然).所以我可能在这里做错了.但是什么?如何调用任何只有param类型的方法Foo

Bas*_*ers 2

你快到了。您现在需要做的就是将Expression type (regexp)$Parameter$ 设置为Foo并留空Text/regexp。此外,您可能还想启用该Apply constraint within type hierarchy复选框,以查找 Foo 的子类。

请注意,您可以将Text/regexp所有变量留空。这相当于.*.