如何查找 Eclipse 中未评估函数 return 值的所有实例?

How to find all instances where function return value is not evaluated in Eclipse?

给定一个函数,该函数 return 是一个对象,例如Stringnull - 如何轻松找到代码中 return 值未分配给 String 变量(case1)或立即评估为条件的一部分 (case2)?

例如

public String getMessageInLog(String toFind) {
    // return String or null, depending on if found
}

String lineInLog = getMessageInLog("test"); // case1
Assert.assertNotNull(getMessageInLog("test"); // case2
Assert.assertNotNull("Failure error message", getMessageInLog("test"); // case2 (extended example - why searching for " getMessageInLog(" does not work.
getMessageInLog("test") // case3 - what I'm trying to find

这种类型的调用在测试中被使用了数千次,我想确定它的使用位置,就像在 case3 中一样。

执行正则表达式搜索 Eclipse, regular expression search and replace
$\s+getMessageInLog

您可以编写一个 Eclipse 插件,它能够

  1. 使用 SearchEngine.
  2. 查找对方法和 类 的引用
  3. 使用 JDT plugin(Java 开发工具)与 Java 编译器交互,为您找到的引用创建 AST。
  4. 稍微遍历 AST 以查看引用的使用方式(if 条件、赋值右侧或 stand-alone 语句)