boolean (PsiExpression[] expressions, PsiMethod targetMethod, PsiSubstitutor substitutor, StringBuilder buf, HashSet<? super ParameterInfoImpl> newParams, PsiParameter[] parameters, List<? super ParameterInfoImpl> result) { // find which parameters to introduce and where Set<String> existingNames = new HashSet<>(); for (PsiParameter parameter : parameters) { existingNames.add(parameter.getName()); } int ei = expressions.length - 1; int pi = parameters.length - 1; final PsiParameter varargParam = targetMethod.isVarArgs() ? parameters[parameters.length - 1] : null; final List<String> params = new ArrayList<>(); while (ei >= 0 || pi >= 0) { PsiExpression expression = ei >=0 ? expressions[ei] : null; PsiParameter parameter = pi >= 0 ? parameters[pi] : null; PsiType paramType = parameter == null ? null : substitutor.substitute(parameter.getType()); boolean parameterAssignable = paramType != null && (expression == null || TypeConversionUtil .areTypesAssignmentCompatible(paramType, expression)); if (parameterAssignable) { final PsiType type = parameter.getType(); result.add(0, ParameterInfoImpl.create(pi).withName(parameter.getName()).withType(type)); params.add(0, escapePresentableType(type)); pi--; ei--; } else if (isArgumentInVarargPosition(expressions, ei, varargParam, substitutor)) { if (pi == parameters.length - 1) { final PsiType type = varargParam.getType(); result.add(0, ParameterInfoImpl.create(pi).withName(varargParam.getName()).withType(type)); params.add(0, escapePresentableType(type)); } pi--; ei--; } else if (expression != null) { if (varargParam != null && pi >= parameters.length) return false; PsiType exprType = CommonJavaRefactoringUtil.getTypeByExpression(expression); if (exprType == null) return false; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject()); String name = suggestUniqueParameterName(codeStyleManager, expression, exprType, existingNames); final ParameterInfoImpl newParameterInfo = ParameterInfoImpl.createNew() .withName(name) .withType(exprType) .withDefaultValue(expression.getText().replace('\n', ' ')); result.add(0, newParameterInfo); newParams.add(newParameterInfo); params.add(0, "<b>" + escapePresentableType(exprType) + "</b>"); ei--; } } if (result.size() != expressions.length && varargParam == null) return false; buf.append(StringUtil.join(params, ", ")); return true; }