boolean (PsiForStatement forStatement) { final PsiStatement initialization = forStatement.getInitialization(); if (!(initialization instanceof PsiDeclarationStatement declaration)) { return false; } final PsiElement[] declaredElements = declaration.getDeclaredElements(); final PsiExpression condition = forStatement.getCondition(); for (PsiElement declaredElement : declaredElements) { if (!(declaredElement instanceof PsiVariable variable)) { continue; } if (TypeUtils.variableHasTypeOrSubtype(variable, "java.util.ListIterator")) { if (isHasNext(condition, variable) || isHasPrevious(condition, variable)) { return true; } } if (TypeUtils.variableHasTypeOrSubtype(variable, CommonClassNames.JAVA_UTIL_ITERATOR)) { if (isHasNext(condition, variable)) { return true; } } else if (TypeUtils.variableHasTypeOrSubtype(variable, "java.util.Enumeration")) { if (isHasMoreElements(condition, variable)) { return true; } } } return false; }