The visitIdentifier method visitIdentifier called in the Identifier notes in the AST, which are created when the identifier is used as an expression. However, the syntax for selecting a member in Java is <expression>.<identifier> , not <expression>.<expression> , which means that YYY in object.YYY not a sub-expression and therefore does not get its own subtree. Instead, MemberSelectTree for object.YYY just contains YYY as Name directly, accessible via getIdentifier() . There TreeScanner no TreeScanner method in visitName , so the only way to get to YYY here would be to do this directly from visitMemberSelect .
Here you can print object.YYY with visitMemberSelect :
Void visitMemberSelect(MemberSelectTree memberSelect, Void p) { // Print the object memberSelect.getExpression().accept(this, p); System.out.print("."); // Print the name of the member System.out.print(memberSelect.getIdentifier()); }
source share