From 32d1c18fe70bc4b2f85ebbfbca4b5001a3cec3e9 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 7 Dec 2017 15:01:51 +0900 Subject: [PATCH] [enumification] support "non-constant-to-constant" transition in enums too. At 9a73c4c we became much more precise about enumification, because formerly we only pull int constant information through DroidDoc only in the latest API. Besides, we had been precise on which int fields are final and which aren't, in API XML metadata. Since we switched the information source to API XML metadata, such final fields that were NOT final are strictly converted to enums only in the constant-ified API Level. That was regarded as regression at https://github.com/xamarin/xamarin-android/pull/1078 . The solution to this situation is: treat them as constants. To do so, now generate-const-list-2.cs is changed to NOT check if an int field is final or not, until at the merge phase. Then we filter out those non-constant fields (which are not much). This uncovers those "formerly non constant" fields too. Fortunately such fields didn't exist other than the ones at PR #1078 mentioned (this generate-const-list-2.exe now prints out such fields now.) --- .../generate-const-list-2.cs | 16 +++++++++++----- src/Mono.Android/map.csv | 12 ++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build-tools/enumification-helpers/generate-const-list-2.cs b/build-tools/enumification-helpers/generate-const-list-2.cs index d44a336568c..4b053fc5d87 100644 --- a/build-tools/enumification-helpers/generate-const-list-2.cs +++ b/build-tools/enumification-helpers/generate-const-list-2.cs @@ -8,9 +8,9 @@ public class Driver { - class Constant { + class ConstantCandidate { public string Package, ParentType, Level, FieldType, Name, Value; - public bool IsTypeInterface; + public bool IsTypeInterface, IsFinal; } static string GetApiLevel (string file) @@ -30,15 +30,16 @@ public static void Main (string [] args) .SelectMany (p => p.Elements ()) .SelectMany (t => t.Elements ("field")) .Where (f => f.Attribute ("type")?.Value == "int") - .Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null) + //.Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null) .ToArray (); - var consts = results.Select (f => new Constant { + var consts = results.Select (f => new ConstantCandidate { Package = f.Parent.Parent.Attribute ("name").Value, ParentType = f.Parent.Attribute ("name").Value, + IsFinal = f.Attribute ("final")?.Value == "true", IsTypeInterface = f.Parent.Name.LocalName == "interface", Name = f.Attribute ("name").Value, FieldType = f.Attribute ("type").Value, - Value = f.Attribute ("value").Value, + Value = f.Attribute ("value")?.Value, Level = levels [f.Document.BaseUri] }) .OrderBy (c => c.Package) @@ -52,9 +53,14 @@ public static void Main (string [] args) while (consts [i - x].Name == consts [i].Name && consts [i - x].ParentType == consts [i].ParentType && consts [i - x].Package == consts [i].Package && consts [i - x].Value != consts [i].Value) { Console.Error.WriteLine ("Overwrite field value: {0}.{1}.{2}: {3} (at {4}) -> {5} (at {6})", consts [i - x].Package, consts [i - x].ParentType, consts [i - x].Name, consts [i - x].Value, consts [i - x].Level, consts [i].Value, consts [i].Level); consts [i - x].Value = consts [i].Value; + if (!consts [i - x].IsFinal) + Console.Error.WriteLine ("Field {0}.{1}.{2} was not constant at API Level {3}", consts [i - x].Package, consts [i - x].ParentType, consts [i - x].Name, consts [i - x].Level); + consts [i - x].IsFinal = consts [i].IsFinal; x++; } } + + consts = consts.Where (f => f.IsFinal).ToArray (); var fields = new List (); string package = null, type = null; diff --git a/src/Mono.Android/map.csv b/src/Mono.Android/map.csv index dc707d02948..cc9c9444d44 100644 --- a/src/Mono.Android/map.csv +++ b/src/Mono.Android/map.csv @@ -1,3 +1,6 @@ +// This file is almost automatically generated by build-tools/enumification-helpers. +// See README.md there for details. + // this cannot be automatically generated, too exceptional... 1,Android.Media.Stream,NotificationDefault,android/app/Notification.STREAM_DEFAULT,-1 1,Android.Media.Stream,Alarm,android/media/AudioManager.STREAM_ALARM,4 @@ -2907,10 +2910,10 @@ 10,Android.Views.Animations.DelayOrder,Normal,android/view/animation/LayoutAnimationController.ORDER_NORMAL,0 10,Android.Views.Animations.DelayOrder,Random,android/view/animation/LayoutAnimationController.ORDER_RANDOM,2 10,Android.Views.Animations.DelayOrder,Reverse,android/view/animation/LayoutAnimationController.ORDER_REVERSE,1 -19,Android.Views.Animations.TransformationTypes,Alpha,android/view/animation/Transformation.TYPE_ALPHA,1 -19,Android.Views.Animations.TransformationTypes,Both,android/view/animation/Transformation.TYPE_BOTH,3 -19,Android.Views.Animations.TransformationTypes,Identity,android/view/animation/Transformation.TYPE_IDENTITY,0 -19,Android.Views.Animations.TransformationTypes,Matrix,android/view/animation/Transformation.TYPE_MATRIX,2 +10,Android.Views.Animations.TransformationTypes,Alpha,android/view/animation/Transformation.TYPE_ALPHA,1 +10,Android.Views.Animations.TransformationTypes,Both,android/view/animation/Transformation.TYPE_BOTH,3 +10,Android.Views.Animations.TransformationTypes,Identity,android/view/animation/Transformation.TYPE_IDENTITY,0 +10,Android.Views.Animations.TransformationTypes,Matrix,android/view/animation/Transformation.TYPE_MATRIX,2 10,Android.Views.InputMethods.ImeAction,ImeMaskAction,android/view/inputmethod/EditorInfo.IME_MASK_ACTION,255 10,Android.Views.InputMethods.ImeAction,ImeNull,android/view/inputmethod/EditorInfo.IME_NULL,0 10,Android.Views.InputMethods.ImeAction,Done,android/view/inputmethod/EditorInfo.IME_ACTION_DONE,6 @@ -4532,6 +4535,7 @@ 23,Android.Util.DisplayMetricsDensity,D420,android/util/DisplayMetrics.DENSITY_420,420 21,Android.Util.DisplayMetricsDensity,D560,android/util/DisplayMetrics.DENSITY_560,560 10,Android.Util.DisplayMetricsDensity,Default,android/util/DisplayMetrics.DENSITY_DEFAULT,160 +24,Android.Util.DisplayMetricsDensity,DeviceStable,android/util/DisplayMetrics.DENSITY_DEVICE_STABLE, 10,Android.Util.DisplayMetricsDensity,High,android/util/DisplayMetrics.DENSITY_HIGH,240 10,Android.Util.DisplayMetricsDensity,Low,android/util/DisplayMetrics.DENSITY_LOW,120 10,Android.Util.DisplayMetricsDensity,Medium,android/util/DisplayMetrics.DENSITY_MEDIUM,160