Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enumification] support "non-constant-to-constant" transition in enums too. #1080

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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