diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs index 41aecbf9c8..411b102929 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation get { return parentContext.CurrentAssembly; } } - public IList Attributes { get; private set; } + public IList Attributes { get; protected set; } public virtual DocumentationComment Documentation { get { diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs index 09b6aee345..c87f858ceb 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs @@ -43,11 +43,127 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation this.TypeParameters = unresolved.TypeParameters.CreateResolvedTypeParameters(context); this.IsExtensionMethod = isExtensionMethod; } - - public static DefaultResolvedMethod CreateFromMultipleParts(IUnresolvedMethod[] parts, ITypeResolveContext firstPartParentContext, bool isExtensionMethod) + + class ListOfLists : IList + { + List> lists =new List> (); + + public void AddList(IList list) + { + lists.Add (list); + } + + #region IEnumerable implementation + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + #endregion + + #region IEnumerable implementation + public IEnumerator GetEnumerator () + { + for (int i = 0; i < this.Count; i++) { + yield return this[i]; + } + } + #endregion + + #region ICollection implementation + public void Add (T item) + { + throw new NotSupportedException(); + } + + public void Clear () + { + throw new NotSupportedException(); + } + + public bool Contains (T item) + { + var comparer = EqualityComparer.Default; + for (int i = 0; i < this.Count; i++) { + if (comparer.Equals(this[i], item)) + return true; + } + return false; + } + + public void CopyTo (T[] array, int arrayIndex) + { + for (int i = 0; i < Count; i++) { + array[arrayIndex + i] = this[i]; + } + } + + public bool Remove (T item) + { + throw new NotSupportedException(); + } + + public int Count { + get { + return lists.Sum (l => l.Count); + } + } + + public bool IsReadOnly { + get { + return true; + } + } + #endregion + + #region IList implementation + public int IndexOf (T item) + { + var comparer = EqualityComparer.Default; + for (int i = 0; i < this.Count; i++) { + if (comparer.Equals(this[i], item)) + return i; + } + return -1; + } + + public void Insert (int index, T item) + { + throw new NotSupportedException(); + } + + public void RemoveAt (int index) + { + throw new NotSupportedException(); + } + + public T this[int index] { + get { + foreach (var list in lists){ + if (index < list.Count) + return list[index]; + index -= list.Count; + } + throw new IndexOutOfRangeException (); + } + set { + throw new NotSupportedException(); + } + } + #endregion + } + + public static DefaultResolvedMethod CreateFromMultipleParts(IUnresolvedMethod[] parts, ITypeResolveContext[] contexts, bool isExtensionMethod) { - DefaultResolvedMethod method = new DefaultResolvedMethod(parts[0], firstPartParentContext, isExtensionMethod); + DefaultResolvedMethod method = new DefaultResolvedMethod(parts[0], contexts[0], isExtensionMethod); method.parts = parts; + if (parts.Length > 1) { + var attrs = new ListOfLists (); + attrs.AddList (method.Attributes); + for (int i = 1; i < parts.Length; i++) { + attrs.AddList (parts[i].Attributes.CreateResolvedAttributes(contexts[i])); + } + method.Attributes = attrs; + } return method; } diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs index d0087a010b..068a5f7822 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs @@ -161,7 +161,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation var info = partialMethodInfos[i]; int memberIndex = NonPartialMemberCount + i; resolvedMembers[memberIndex] = DefaultResolvedMethod.CreateFromMultipleParts( - info.Parts.ToArray(), info.PrimaryContext, false); + info.Parts.ToArray(), info.Contexts.ToArray (), false); } } } @@ -250,15 +250,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation public readonly int TypeParameterCount; public readonly IList Parameters; public readonly List Parts = new List(); - public ITypeResolveContext PrimaryContext; - + public readonly List Contexts = new List(); + public PartialMethodInfo(IUnresolvedMethod method, ITypeResolveContext context) { this.Name = method.Name; this.TypeParameterCount = method.TypeParameters.Count; this.Parameters = method.Parameters.CreateResolvedParameters(context); this.Parts.Add(method); - this.PrimaryContext = context; + this.Contexts.Add (context); } public void AddPart(IUnresolvedMethod method, ITypeResolveContext context) @@ -266,9 +266,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation if (method.IsPartialMethodImplementation) { // make the implementation the primary part this.Parts.Insert(0, method); - this.PrimaryContext = context; + this.Contexts.Insert (0, context); } else { this.Parts.Add(method); + this.Contexts.Add (context); } }