PsiLocalVariable (@Nullable PsiStatement statement) { PsiDeclarationStatement declarationStatement = tryCast(statement, PsiDeclarationStatement.class); if (declarationStatement == null) return null; PsiElement[] elements = declarationStatement.getDeclaredElements(); if (elements.length != 1) return null; return tryCast(elements[0], PsiLocalVariable.class); }