0

I need to search for a string (actually a method call) in a java file. I also need to know where it was called (I mean in which method in the java file). What is the best approach?

4

2 回答 2

1

反射实际上只能告诉您给定 Java 对象存在哪些方法和字段。到 JVM 运行时,Java 源代码已经编译为字节码,在源文件中“搜索字符串”是没有意义的。

我认为最好的办法就是像普通文本文件一样解析它。

于 2012-05-16T13:48:35.827 回答
-1
class Test {
   void doTest(){
    // do test
   }

   public static void main(String[] args){
      for (Method each : Test.class.getMethods()){
         System.out.println(each.getName() + "()");
      }
   }
}

将返回:“doTest()”

于 2012-05-16T14:04:11.703 回答