void (@NotNull ActionContext context, @NotNull PsiNewExpression element, @NotNull ModPsiUpdater updater) { PsiNewExpression newExpression; PsiElementFactory factory = JavaPsiFacade.getElementFactory(element.getProject()); int caretOffset; TextRange selection; CommentTracker commentTracker = new CommentTracker(); if (myType instanceof PsiArrayType) { final PsiExpression[] originalExpressionArrayDimensions = element.getArrayDimensions(); caretOffset = 0; @NonNls StringBuilder text = new StringBuilder("new " + myType.getDeepComponentType().getCanonicalText() + "["); if (originalExpressionArrayDimensions.length > 0) { text.append(commentTracker.text(originalExpressionArrayDimensions[0])); } else { text.append("0"); caretOffset = -2; } text.append("]"); for (int i = 1; i < myType.getArrayDimensions(); i++) { text.append("["); if (originalExpressionArrayDimensions.length > i) { text.append(commentTracker.text(originalExpressionArrayDimensions[i])); } text.append("]"); if (caretOffset < 0) { caretOffset -= 2; } } newExpression = (PsiNewExpression)factory.createExpressionFromText(text.toString(), element); selection = caretOffset < 0 ? new UnfairTextRange(caretOffset, caretOffset + 1) : null; } else { final PsiAnonymousClass anonymousClass = element.getAnonymousClass(); newExpression = (PsiNewExpression)factory.createExpressionFromText("new " + myType.getCanonicalText() + "()" + (anonymousClass != null ? "{}" : ""), element); PsiExpressionList argumentList = element.getArgumentList(); if (argumentList != null) { final PsiExpressionList newArgumentList = newExpression.getArgumentList(); assert newArgumentList != null; newArgumentList.replace(commentTracker.markUnchanged(argumentList)); } if (anonymousClass != null) { PsiAnonymousClass newAnonymousClass = newExpression.getAnonymousClass(); assert newAnonymousClass != null; final PsiElement lBrace = anonymousClass.getLBrace(); assert lBrace != null; final PsiElement childInside = lBrace.getNextSibling(); if (childInside != null) { PsiElement element1 = childInside; do { commentTracker.markUnchanged(element1); } while ((element1 = element1.getNextSibling()) != null); final PsiElement rBrace = anonymousClass.getRBrace(); assert rBrace != null; newAnonymousClass.addRange(childInside, rBrace.getPrevSibling()); } } selection = null; caretOffset = -1; } newExpression = (PsiNewExpression)commentTracker.replaceAndRestoreComments(element, newExpression); if (PsiDiamondTypeUtil.canCollapseToDiamond(newExpression, newExpression, myType)) { final PsiJavaCodeReferenceElement reference = newExpression.getClassOrAnonymousClassReference(); assert reference != null; RemoveRedundantTypeArgumentsUtil.replaceExplicitWithDiamond(reference.getParameterList()); } if (selection != null) { selection = selection.shiftRight(newExpression.getTextRange().getEndOffset()); updater.select(selection); } updater.moveTo(newExpression.getTextRange().getEndOffset() + caretOffset); }