@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
      if (!(element instanceof PsiExpression condition)) return;
      PsiReferenceExpression optionalRef = extractOptionalFromPresenceCheck(condition);
      if (optionalRef == null) return;
      PsiElement cond = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class, PsiConditionalExpression.class);
      PsiElement thenElement;
      PsiElement elseElement;
      boolean invert = isEmptyCheck(condition);
      if (cond instanceof PsiIfStatement ifStatement) {
        thenElement = extractThenStatement(ifStatement, invert);
        elseElement = extractElseStatement(ifStatement, invert);
      }
      else if (cond instanceof PsiConditionalExpression ternary) {
        thenElement = invert ? ternary.getElseExpression() : ternary.getThenExpression();
        elseElement = invert ? ternary.getThenExpression() : ternary.getElseExpression();
      }
      else {
        return;
      }
      if (myScenario.getProblemType(optionalRef, thenElement, elseElement) == ProblemType.NONE) {
        // Probably the code was modified
        return;
      }
      PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
      CommentTracker ct = new CommentTracker();
      String replacementText = myScenario.generateReplacement(factory, ct, optionalRef, thenElement, elseElement);
      if (thenElement != null && !PsiTreeUtil.isAncestor(cond, thenElement, true)) ct.delete(thenElement);
      if (elseElement != null && !PsiTreeUtil.isAncestor(cond, elseElement, true)) ct.delete(elseElement);
      PsiElement result = ct.replaceAndRestoreComments(cond, replacementText);
      LambdaCanBeMethodReferenceInspection.replaceAllLambdasWithMethodReferences(result);
      RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(result);
      CodeStyleManager.getInstance(project).reformat(result);
    }
@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater)