Skip to content

Commit

Permalink
[enumification] Support "non-constant-to-constant" transition in enums (
Browse files Browse the repository at this point in the history
#1080)

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 #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.)
  • Loading branch information
atsushieno authored and jonpryor committed Dec 7, 2017
1 parent 71c8756 commit 50c0c15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 11 additions & 5 deletions build-tools/enumification-helpers/generate-const-list-2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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> ();
string package = null, type = null;
Expand Down
12 changes: 8 additions & 4 deletions src/Mono.Android/map.csv
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50c0c15

Please sign in to comment.