@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
      PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
      PsiMethodCallExpression chainExpression = tryCast(element, PsiMethodCallExpression.class);
      if (chainExpression == null) return;
      PsiStatement chainStatement = PsiTreeUtil.getParentOfType(chainExpression, PsiStatement.class);
      if (chainStatement == null) return;
      List<Operation> operations = extractOperations(chainExpression, true);
      if (operations == null || operations.isEmpty()) return;
      OptionalToIfContext context = OptionalToIfContext.create(chainExpression);
      if (context == null) return;
      String code = generateCode(context, operations);
      if (code == null) return;
      code = context.addInitializer(code);
      PsiStatement firstStatement = chainStatement;
      PsiStatement[] statements = addStatements(factory, chainStatement, code);
      if (statements.length > 0) firstStatement = statements[0];
      List<Instruction> instructions = createInstructions(statements);
      if (instructions != null) {
        code = Simplifier.simplify(instructions);
        Arrays.stream(statements).forEach(PsiStatement::delete);
        statements = addStatements(factory, chainStatement, code);
        firstStatement = statements.length > 0 ? statements[0] : chainStatement;
      }
      CommentTracker tracker = new CommentTracker();
      tracker.grabComments(chainStatement);
      tracker.insertCommentsBefore(firstStatement);
      chainStatement.delete();
    }
@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater)