//probably an iterator.
List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), line);
//look at the predecessor lines; validate there are only 2 predecessors.
if(predecessors.size() == 2) {
StatementIntermediate declaration = null;
for(AbstractIntermediate predecessor : predecessors) {
if(comparator.before(predecessor, line)) {
//should be declaration.
if(predecessor instanceof StatementIntermediate) {
declaration = (StatementIntermediate)predecessor;
break;
}
}
}
//check to see if the declaration is a temporary variable..
if(declaration == null) {
return;
}
//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())) {