如何递归遍历XPath?
有没有办法(如果有的话,如何?)递归地遍历 XPath 查询?
我在 Java 中有一个 AST,具有以下场景,
@Relevant
public void foo() {
bar(true);
}
public void bar(boolean flag) {
assert flag;
}
我想找到用“@Relevant”注释的方法(这很简单),并检查 foo(此处为 bar)中调用的方法是否有断言语句。
那么 a) 如何提取方法名称“bar”并通过 XPath 询问名为“bar”的方法?
如果 'bar' 实际上调用了发生断言的 'bla' 又会怎样呢?
希望这是可以理解的...
感谢您的帮助
is there a way (and if so, how ?) to traverse a XPath query recursively ?
I have an AST in Java with the following scenario
@Relevant
public void foo() {
bar(true);
}
public void bar(boolean flag) {
assert flag;
}
I want to find the method which is annotated with '@Relevant' (thats easy) and check if the method which is called in foo (here bar) does have an assert Statement.
So a) how do I extract the methode name 'bar' and ask via XPath for the method called 'bar' ?
and what if 'bar' actually calls 'bla' in which the assert happens ?
hope this is understandable...
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单个 Xpath 不足以完成您要完成的任务。
首先,您需要一个类型绑定(例如,用于查找 bar() 方法声明)。
其次,您需要开发某种静态代码分析器,它递归地在 AST 上运行并尝试满足一个条件,即调用堆栈中“存在断言表达式”。
您可以查看 Eclipse JDT 源代码,了解其中如何实现类型绑定。一旦有了绑定,您就可以在其上调用逻辑。
A single Xpath is not sufficient for the task you're trying to accomplish.
First, you need a type binding (for finding a bar() method declaration, for example).
Second, you need to develop some kind of static code analyzer, which runs on ASTs recursively and tries to satisfy a condition, which is "an assert expression exists" in a call stack.
You may have a look at the Eclipse JDT source code for how type binding is implemented there. Once you have a binding, you can invoke your logic on it.