Пример #1
0
        public static OverloadResult Merge(IEnumerable <OverloadResult> overloads)
        {
            overloads = overloads.ToArray();

            var name       = overloads.Select(o => o.Name).OrderByDescending(n => n?.Length ?? 0).FirstOrDefault();
            var doc        = overloads.Select(o => o.Documentation).OrderByDescending(n => n?.Length ?? 0).FirstOrDefault();
            var parameters = overloads.Select(o => o.Parameters).Aggregate(Array.Empty <ParameterResult>(), (all, pms) => {
                var res = all.Concat(pms.Skip(all.Length)).ToArray();

                for (int i = 0; i < res.Length; ++i)
                {
                    if (res[i] == null)
                    {
                        res[i] = pms[i];
                    }
                    else
                    {
                        var l  = res[i];
                        var r  = pms[i];
                        res[i] = new ParameterResult(
                            Longest(l.Name, r.Name),
                            Longest(l.Documentation, r.Documentation),
                            Merge(l.Type, r.Type),
                            l.IsOptional || r.IsOptional,
                            l.Variables?.Concat(r.Variables.MaybeEnumerate()).ToArray() ?? r.Variables,
                            Longest(l.DefaultValue, r.DefaultValue)
                            );
                    }
                }

                return(res);
            });

            return(new OverloadResult(parameters, name, doc));
        }
Пример #2
0
        private void EnsureParameters()
        {
            if (_parameters != null)
            {
                return;
            }

            if (_overload != null)
            {
                var             pinfo   = _overload.GetParameters();
                var             result  = new List <ParameterResult>(pinfo.Length + _extraParameters.Length);
                var             ignored = 0;
                ParameterResult kwDict  = null;
                foreach (var param in pinfo)
                {
                    if (ignored < _removedParams)
                    {
                        _selfParameter = GetParameterResultFromParameterInfo(param);
                        ignored++;
                    }
                    else
                    {
                        var paramResult = GetParameterResultFromParameterInfo(param);
                        if (param.IsKeywordDict)
                        {
                            kwDict = paramResult;
                        }
                        else
                        {
                            result.Add(paramResult);
                        }
                    }
                }

                result.InsertRange(0, _extraParameters);

                // always add kw dict last.  When defined in C# and combined w/ params
                // it has to come earlier than it's legally allowed in Python so we
                // move it to the end for intellisense purposes here.
                if (kwDict != null)
                {
                    result.Add(kwDict);
                }
                _parameters = result.ToArray();
            }
            else
            {
                _parameters = Array.Empty <ParameterResult>();
            }
        }
Пример #3
0
        public OverloadResult ToOverloadResult()
        {
            var parameters = new ParameterResult[_pnames.Length];

            for (var i = 0; i < parameters.Length; ++i)
            {
                if (string.IsNullOrEmpty(_pnames[i]))
                {
                    return(null);
                }

                parameters[i] = new ParameterResult(
                    _pnames[i],
                    null,
                    _ptypes[i],
                    false,
                    null,
                    _pdefaults[i]
                    );
            }
            return(new OverloadResult(parameters, _name, _doc, _rtypes));
        }
Пример #4
0
        public OverloadResult ToOverloadResult()
        {
            var parameters = new ParameterResult[_pnames.Length];

            for (int i = 0; i < parameters.Length; ++i)
            {
                if (string.IsNullOrEmpty(_pnames[i]))
                {
                    return(null);
                }

                parameters[i] = new ParameterResult(
                    _pnames[i],
                    null,
                    (_ptypes[i] == null || _ptypes[i].IsObjectOrUnknown()) ? null : string.Join(", ", _ptypes[i].GetShortDescriptions()),
                    false,
                    null,
                    _pdefaults[i]
                    );
            }
            return(new OverloadResult(parameters, _name, _doc, _rtypes));
        }
Пример #5
0
 public SimpleOverloadResult(ParameterResult[] parameters, string name, string documentation)
     : base(parameters, name)
 {
     _documentation = ParameterResult.Trim(documentation);
 }