在java方法中获取return语句

ibe*_*rck 4 java

如何在java中获取方法的所有可能返回值?

例:

Object onEvent() {
 if (condition) {
     return "a";
 }

 if (condition2) {
    return "b";
 }

 if (condition3) {
     return "c";
 } 

}
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西:

String[] returns = Utils.getReturnStatements("object.onEvent()");
returns = ["a", "b", "c"]
Run Code Online (Sandbox Code Playgroud)

Joh*_*erg 5

只能检索方法签名,在这种情况下,它将Object作为返回类型.

要获得更多详细信息,您需要静态分析源代码或返回类型等enum.

  • @iberck,http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis (2认同)