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 = 0; int pi = 0; PsiParameter varargParam = targetMethod.isVarArgs() ? parameters[parameters.length - 1] : null; while (ei < expressions.length || pi < parameters.length) { if (!buf.isEmpty()) buf.append(", "); PsiExpression expression = ei < expressions.length ? expressions[ei] : null; PsiParameter parameter = pi < parameters.length ? 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(ParameterInfoImpl.create(pi).withName(parameter.getName()).withType(type)); buf.append(escapePresentableType(type)); pi++; ei++; } else if (isArgumentInVarargPosition(expressions, ei, varargParam, substitutor)) { if (pi == parameters.length - 1) { final PsiType type = varargParam.getType(); result.add(ParameterInfoImpl.create(pi).withName(varargParam.getName()).withType(type)); buf.append(escapePresentableType(type)); } pi++; ei++; } else if (expression != null) { if (varargParam != null && pi >= parameters.length) return false; if (PsiPolyExpressionUtil.isPolyExpression(expression)) return false; PsiType exprType = CommonJavaRefactoringUtil.getTypeByExpression(expression); if (exprType == null || PsiTypes.voidType().equals(exprType)) return false; if (exprType instanceof PsiDisjunctionType) { exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound(); } if (!PsiTypesUtil.allTypeParametersResolved(myTargetMethod, exprType)) 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(newParameterInfo); newParams.add(newParameterInfo); buf.append("<b>").append(escapePresentableType(exprType)).append("</b>"); ei++; } } if (result.size() != expressions.length && varargParam == null) return false; return true; }