//otherwise, let's see if the declaration is an iterator.
if(declaration.getExpression() instanceof Declaration) {
Declaration declarationExpression = (Declaration)declaration.getExpression();
Variable v = (Variable)declarationExpression.getAssignment().getLeftHandSide();
//check to see if the declaration is the same as the iterator's name.
if(StringUtils.equals(iteratorName, v.getName())) {
LOG.debug("Identified Likely Iterator: "+v.getName());
//get the ".next()" statement, which should be the first child.
AbstractIntermediate firstChild = igc.getTrueTarget(line);
//see if this is a statement, if the statement is an assignment...
//then check the right side to see if it is an invocation.. and the invocation has the method name "next"...
if(firstChild instanceof StatementIntermediate) {
StatementIntermediate nextStatement = (StatementIntermediate)firstChild;
if(nextStatement.getExpression() instanceof Declaration) {
//the statement is indeed a declaration.
Declaration nextDeclaration = (Declaration)nextStatement.getExpression();
if(nextDeclaration.getAssignment().getRightHandSide() instanceof MethodInvocation) {
MethodInvocation nextMethodInvocation = (MethodInvocation)nextDeclaration.getAssignment().getRightHandSide();
if(StringUtils.equals("next", nextMethodInvocation.getMethodName())) {
//YES.
//check to see if the next method is on the candidate iterator.
if(nextMethodInvocation.getTarget() instanceof Variable) {
Variable nextMethodTarget = (Variable)nextMethodInvocation.getTarget();
if(StringUtils.equals(iteratorName, nextMethodTarget.getName())) {
LOG.info("Definitely an enhanced for loop.");
if(declarationExpression.getAssignment().getRightHandSide() instanceof MethodInvocation) {
MethodInvocation iteratorInvocation = (MethodInvocation)declarationExpression.getAssignment().getRightHandSide();