I solved this by creating a for_updaters List (using node.updaters()
) and updating it every time i visit a for
loop (could also be nested loops
). Also, whenever i come across a PostfixExpression
(including for updaters
), i add it to another List, and then delete from this List all similar occurrences that appear in for_updaters List. This way i'm only left with non-for-updaters Postfixes. This also works for me because every time i visit a for
loop i clear both Lists, so no worries about duplicate variable names.
Note: node.updaters()
returns the exact full expression: [i++]
. But i only need i
. It's easy to extract it by converting the updater
to String
and then use substring()
.