internal static string MakeDescription(AnalysisValue type, string typeName, IAnalysisSet indexTypes) { if (type.Push()) { try { if (indexTypes == null || indexTypes.Count == 0) { return(typeName); } else if (indexTypes.Count == 1) { return(typeName + " of " + indexTypes.First().ShortDescription); } else if (indexTypes.Count < 4) { return(typeName + " of {" + string.Join(", ", indexTypes.Select(ns => ns.ShortDescription)) + "}"); } else { return(typeName + " of multiple types"); } } finally { type.Pop(); } } return(typeName); }
private IAnalysisSet UrlProcessor(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { // No completion if the url has no name (reverse matching not possible) if (keywordArgNames.Length == 0) { return(AnalysisSet.Empty); } IAnalysisSet urlNames = GetArg(args, keywordArgNames, "name", -1); if (urlNames == null) // The kwargs do not contain a name arg { return(AnalysisSet.Empty); } string urlName = urlNames.First().GetConstantValueAsString(); string urlRegex = args.First().First().GetConstantValueAsString(); if (urlName != null && urlRegex != null) { _urls.Add(new DjangoUrl(urlName, urlRegex)); } return(AnalysisSet.Empty); }
/// <summary> /// Removes excess capacity from <paramref name="set"/>. /// </summary> public static IAnalysisSet Trim(this IAnalysisSet set) { if (set is AnalysisSetDetails.AnalysisHashSet) { switch (set.Count) { case 0: if (set.Comparer is UnionComparer) { return(AnalysisSetDetails.AnalysisSetEmptyUnion.Instances[((UnionComparer)set.Comparer).Strength]); } return(Empty); case 1: if (set.Comparer is UnionComparer) { return(new AnalysisSetDetails.AnalysisSetOneUnion(set.First(), (UnionComparer)set.Comparer)); } return(set.First()); case 2: if (set.Comparer is UnionComparer) { var tup = AnalysisSetDetails.AnalysisSetTwoUnion.FromEnumerable(set, (UnionComparer)set.Comparer); if (tup == null) { return(set); } else if (tup.Item1 == null && tup.Item2 == null) { return(AnalysisSetDetails.AnalysisSetEmptyUnion.Instances[((UnionComparer)set.Comparer).Strength]); } else if (tup.Item2 == null) { return(new AnalysisSetDetails.AnalysisSetOneUnion(tup.Item1, (UnionComparer)set.Comparer)); } else { return(new AnalysisSetDetails.AnalysisSetTwoUnion(tup.Item1, tup.Item2, (UnionComparer)set.Comparer)); } } return(new AnalysisSetDetails.AnalysisSetTwoObject(set)); } } return(set); }
private object GenerateTypeName(IAnalysisSet name, bool isRef) { if (name.Count == 0) { return(null); } else if (name.Count == 1) { return(GenerateTypeName(name.First(), isRef)); } return(name.Select(ns => GenerateTypeName(ns, isRef)).Distinct().ToList <object>()); }
internal override IPropertyDescriptor GetProperty(Node node, AnalysisUnit unit, string name) { if (_prototypes.Count == 0) { return(null); } else if (_prototypes.Count == 1) { return(_prototypes.First().Value.GetProperty(node, unit, name)); } return(new MergedPropertyDescriptor(this, name)); }
private object GetMemberValue(IAnalysisSet types, ModuleInfo declModule, bool isRef) { if (types.Count == 1) { var type = types.First(); var res = GetMemberValueInternal(type, declModule, isRef); if (res == null) { _errors.Add(String.Format("Cannot save single member: {0}", types.First())); } return(res); } else if (types.Count == 0) { return(new Dictionary <string, object>() { { "type", null } }); } else { List <object> res = new List <object>(); foreach (var type in types) { res.Add( new Dictionary <string, object>() { { "kind", GetMemberKind(type, declModule, isRef) }, { "value", GetMemberValueInternal(type, declModule, isRef) } } ); } return(new Dictionary <string, object>() { { "members", res.ToArray() } }); } }
bool IAnalysisSet.SetEquals(IAnalysisSet other) { if (other.Count != 1) { return(false); } var av = other as AnalysisValue; if (av != null) { return(((IAnalysisSet)this).Comparer.Equals(this, av)); } return(((IAnalysisSet)this).Comparer.Equals(this, other.First())); }
protected string MakeDescription(string typeName) { if (_indexTypes == null || _indexTypes.Count == 0) { return(typeName); } else if (_indexTypes.Count == 1) { return(typeName + " of " + GetInstanceShortDescription(_indexTypes.First())); } else if (_indexTypes.Count < 4) { return(typeName + " of {" + string.Join(", ", _indexTypes.Select(GetInstanceShortDescription)) + "}"); } else { return(typeName + " of multiple types"); } }
/// <summary> /// Returns true if the set contains no or only the object type /// </summary> internal static bool IsObjectOrUnknown(this IAnalysisSet res) { return(res.Count == 0 || (res.Count == 1 && res.First().Value.TypeId == BuiltinTypeId.Object)); }
internal static string MakeDescription(AnalysisValue type, string typeName, IAnalysisSet indexTypes) { if (type.Push()) { try { if (indexTypes == null || indexTypes.Count == 0) { return typeName; } else if (indexTypes.Count == 1) { return typeName + " of " + indexTypes.First().ShortDescription; } else if (indexTypes.Count < 4) { return typeName + " of {" + string.Join(", ", indexTypes.Select(ns => ns.ShortDescription)) + "}"; } else { return typeName + " of multiple types"; } } finally { type.Pop(); } } return typeName; }
private IAnalysisSet UrlProcessor(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames) { // No completion if the url has no name (reverse matching not possible) if (keywordArgNames.Length == 0) { return AnalysisSet.Empty; } IAnalysisSet urlNames = GetArg(args, keywordArgNames, "name", -1); if (urlNames == null) { // The kwargs do not contain a name arg return AnalysisSet.Empty; } string urlName = urlNames.First().GetConstantValueAsString(); string urlRegex = args.First().First().GetConstantValueAsString(); _urls.Add(new DjangoUrl(urlName, urlRegex)); return AnalysisSet.Empty; }