[mdoc] Added -api-style parameter.
[mono.git] / mcs / tools / mdoc / Mono.Documentation / exceptions.cs
index ad1ba9d76ae832a258c585cd8964d6e9761301b0..5919870876ca773db4ebbb255220415b927870c5 100644 (file)
@@ -47,13 +47,11 @@ namespace Mono.Documentation {
                internal ExceptionSources (TypeReference exception)
                {
                        Exception = exception;
-                       SourcesList = new List<IMemberReference> ();
-                       Sources = new ReadOnlyCollection<IMemberReference> (SourcesList);
+                       Sources   = new HashSet<MemberReference> ();
                }
 
                public TypeReference Exception { get; private set; }
-               public ReadOnlyCollection<IMemberReference> Sources { get; private set; }
-               internal List<IMemberReference> SourcesList;
+               internal  HashSet<MemberReference>  Sources;
        }
 
 
@@ -72,11 +70,11 @@ namespace Mono.Documentation {
                        this.locations = locations;
                }
 
-               public IEnumerable<ExceptionSources> this [IMemberReference member] {
+               public IEnumerable<ExceptionSources> this [MemberReference member] {
                        get {
                                if (member == null)
                                        throw new ArgumentNullException ("member");
-                               IMemberReference memberDef = member.Resolve ();
+                               MemberReference memberDef = member.Resolve ();
                                if (memberDef == null) {
                                        ArrayType array = member.DeclaringType as ArrayType;
                                        if (array != null && array.Rank > 1) {
@@ -93,25 +91,25 @@ namespace Mono.Documentation {
                                Dictionary<string, ExceptionSources> e;
                                if (!db.TryGetValue (memberDecl, out e)) {
                                        e = new Dictionary<string, ExceptionSources> ();
+                                       db.Add (memberDecl, e);
                                        var bodies = GetMethodBodies (member);
                                        foreach (var body in bodies) {
                                                if (body == null)
                                                        continue;
                                                FillExceptions (body, e);
                                        }
-                                       db.Add (memberDecl, e);
                                }
                                return e.Values;
                        }
                }
 
-               MethodBody[] GetMethodBodies (IMemberReference member)
+               MethodBody[] GetMethodBodies (MemberReference member)
                {
                        if (member is MethodReference) {
                                return new[]{ (((MethodReference) member).Resolve ()).Body };
                        }
                        if (member is PropertyReference) {
-                               PropertyDefinition prop = ((PropertyReference) member).Resolve ();
+                               PropertyDefinition prop = (PropertyDefinition) member;
                                return new[]{
                                        prop.GetMethod != null ? prop.GetMethod.Body : null,
                                        prop.SetMethod != null ? prop.SetMethod.Body : null,
@@ -120,7 +118,7 @@ namespace Mono.Documentation {
                        if (member is FieldReference)
                                return new MethodBody[]{};
                        if (member is EventReference) {
-                               EventDefinition ev = ((EventReference) member).Resolve ();
+                               EventDefinition ev = (EventDefinition) member;
                                return new[]{
                                        ev.AddMethod != null ? ev.AddMethod.Body : null,
                                        ev.InvokeMethod != null ? ev.InvokeMethod.Body : null, 
@@ -140,11 +138,12 @@ namespace Mono.Documentation {
                                                if ((locations & ExceptionLocations.Assembly) == 0 && 
                                                                (locations & ExceptionLocations.DependentAssemblies) == 0)
                                                        break;
-                                               IMemberReference memberRef = ((IMemberReference) instruction.Operand);
+                                               MemberReference memberRef = ((MemberReference) instruction.Operand);
                                                if (((locations & ExceptionLocations.Assembly) != 0 && 
                                                                        body.Method.DeclaringType.Scope.Name == memberRef.DeclaringType.Scope.Name) ||
                                                                ((locations & ExceptionLocations.DependentAssemblies) != 0 && 
                                                                        body.Method.DeclaringType.Scope.Name != memberRef.DeclaringType.Scope.Name)) {
+
                                                        IEnumerable<ExceptionSources> memberExceptions = this [memberRef];
                                                        AddExceptions (body, instruction, 
                                                                        memberExceptions.Select (es => es.Exception),
@@ -158,7 +157,7 @@ namespace Mono.Documentation {
                                                if (IsExceptionConstructor (ctor)) {
                                                        AddExceptions (body, instruction,
                                                                        new TypeReference[]{ctor.DeclaringType},
-                                                                       new IMemberReference[]{body.Method},
+                                                                       new MemberReference[]{body.Method},
                                                                        exceptions);
                                                }
                                                break;
@@ -167,7 +166,7 @@ namespace Mono.Documentation {
                        }
                }
 
-               void AddExceptions (MethodBody body, Instruction instruction, IEnumerable<TypeReference> add, IEnumerable<IMemberReference> sources,
+               void AddExceptions (MethodBody body, Instruction instruction, IEnumerable<TypeReference> add, IEnumerable<MemberReference> sources,
                                Dictionary<string, ExceptionSources> exceptions)
                {
                        var handlers = body.ExceptionHandlers.Cast<ExceptionHandler> ()
@@ -181,7 +180,8 @@ namespace Mono.Documentation {
                                                s = new ExceptionSources (ex);
                                                exceptions.Add (eName, s);
                                        }
-                                       s.SourcesList.AddRange (sources);
+                                       foreach (var m in sources)
+                                               s.Sources.Add (m);
                                }
                        }
                }