All three Primaryprefix PrimarySuffix and PrimaySuffix falls under PrimaryExpression at same level I want to retrieve the node primarySuffix whose value is equals .
I tried retrieving the value with below line of code but its not working. I'm always getting null.
ASTPrimarySuffix suffixValue = (ASTPrimarySuffix) primaryExpression.getFirstChildOfType(ASTPrimarySuffix.class);
Last edit: Andreas Dangel 2014-03-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While writing the rule I got stuck at a level where I'm unable to retrieve the value of ASTPrimarySuffix node. Can someone respond to this ASAP.
This is how the tree looks like in PMD.
All three Primaryprefix PrimarySuffix and PrimaySuffix falls under PrimaryExpression at same level I want to retrieve the node primarySuffix whose value is equals .
I tried retrieving the value with below line of code but its not working. I'm always getting null.
ASTPrimarySuffix suffixValue = (ASTPrimarySuffix) primaryExpression.getFirstChildOfType(ASTPrimarySuffix.class);
Last edit: Andreas Dangel 2014-03-30
attaching screenshot
I assume, you want the second ASTPrimarySuffix node, whose
image
happen to beequals
. Is this correct?In your code example, you'll get the first suffix node, which is the wrong node. You would need to use the second node.
In this case, you can call
findChildrenOfType(ASTPrimarySuffix.class)
which will return a list of all suffix nodes:You could also iterate through the list, to search for the
equals
call:Hope this helps.