@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
      PsiTypeCastExpression castExpression = PsiTreeUtil.getParentOfType(element, false, PsiTypeCastExpression.class);
      if (castExpression == null) return;
      PsiTypeElement originalTypeElement = castExpression.getCastType();
      if (originalTypeElement == null) return;
      PsiInstanceOfExpression originalInstanceOf = myInstanceOfPointer.getElement();
      if (originalInstanceOf == null) return;
      PsiInstanceOfExpression instanceOf = PsiTreeUtil.findSameElementInCopy(originalInstanceOf, element.getContainingFile());
      if (instanceOf.getPattern() instanceof PsiDeconstructionPattern) return;
      PsiTypeElement instanceOfType = instanceOf.getCheckType();
      PsiTypeElement typeElement = originalTypeElement;
      if (instanceOfType != null && instanceOfType.getType() instanceof PsiClassType classType && !classType.isRaw()) {
        typeElement = instanceOfType;
      }
      PsiIfStatement psiIfStatement = PsiTreeUtil.getParentOfType(instanceOf, PsiIfStatement.class);
      if (psiIfStatement == null || psiIfStatement.getParent() == null) return;
      var visitor = new JavaRecursiveElementVisitor() {
        final List<PsiTypeCastExpression> myCasts = new ArrayList<>();

        @Override
        public void visitTypeCastExpression(@NotNull PsiTypeCastExpression expression) {
          PsiTypeElement castType = expression.getCastType();
          if (castType == null) return;
          if (!castType.textMatches(originalTypeElement)) {
            return;
          }
          InstanceOfCandidateResult result = findInstanceOfCandidateResult(expression);
          if (result != null && result.instanceOf == instanceOf) {
            myCasts.add(expression);
          }
        }
      };

      psiIfStatement.getParent().accept(visitor);
      List<PsiTypeCastExpression> casts = visitor.myCasts;
      if (casts.isEmpty()) return;

      CommentTracker ct = new CommentTracker();
      StringBuilder text = generateTextForInstanceOf(null, ct, instanceOf, typeElement);
      if (text == null) return;
      PsiElement replaced = ct.replace(instanceOf, text.toString());
      if (!(replaced instanceof PsiInstanceOfExpression instanceOfExpression)) {
        return;
      }
      PsiPrimaryPattern pattern = instanceOfExpression.getPattern();
      if (!(pattern instanceof PsiTypeTestPattern typeTestPattern)) {
        return;
      }
      PsiPatternVariable patternVariable = typeTestPattern.getPatternVariable();
      if (patternVariable == null) return;
      String variableName = patternVariable.getName();
      for (PsiTypeCastExpression cast : casts) {
        PsiElement currentCast = cast;
        CommentTracker castCt = new CommentTracker();
        while (currentCast.getParent() instanceof PsiParenthesizedExpression parenthesizedExpression) {
          currentCast = parenthesizedExpression;
        }
        castCt.replace(currentCast, variableName);
      }
      final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
      List<String> names = new VariableNameGenerator(instanceOfExpression, VariableKind.LOCAL_VARIABLE)
        .byType(patternVariable.getType()).byName(
          codeStyleManager.suggestUniqueVariableName(variableName, instanceOfExpression, true)).generateAll(true);
      names.remove(patternVariable.getName());
      updater.rename(patternVariable, names);
    }
@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater)