public static boolean hasConflictingDeclaredNames(@NotNull PsiLocalVariable variable, @NotNull PsiInstanceOfExpression instanceOf) {
    PsiIdentifier identifier = variable.getNameIdentifier();
    if (identifier == null) {
      return false;
    }

    PsiElement scope = JavaSharedImplUtil.getPatternVariableDeclarationScope(instanceOf);
    if (scope == null) {
      return false;
    }
    boolean hasConflict = isConflictingNameDeclaredInside(variable, scope, false);
    if (hasConflict) {
      if (instanceOf.getPattern() != null) return true;
      final PsiElementFactory factory = JavaPsiFacade.getElementFactory(variable.getProject());
      PsiElement newExpression = factory.createExpressionFromText(instanceOf.getText() + " " + identifier.getText(), instanceOf);

      PsiFile file = variable.getContainingFile();
      if (file != instanceOf.getContainingFile()) {
        return true;
      }
      PsiFile copyFile = (PsiFile)file.copy();
      PsiInstanceOfExpression copyInstanceOf = PsiTreeUtil.findSameElementInCopy(instanceOf, copyFile);
      PsiLocalVariable copyVariable = PsiTreeUtil.findSameElementInCopy(variable, copyFile);
      copyVariable.delete();
      newExpression = copyInstanceOf.replace(newExpression);
      if (!(newExpression instanceof PsiInstanceOfExpression newInstanceOfExpression)) {
        return true;
      }
      if (!(newInstanceOfExpression.getPattern() instanceof PsiTypeTestPattern typeTestPattern)) {
        return true;
      }
      PsiPatternVariable patternVariable = typeTestPattern.getPatternVariable();
      if (patternVariable == null) {
        return true;
      }
      scope = JavaSharedImplUtil.getPatternVariableDeclarationScope(newInstanceOfExpression);
      if (scope == null) {
        return false;
      }
      return isConflictingNameDeclaredInside(patternVariable, scope, true);
    }
    return false;
  }
public static boolean hasConflictingDeclaredNames(@NotNull PsiLocalVariable variable, @NotNull PsiInstanceOfExpression instanceOf)