void (@NotNull PsiElement element) { if (!(element instanceof PsiExpressionStatement statement)) { return; } final PsiExpressionStatement nextSibling = PsiTreeUtil.getNextSiblingOfType(statement, PsiExpressionStatement.class); if (nextSibling == null) { return; } final PsiExpression expression = statement.getExpression(); final StringBuilder newMethodCallExpression = new StringBuilder(expression.getText()); final PsiExpression expression1 = nextSibling.getExpression(); if (!(expression1 instanceof PsiMethodCallExpression)) { return; } PsiMethodCallExpression methodCallExpression = getRootMethodCallExpression((PsiMethodCallExpression)expression1); CommentTracker tracker = new CommentTracker(); while (true) { final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); tracker.markUnchanged(argumentList); final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final String methodName = methodExpression.getReferenceName(); newMethodCallExpression.append('.').append(methodName).append(argumentList.getText()); final PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodCallExpression.getParent()); final PsiElement grandParent = parent.getParent(); if (!(grandParent instanceof PsiMethodCallExpression)) { break; } methodCallExpression = (PsiMethodCallExpression)grandParent; } PsiReplacementUtil.replaceExpression(expression, newMethodCallExpression.toString()); tracker.deleteAndRestoreComments(nextSibling); }