从行号方法名称 [英] Method name from line number

查看:163
本文介绍了从行号方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于特定类的源代码行数(Java / C#) - 有一种简单的方法来获得它属于内的方法的名称? (如果它属于一个之内)(据推测使用抽象语法树)

Given a line number of a particular class source code (Java/C#) - is there an easy way to get the name of the method it falls within? (If it falls within one) (Presumably using an Abstract Syntax Tree)

(这将是在限制的Checkstyle的输出,以只方法触及有用)。

(This would be useful in limiting the output of checkstyle to just the method touched).

我假设你必须使用一个抽象语法树做线路# - >方法名

I'm assuming you'd have to use an Abstract Syntax Tree to do Line#->MethodName.

推荐答案

(针对Java)

如果类文件与调试信息编译然后是行号表将包含一个映射代码< - >行号。我不认为有一个内置的用于获取这个在运行时API但我敢肯定,你也许可以做一些字节码工程库在那里,如ASM或BCEL的。

If the class file was compiled with debug info then the line number table will contain a mapping of code<->line number. I don't think there's a built-in API for getting at this at runtime though I'm sure you can probably do with with some of the bytecode engineering libs out there such as ASM or BCEL.

这篇关于从行号方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆