void (@NotNull PsiElement element) { final PsiCall call = PsiTreeUtil.getParentOfType(element, PsiCall.class); if (call == null) { return; } final PsiMethod method = call.resolveMethod(); if (method == null) { return; } final PsiParameterList parameterList = method.getParameterList(); final int parametersCount = parameterList.getParametersCount(); final PsiExpressionList argumentList = call.getArgumentList(); if (argumentList == null) { return; } final PsiExpression[] arguments = argumentList.getExpressions(); final StringBuilder newExpressionText = new StringBuilder("new "); final PsiParameter[] parameters = parameterList.getParameters(); final int varargParameterIndex = parametersCount - 1; final PsiType componentType = PsiTypesUtil.getParameterType(parameters, varargParameterIndex, true); final JavaResolveResult resolveResult = call.resolveMethodGenerics(); final PsiSubstitutor substitutor = resolveResult.getSubstitutor(); PsiType type = substitutor.substitute(componentType); if (type instanceof PsiCapturedWildcardType) { type = ((PsiCapturedWildcardType)type).getLowerBound(); } newExpressionText.append(JavaGenericsUtil.isReifiableType(type) ? type.getCanonicalText() : TypeConversionUtil.erasure(type).getCanonicalText()); newExpressionText.append("[]{"); if (arguments.length > varargParameterIndex) { final PsiExpression argument1 = arguments[varargParameterIndex]; argument1.delete(); newExpressionText.append(argument1.getText()); for (int i = parametersCount; i < arguments.length; i++) { final PsiExpression argument = arguments[i]; newExpressionText.append(',').append(argument.getText()); argument.delete(); } } newExpressionText.append("}"); final Project project = element.getProject(); final PsiExpression newExpression = JavaPsiFacade.getElementFactory(project).createExpressionFromText(newExpressionText.toString(), element); CodeStyleManager.getInstance(project).reformat(argumentList.add(newExpression)); }