[mono-api-html] Allow ignoring parameter names, virtual.
authorJonathan Pryor <jonpryor@vt.edu>
Wed, 12 Nov 2014 22:28:48 +0000 (17:28 -0500)
committerJonathan Pryor <jonpryor@vt.edu>
Wed, 12 Nov 2014 22:34:21 +0000 (17:34 -0500)
I've been trying to review API diffs in Xamarin.Android between API
levels, but the diffs are "noisy" because Google will change parameter
names at-will, or will change a non-virtual method into a virtual
method, or a virtual method into an override, all of which are
acceptable changes but individually generate a Removed line in
mono-api-html output, and manually removing the *hundreds* of changes
is error-prone.

Add two new option flags to mono-api-html:

  --ignore-changes-parameter-names:
      Ignore changes in constructor and method parameter names.

      If parameter names change between <reference.xml> and
      <assembly.xml>, don't report a change for the constructor or
      method.

  --ignore-changes-virtual:
      Ignore changes in "virtual-ness".

      If a method or property changes from non-virtual to virtual,
      non-virtual to override, or virtual to override, don't report a
      change for the member.

mcs/tools/corcompare/mono-api-html/ApiDiff.cs
mcs/tools/corcompare/mono-api-html/ConstructorComparer.cs
mcs/tools/corcompare/mono-api-html/PropertyComparer.cs

index b79dd7b886a96bee9efbf21a1ea07a8176236729..4bbebf576248071b8bcfb580ae49c37ab3a26adc 100644 (file)
@@ -74,6 +74,9 @@ namespace Xamarin.ApiDiff {
                        get { return ignoreRemoved; }
                }
 
+               public  static  bool    IgnoreParameterNameChanges  { get; set; }
+               public  static  bool    IgnoreVirtualChanges        { get; set; }
+
                public static bool Lax;
        }
 
@@ -105,6 +108,12 @@ namespace Xamarin.ApiDiff {
                                { "n|ignore-new=", "Ignore new namespaces and types whose description matches a given C# regular expression (see below).",
                                        v => State.IgnoreNew.Add (new Regex (v))
                                },
+                               { "ignore-changes-parameter-names", "Ignore changes to parameter names for identically prototyped methods.",
+                                       v => State.IgnoreParameterNameChanges   = v != null
+                               },
+                               { "ignore-changes-virtual", "Ignore changing non-`virtual` to `virtual` or adding `override`.",
+                                       v => State.IgnoreVirtualChanges = v != null
+                               },
                                { "x|lax", "Ignore duplicate XML entries", v => State.Lax = true }
                        };
 
index ffef2e010509c78982f8c44178a5fe9e1a9fb0e0..eae249a205893efc915fddbc939f44cb62a6045c 100644 (file)
@@ -62,7 +62,7 @@ namespace Xamarin.ApiDiff {
 
                                if ((attr & MethodAttributes.Static) != 0) {
                                        sb.Append ("static ");
-                               } else if ((attr & MethodAttributes.Virtual) != 0) {
+                               } else if ((attr & MethodAttributes.Virtual) != 0 && !State.IgnoreVirtualChanges) {
                                        if ((attr & MethodAttributes.VtableLayoutMask) == 0)
                                                sb.Append ("override ");
                                        else
@@ -99,7 +99,10 @@ namespace Xamarin.ApiDiff {
                        if (parameters != null) {
                                var list = new List<string> ();
                                foreach (var p in parameters.Elements ("parameter")) {
-                                       list.Add (p.GetTypeName ("type") + " " + p.GetAttribute ("name"));
+                                       var pTypeName   = p.GetTypeName ("type");
+                                       list.Add (State.IgnoreParameterNameChanges
+                                               ? pTypeName
+                                               : pTypeName + " " + p.GetAttribute ("name"));
                                }
                                sb.Append (String.Join (", ", list));
                        }
index 0d0a9bdd548dc3112d54a97d2760affc8cff90ee..4a5f34fd2ec8978d0b94cf5788e4f03ec1be8bca 100644 (file)
@@ -77,7 +77,7 @@ namespace Xamarin.ApiDiff {
                        var sb = new StringBuilder ();
 
                        sb.Append (family ? "protected " : "public ");
-                       if (virt)
+                       if (virt && !State.IgnoreVirtualChanges)
                                sb.Append (over ? "override " : "virtual ");
                        else if (stat)
                                sb.Append ("static ");