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