void (String arrayTypeText, int indexOfFirstVarargArgument, @NotNull PsiElement reference) { final PsiCall call = (PsiCall)(reference instanceof PsiCall ? reference : reference.getParent()); JavaResolveResult result = call.resolveMethodGenerics(); if (result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).getApplicabilityLevel() != MethodCandidateInfo.ApplicabilityLevel.VARARGS) { return; } final PsiExpressionList argumentList = call.getArgumentList(); if (argumentList == null) { return; } final PsiExpression[] arguments = argumentList.getExpressions(); @NonNls final StringBuilder builder = new StringBuilder("new ").append(arrayTypeText).append("[]{"); if (arguments.length > indexOfFirstVarargArgument) { final PsiExpression firstArgument = arguments[indexOfFirstVarargArgument]; builder.append(firstArgument.getText()); for (int i = indexOfFirstVarargArgument + 1; i < arguments.length; i++) { builder.append(',').append(arguments[i].getText()); } } builder.append('}'); final Project project = reference.getProject(); final PsiExpression arrayExpression = JavaPsiFacade.getElementFactory(project).createExpressionFromText(builder.toString(), reference); CommentTracker ct = new CommentTracker(); if (arguments.length > indexOfFirstVarargArgument) { PsiExpression firstArgument = arguments[indexOfFirstVarargArgument]; PsiExpression lastArgument = arguments[arguments.length - 1]; for (PsiElement e = firstArgument; e != lastArgument; e = e.getNextSibling()) { ct.grabComments(e); } argumentList.deleteChildRange(firstArgument, lastArgument); } argumentList.add(arrayExpression); ct.insertCommentsBefore(call); JavaCodeStyleManager.getInstance(project).shortenClassReferences(argumentList); CodeStyleManager.getInstance(project).reformat(argumentList); }