简体   繁体   English

从Java中的行号中找出方法名称?

[英]Figure out method name from line number in Java?

Given a line number, the code file, as well as the compiled class file if necessary, what is the most elegant way to get the signature of the surrounding method (if the line number is even in a method)? 给定行号,代码文件以及必要时的已编译类文件,获取周围方法签名的最优雅方法是什么(如果行号在方法中是偶数)?

Things to keep in mind: 注意事项:

  • the line might not even be in a method 该行甚至可能不在方法中
  • the line might be in a method of an inner or anonymous class 该行可能在内部或匿名类的方法中

While Googling I discovered this duplicate question so I'm closing this down myself. 在谷歌搜索时,我发现了这个重复的问题,所以我自己将其关闭。

That information should be available from the debugger meta information generated by the compiler. 该信息应可从编译器生成的调试器元信息中获得。

javac -g:lines foo.java javac -g:lines foo.java

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM