* tuner/Mono.Tuner/MoonlightA11yProcessor.cs: Look for base methods in
authorAndrés G. Aragoneses <knocte@gmail.com>
Wed, 12 Aug 2009 20:53:48 +0000 (20:53 -0000)
committerAndrés G. Aragoneses <knocte@gmail.com>
Wed, 12 Aug 2009 20:53:48 +0000 (20:53 -0000)
interfaces as well.

svn path=/trunk/mcs/; revision=139796

mcs/tools/tuner/ChangeLog
mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs

index b97e70f316ea0b2e978146379bf43bfb8eb1747e..094d71770637c3c1f3334ecba83ac11a2a334fd0 100644 (file)
@@ -1,3 +1,8 @@
+2009-08-12  Andrés G. Aragoneses  <aaragoneses@novell.com>
+
+       * Mono.Tuner/MoonlightA11yProcessor.cs: Look for base methods
+         in interfaces as well.
+
 2009-08-11  Andrés G. Aragoneses  <aaragoneses@novell.com>
 
        * Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Yet another
index e543441926506be1d5e42f29dde697c75c304f5f..c2ae8691820252b500c64c792497ef847f5f1674 100644 (file)
@@ -91,11 +91,16 @@ namespace Mono.Tuner {
                                                MethodDefinition parent = null;
                                        
                                                //TODO: take in account generic params
-                                               if (!method.HasGenericParameters)
-                                                       //NOTE: GetOverridenMethod returns null if there is no base method
-                                                       parent = GetOverridenMethod (type, method);
+                                               if (!method.HasGenericParameters) {
+                                                       
+                                                       /*
+                                                        * we need to scan base methods because the CoreCLR complains about SC attribs added
+                                                        * to overriden methods whose base (virtual or interface) method is not marked as SC
+                                                        * with TypeLoadExceptions
+                                                        */
+                                                       parent = GetBaseMethod (type, method);
+                                               }
 
-                                               //to prevent Type*Exceptions because of having SC attribs in overriden methods of non-SC base methods
                                                if (parent == null || HasSecurityAttribute (parent, AttributeType.Critical))
                                                        AddCriticalAttribute (method);
                                }
@@ -103,12 +108,17 @@ namespace Mono.Tuner {
                        }
                }
                
+               MethodDefinition GetBaseMethod (TypeDefinition finalType, MethodDefinition final)
+               {
+                       // both GetOverridenMethod and GetInterfaceMethod return null if there is no base method
+                       return GetOverridenMethod (finalType, final) ?? GetInterfaceMethod (finalType, final);
+               }
+               
                //note: will not return abstract methods
                MethodDefinition GetOverridenMethod (TypeDefinition finalType, MethodDefinition final)
                {
                        TypeReference baseType = finalType.BaseType;
                        while (baseType != null && baseType.Resolve () != null) {
-                               
                                foreach (MethodDefinition method in baseType.Resolve ().Methods) {
                                        if (!method.IsVirtual || method.Name != final.Name)
                                                continue;
@@ -125,6 +135,21 @@ namespace Mono.Tuner {
                        return null;
                }
                
+               MethodDefinition GetInterfaceMethod (TypeDefinition finalType, MethodDefinition final)
+               {
+                       TypeDefinition baseType = finalType;
+                       while (baseType != null) {
+                               if (baseType.HasInterfaces)
+                                       foreach (TypeReference @interface in baseType.Interfaces)
+                                               foreach (MethodDefinition method in @interface.Resolve ().Methods)
+                                                       if (method.Name == final.Name && HasSameSignature (method, final))
+                                                               return method;
+
+                               baseType = baseType.BaseType == null ? null : baseType.BaseType.Resolve ();
+                       }
+                       return null;
+               }
+               
                bool HasSameSignature (MethodDefinition method1, MethodDefinition method2)
                {
                        if (method1.ReturnType.ReturnType.FullName != method2.ReturnType.ReturnType.FullName)