If this isn't the correct forum and audience for AST-related questions, please pardon the intrusion.
I need to write a one-off ditty to parse a large set of java source files searching for assignment or comparison operation on arrays (not individual array elements).
I've read several howto's and well-written articles that provided sufficient fodder that I got close to my target - but no dice. Could use some help.
I'm thinking that it could all be done with two visitors - one for Assignment and the other, IfStatement. My conundrum lies in my ability (or lack thereof) to intuit the API and the DOM structure.
For instance, in the following snippet, how do I ascertain whether or not Expression left is an array (from within this Assignment visitor)?
public boolean visit(Assignment node) {
Expression left = node.getLeftHandSide();
if (left instanceof QualifiedName)
System.err.println(((QualifiedName) left).getFullyQualifiedName());
else if (left instanceof SimpleName) {
System.err.println(((SimpleName) left).getIdentifier());
}
Same of IfStatement. How do I relate the InfixExpression.getLeftOperand() to it's data type and identify whether or not it's an array.
You might want to check the methods
org.eclipse.jdt.core.dom.ASTParser.setEnvironment(String[], String[], String[], boolean) and org.eclipse.jdt.core.dom.ASTParser.setUnitName(String)
You need to provide the required classpath entries so that the bindings can be resolved. This is explained in the javadoc of the org.eclipse.jdt.core.dom.ASTParser.setResolveBindings(boolean) method.