void (@NotNull Project project, @NotNull PsiElement psiElement, @NotNull ModPsiUpdater updater) { if (myInfo instanceof ReplaceInfo.NotAvailableReplaceInfo) { return; } if (!(psiElement.getParent() instanceof PsiReferenceExpression referenceExpression)) { return; } PsiElement parent = referenceExpression.getParent(); if (!(parent instanceof PsiMethodCallExpression callExpression)) { return; } PsiExpression qualifierExpression = referenceExpression.getQualifierExpression(); if (qualifierExpression == null) { return; } PsiExpression[] expressions = callExpression.getArgumentList().getExpressions(); if (expressions.length != 1) { return; } PsiExpression argument = expressions[0]; if (argument == null) { return; } StringBuilder builder = new StringBuilder(); CommentTracker ct = new CommentTracker(); if (myInfo instanceof ReplaceInfo.SimpleReplaceInfo simpleReplaceInfo) { fillSimple(simpleReplaceInfo, argument, qualifierExpression, builder, ct); } if (myInfo instanceof ReplaceInfo.ComplexReplaceInfo complexReplaceInfo) { complexReplaceInfo.fill(argument, qualifierExpression, builder, ct); } if (builder.isEmpty()) { return; } PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiExpression newExpression = factory.createExpressionFromText(builder.toString(), callExpression); PsiElement callParent = callExpression.getParent(); if (callParent instanceof PsiExpression && ParenthesesUtils.areParenthesesNeeded(newExpression, (PsiExpression)callParent, true)) { newExpression = factory.createExpressionFromText("(" + newExpression.getText() + ")", callExpression); } PsiElement replaced = ct.replaceAndRestoreComments(callExpression, newExpression); final CodeStyleManager styleManager = CodeStyleManager.getInstance(project); styleManager.reformat(replaced); }