void (final PsiNewExpression arrayCreation) { PsiExpressionList argumentList = (PsiExpressionList)PsiUtil.skipParenthesizedExprUp(arrayCreation.getParent()); if (argumentList == null) return; PsiExpression[] args = argumentList.getExpressions(); PsiArrayInitializerExpression arrayInitializer = arrayCreation.getArrayInitializer(); try { if (arrayInitializer == null) { arrayCreation.delete(); return; } CommentTracker cm = new CommentTracker(); PsiExpression[] initializers = arrayInitializer.getInitializers(); if (initializers.length > 0) { PsiElement lastInitializerSibling = initializers[initializers.length - 1]; while (true) { final PsiElement nextSibling = lastInitializerSibling.getNextSibling(); if (nextSibling == null) { break; } if (PsiUtil.isJavaToken(nextSibling, JavaTokenType.RBRACE)) break; lastInitializerSibling = nextSibling; } if (lastInitializerSibling instanceof PsiWhiteSpace) { lastInitializerSibling = lastInitializerSibling.getPrevSibling(); } if (lastInitializerSibling instanceof PsiComment) { final PsiElement possibleComma = PsiTreeUtil.skipWhitespacesAndCommentsBackward(lastInitializerSibling); if (PsiUtil.isJavaToken(possibleComma, JavaTokenType.COMMA)) { possibleComma.delete(); } } else if (PsiUtil.isJavaToken(lastInitializerSibling, JavaTokenType.COMMA)) { lastInitializerSibling = lastInitializerSibling.getPrevSibling(); } PsiElement firstElement = initializers[0]; final PsiElement leadingComment = PsiTreeUtil.skipWhitespacesBackward(firstElement); if (leadingComment instanceof PsiComment) { firstElement = leadingComment; } argumentList.addRange(firstElement, lastInitializerSibling); cm.markRangeUnchanged(firstElement, lastInitializerSibling); } cm.deleteAndRestoreComments(args[args.length - 1]); } catch (IncorrectOperationException e) { LOG.error(e); } }