boolean (PsiForStatement forStatement) { final PsiStatement initialization = forStatement.getInitialization(); if (!(initialization instanceof PsiDeclarationStatement declaration)) { return false; } final PsiElement[] declaredElements = declaration.getDeclaredElements(); final PsiElement secondDeclaredElement; if (declaredElements.length == 1) { secondDeclaredElement = null; } else if (declaredElements.length == 2) { secondDeclaredElement = declaredElements[1]; } else { return false; } final PsiElement declaredElement = declaredElements[0]; if (!(declaredElement instanceof PsiVariable indexVariable)) { return false; } final PsiExpression initialValue = indexVariable.getInitializer(); final Object constant = ExpressionUtils.computeConstantExpression(initialValue); if (!(constant instanceof Integer integer)) { return false; } if (integer.intValue() != 0) { return false; } final PsiStatement update = forStatement.getUpdate(); if (!VariableAccessUtils.variableIsIncremented(indexVariable, update)) { return false; } final PsiExpression condition = forStatement.getCondition(); final PsiReferenceExpression arrayReference = getVariableReferenceFromCondition(condition, indexVariable, secondDeclaredElement); if (arrayReference == null) { return false; } if (!(arrayReference.getType() instanceof PsiArrayType)) { return false; } final PsiElement element = arrayReference.resolve(); if (!(element instanceof PsiVariable arrayVariable)) { return false; } final PsiStatement body = forStatement.getBody(); return body == null || isIndexVariableOnlyUsedAsIndex(arrayVariable, indexVariable, body) && !VariableAccessUtils.variableIsAssigned(arrayVariable, body) && !VariableAccessUtils.arrayContentsAreAssigned(arrayVariable, body) && !arrayMayBeChangedBeforeLoop(arrayVariable, arrayReference, forStatement); }