Skip to content

Commit 50c0c15

Browse files
atsushienojonpryor
authored andcommitted
[enumification] Support "non-constant-to-constant" transition in enums (#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.)
1 parent 71c8756 commit 50c0c15

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

build-tools/enumification-helpers/generate-const-list-2.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
public class Driver
1010
{
11-
class Constant {
11+
class ConstantCandidate {
1212
public string Package, ParentType, Level, FieldType, Name, Value;
13-
public bool IsTypeInterface;
13+
public bool IsTypeInterface, IsFinal;
1414
}
1515

1616
static string GetApiLevel (string file)
@@ -30,15 +30,16 @@ public static void Main (string [] args)
3030
.SelectMany (p => p.Elements ())
3131
.SelectMany (t => t.Elements ("field"))
3232
.Where (f => f.Attribute ("type")?.Value == "int")
33-
.Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null)
33+
//.Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null)
3434
.ToArray ();
35-
var consts = results.Select (f => new Constant {
35+
var consts = results.Select (f => new ConstantCandidate {
3636
Package = f.Parent.Parent.Attribute ("name").Value,
3737
ParentType = f.Parent.Attribute ("name").Value,
38+
IsFinal = f.Attribute ("final")?.Value == "true",
3839
IsTypeInterface = f.Parent.Name.LocalName == "interface",
3940
Name = f.Attribute ("name").Value,
4041
FieldType = f.Attribute ("type").Value,
41-
Value = f.Attribute ("value").Value,
42+
Value = f.Attribute ("value")?.Value,
4243
Level = levels [f.Document.BaseUri]
4344
})
4445
.OrderBy (c => c.Package)
@@ -52,9 +53,14 @@ public static void Main (string [] args)
5253
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) {
5354
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);
5455
consts [i - x].Value = consts [i].Value;
56+
if (!consts [i - x].IsFinal)
57+
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);
58+
consts [i - x].IsFinal = consts [i].IsFinal;
5559
x++;
5660
}
5761
}
62+
63+
consts = consts.Where (f => f.IsFinal).ToArray ();
5864

5965
var fields = new List<string> ();
6066
string package = null, type = null;

src/Mono.Android/map.csv

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This file is almost automatically generated by build-tools/enumification-helpers.
2+
// See README.md there for details.
3+
14
// this cannot be automatically generated, too exceptional...
25
1,Android.Media.Stream,NotificationDefault,android/app/Notification.STREAM_DEFAULT,-1
36
1,Android.Media.Stream,Alarm,android/media/AudioManager.STREAM_ALARM,4
@@ -2907,10 +2910,10 @@
29072910
10,Android.Views.Animations.DelayOrder,Normal,android/view/animation/LayoutAnimationController.ORDER_NORMAL,0
29082911
10,Android.Views.Animations.DelayOrder,Random,android/view/animation/LayoutAnimationController.ORDER_RANDOM,2
29092912
10,Android.Views.Animations.DelayOrder,Reverse,android/view/animation/LayoutAnimationController.ORDER_REVERSE,1
2910-
19,Android.Views.Animations.TransformationTypes,Alpha,android/view/animation/Transformation.TYPE_ALPHA,1
2911-
19,Android.Views.Animations.TransformationTypes,Both,android/view/animation/Transformation.TYPE_BOTH,3
2912-
19,Android.Views.Animations.TransformationTypes,Identity,android/view/animation/Transformation.TYPE_IDENTITY,0
2913-
19,Android.Views.Animations.TransformationTypes,Matrix,android/view/animation/Transformation.TYPE_MATRIX,2
2913+
10,Android.Views.Animations.TransformationTypes,Alpha,android/view/animation/Transformation.TYPE_ALPHA,1
2914+
10,Android.Views.Animations.TransformationTypes,Both,android/view/animation/Transformation.TYPE_BOTH,3
2915+
10,Android.Views.Animations.TransformationTypes,Identity,android/view/animation/Transformation.TYPE_IDENTITY,0
2916+
10,Android.Views.Animations.TransformationTypes,Matrix,android/view/animation/Transformation.TYPE_MATRIX,2
29142917
10,Android.Views.InputMethods.ImeAction,ImeMaskAction,android/view/inputmethod/EditorInfo.IME_MASK_ACTION,255
29152918
10,Android.Views.InputMethods.ImeAction,ImeNull,android/view/inputmethod/EditorInfo.IME_NULL,0
29162919
10,Android.Views.InputMethods.ImeAction,Done,android/view/inputmethod/EditorInfo.IME_ACTION_DONE,6
@@ -4532,6 +4535,7 @@
45324535
23,Android.Util.DisplayMetricsDensity,D420,android/util/DisplayMetrics.DENSITY_420,420
45334536
21,Android.Util.DisplayMetricsDensity,D560,android/util/DisplayMetrics.DENSITY_560,560
45344537
10,Android.Util.DisplayMetricsDensity,Default,android/util/DisplayMetrics.DENSITY_DEFAULT,160
4538+
24,Android.Util.DisplayMetricsDensity,DeviceStable,android/util/DisplayMetrics.DENSITY_DEVICE_STABLE,
45354539
10,Android.Util.DisplayMetricsDensity,High,android/util/DisplayMetrics.DENSITY_HIGH,240
45364540
10,Android.Util.DisplayMetricsDensity,Low,android/util/DisplayMetrics.DENSITY_LOW,120
45374541
10,Android.Util.DisplayMetricsDensity,Medium,android/util/DisplayMetrics.DENSITY_MEDIUM,160

0 commit comments

Comments
 (0)