boolean (@NotNull PsiExpression expression, @NotNull PsiForStatement statement, @Nullable Object defaultValue) { PsiReferenceExpression arrayRef = tryCast(PsiUtil.skipParenthesizedExprDown(expression), PsiReferenceExpression.class); if (arrayRef == null) return false; PsiVariable arrayVar = tryCast(arrayRef.resolve(), PsiVariable.class); if (arrayVar == null) return false; PsiCodeBlock block = tryCast(PsiUtil.getVariableCodeBlock(arrayVar, null), PsiCodeBlock.class); if (block == null) return false; ControlFlow flow = createControlFlow(block); if (flow == null) return false; int statementStart = flow.getStartOffset(statement); if (statementStart == -1) return false; int statementEnd = flow.getEndOffset(statement); if (statementEnd == -1) return false; PsiElement[] defs = getDefs(block, arrayVar, arrayRef, defaultValue); if (defs == null) return false; Set<Integer> exclude = getDefsOffsets(flow, defs); if (exclude == null) return false; for (int i = statementStart; i < statementEnd; i++) { exclude.add(i); } return !ContainerUtil.exists(defs, def -> ControlFlowUtils.isVariableReferencedBeforeStatementEntry(flow, flow.getEndOffset(def) + 1, statement, arrayVar, exclude)); }