ASTParser 方法调用顺序
我正在使用 ASTParser 解析项目中的 java 源代码。我设法获得了我的java项目的不同类中所有方法的名称和返回类型。我现在想知道当我运行java项目时是否可以有方法调用的顺序。
事实上,我还没有阅读这个类的所有文档,这有点复杂。您知道它是否处理访问主程序中方法的顺序吗?如果是这样的话,你能给我一个简单的例子,或者给我我应该做什么的指导方针。 提前致谢
I'm using ASTParser to parse a java source code in a project . I managed to get the name and the return type of all the methods in the diffrent classes of my java project . I'm now wondering if it's possible to have the order of methods calls when I run the java project .
In fact I haven't read all the documentation for this class which is a bit complicated. Do you know if it handles the order of accessing the methods in the main program. if it's the case can you give me a simple example or give me the guide lines of what I should do.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个极其难解决的问题。
当您获取程序的 AST 时,您将获取有关程序结构的静态信息,而不是有关程序实际执行的动态信息。事实上,一般问题是“给定这个程序的源代码,它将进行什么顺序的方法调用?”是不可判定,这意味着没有任何算法,无论多么聪明,总能正确地得到这个问题的答案。
如果您仍然需要此信息,您有几种选择。首先,您可以尝试近似一系列方法调用,最终得到一个接近真实答案的答案,但不能正确涵盖所有情况。其次,您可以尝试运行程序并通过编写某种 JVM 插件(也许通过 JVMTI)来监视调用哪些函数。
This is actually an extremely hard problem to solve.
When you get the AST for a program, you are getting static information about the structure of the program, not dynamic information about the actual execution of the program. In fact, the general problem of "given the source code for this program, what sequence of method calls will it make?" is undecidable, meaning that no algorithm, no matter how clever, can always get the answer to this question correctly.
If you still need this information, you have a few options. First, you could try approximating the series of method calls, ending up with an answer that gives you something close to the true answer but which does not correctly cover all cases. Second, you could try running the program and monitor what functions get called by writing some sort of JVM plugin, perhaps through JVMTI.