XPath find element based on ancestor element
Posted
by martymcfly
on Stack Overflow
See other posts from Stack Overflow
or by martymcfly
Published on 2010-03-25T12:59:05Z
Indexed on
2010/03/25
13:03 UTC
Read the original article
Hit count: 365
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
© Stack Overflow or respective owner