void (PsiStatement @NotNull [] statements, @Nullable PsiElement parent) { for (PsiStatement statement : statements) { if (statement instanceof PsiDeclarationStatement declarationStatement) { for (PsiElement declaration : declarationStatement.getDeclaredElements()) { if (declaration instanceof PsiVariable variable) { removeVariable(variable); } } } } if (parent instanceof PsiCatchSection catchSection) { removeVariable(catchSection.getParameter()); } else if (parent instanceof PsiForeachStatement forEach) { removeVariable(forEach.getIterationParameter()); } else if (parent instanceof PsiForStatement forStatement) { PsiStatement statement = forStatement.getInitialization(); if (statement instanceof PsiDeclarationStatement declarationStatement) { for (PsiElement declaration : declarationStatement.getDeclaredElements()) { if (declaration instanceof PsiVariable variable) { removeVariable(variable); } } } } else if (parent instanceof PsiTryStatement tryStatement) { PsiResourceList list = tryStatement.getResourceList(); if (list != null) { for (PsiResourceListElement resource : list) { if (resource instanceof PsiResourceVariable variable) { removeVariable(variable); } } } } }