PsiVariable (PsiLoopStatement loop) { if (loop instanceof PsiForeachStatement foreachStatement) { return foreachStatement.getIterationParameter(); } if (loop instanceof PsiForStatement forStatement) { CountingLoop countingLoop = CountingLoop.from(forStatement); if (countingLoop != null) { return countingLoop.getCounter(); } } return null; }