is there a way (and if so, how ?) to traverse a XPath query recursively ?
开发者_如何学GoI 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
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.
精彩评论