PsiVariable (@NotNull PsiForStatement forStatement) { final PsiStatement initialization = forStatement.getInitialization(); if (!(initialization instanceof PsiDeclarationStatement)) { return null; } final PsiElement declaration = ((PsiDeclarationStatement)initialization).getDeclaredElements()[0]; if (!(declaration instanceof PsiVariable)) { return null; } return (PsiVariable)declaration; }