Browse Source

[TypeSystem] All attributes from partial method declarations are now

merged.
newNRvisualizers
Mike Krüger 14 years ago
parent
commit
7a3e68fb1d
  1. 2
      ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs
  2. 122
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs
  3. 11
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs

2
ICSharpCode.NRefactory/TypeSystem/Implementation/AbstractResolvedEntity.cs

@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return parentContext.CurrentAssembly; }
}
public IList<IAttribute> Attributes { get; private set; }
public IList<IAttribute> Attributes { get; protected set; }
public virtual DocumentationComment Documentation {
get {

122
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedMethod.cs

@ -43,11 +43,127 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -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<T> : IList<T>
{
List<IList<T>> lists =new List<IList<T>> ();
public void AddList(IList<T> list)
{
lists.Add (list);
}
#region IEnumerable implementation
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region IEnumerable implementation
public IEnumerator<T> 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<T>.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<T>.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 <IAttribute>();
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;
}

11
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultResolvedTypeDefinition.cs

@ -161,7 +161,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -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 @@ -250,15 +250,15 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public readonly int TypeParameterCount;
public readonly IList<IParameter> Parameters;
public readonly List<IUnresolvedMethod> Parts = new List<IUnresolvedMethod>();
public ITypeResolveContext PrimaryContext;
public readonly List<ITypeResolveContext> Contexts = new List<ITypeResolveContext>();
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 @@ -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);
}
}

Loading…
Cancel
Save