XPath find element based on ancestor element
- by martymcfly
Hi,
again I have Java AST which is created from
public class Test {
String o = new String("hh");
public void wrong1() {
synchronized(o) {
// huhu
}
}
}
I try to create a XPath query which finds the synchronized block in which the defined String variable o is used.
As the definition is above it is an ancestor of the SynchronizedStatement, but I dont get it working
//SynchronizedStatement[Expression/PrimaryExpression/PrimaryPrefix/Name[@Image=ancestor::ClassOrInterfaceBody[ClassOrInterfaceBodyDeclaration/FieldVariableDeclaratorId/@Image]]]
I know that /SynchronizedStatement[Expression/PrimaryExpression/PrimaryPrefix/Name[@Image= is correct, my problem is how to address the ancestor ClassOrInterfaceBody part.
Hope its clear what i mean ;-)
Thanks