Let's say variable i is initialized like:
int i = 0;
I'm trying to detect simple java variable changes like:
i=i+1;
This can be done using a visitor pattern with JDT like:
public boolean visit(XXXXXXX node) {
//something here
}
However, I'm not sure of the name of XXXXX that will give me the statement in the second code example. I've looked through http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FASTNode.html but it is really big and so far I can't find it.
"i = i + 1" is an ExpressionStatement
(your XXXXXXX). The expression inside is of type Assignment
where you can check the operator, SimpleName
of the left hand side and the InfixExpression
on the right hand side.
A great tool to analize your code is the ASTView. It can show you the AST of any code marked in your editor. You can install it into Eclipse from the update site http://www.eclipse.org/jdt/ui/update-site