void (@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) { PsiElement element = myIsTernary ? startElement : startElement.getParent(); final PsiElement result; if(element instanceof PsiIfStatement) { NotNullContext context = NotNullContext.from((PsiIfStatement)element); if (context == null) return; CommentTracker tracker = new CommentTracker(); PsiExpression expression = context.myExpressionToReplace; if(!context.myIsStream) { PsiExpression requireCall = createRequireExpression(tracker, expression, project, context.myReference, context.myDiff); context.myDiff.replace(requireCall); } else { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); String streamOfNullableText = CommonClassNames.JAVA_UTIL_STREAM_STREAM + ".ofNullable(" + context.myReference.getText() + ")"; PsiExpression streamOfNullable = factory.createExpressionFromText(streamOfNullableText, expression); expression.replace(streamOfNullable); } result = tracker.replaceAndRestoreComments(context.myIfStatement, context.myNullBranchStmt); if (context.myNextToDelete != null) { context.myNextToDelete.delete(); } } else if(element instanceof PsiConditionalExpression) { TernaryNotNullContext context = TernaryNotNullContext.from((PsiConditionalExpression)element); if(context == null) return; CommentTracker tracker = new CommentTracker(); PsiExpression requireCall = createRequireExpression(tracker, context.myNullExpr, project, context.myReferenceExpression, context.myNullExpr); result = tracker.replaceAndRestoreComments(context.myTernary, requireCall); } else return; LambdaCanBeMethodReferenceInspection.replaceAllLambdasWithMethodReferences(result); CodeStyleManager.getInstance(project).reformat(JavaCodeStyleManager.getInstance(project).shortenClassReferences(result)); }