Skip to content

Commit 78f7301

Browse files
jonpryoratsushieno
authored andcommitted
[generator] Don't special case synthetic methods
Context: dotnet/android#1998 (comment) Context: https://github.com/xamarin/monodroid/commit/2c515356d9a671f729aff2e81c4c2f6184749722 Long ago, `generator` was written to consume API XML descriptions provided by Google. This approach worked reasonably well until Honeycomb, at which point Google didn't provide an XML API description when the API-H `android.jar` was released. The fix was `jar2xml`, which used Java Reflection around `android.jar` to generate a similar API XML description which `generator` could use. `jar2xml` in turn had its own share of problems, which resulted in `class-parse`, which had a *different* share of problems. :-) The original hope was that `generator` could directly use `class-parse` output. Turns out, it wasn't that easy, hence `Xamarin.Android.Tools.ApiXmlAdjuster`, which took `class-parse` output and "munged" it into something resembling `jar2xml` output (e.g. with respect to whether method overrides were included). However, *before* `Xamarin.Android.Tools.ApiXmlAdjuster` existed, I tried to get `generator` to consume `class-parse` output directly, and in that spirit monodroid@2c515356 updated `generator` to *skip* processing of `synthetic` methods: > Don't emit `synthetic` methods, as this results in "duplicate" methods > -- one for the "real" method, one for the synthetic method. However, the scenario monodroid@2c515356 attempted to address -- direct support for `class-parse` output -- is not something that has ever been used, or been tested, or even *worked*. Thus, the special-casing of `synthetic` methods is effectively dead code, all the more so because `Xamarin.Android.Tools.ApiXmlAdjuster` never emitted the `//method/@synthetic` attribute in the first place, so `generator`s special-casing of `synthetic` methods was never hit. ...until 0881acc, which updated `Xamarin.Android.Tools.ApiXmlAdjuster` to include and copy over *all* source attributes, *including* `//method/@synthetic`. *NOW* `generator` began to see methods with `//method[@Synthetic='true']`, *and **skip** them*. The resulting code *compiled*, but had [ABI breakage][0]. Remove the special-casing logic for `synthetic` methods from `generator`. monodroid@2c515356 never supported direct consumption of `class-parse` output by `generator`, meaning such an effort will require more work *anyway*, and removing `synthetic` special-casing from `generator` will allow it to consume post-0881accd `Xamarin.Android.Tools.ApiXmlAdjuster` output without breaking things. [0]: https://jenkins.mono-project.com/job/xamarin-android-pr-builder/3642/API_20Compatibility_20Checks/
1 parent 9fecba2 commit 78f7301

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

tools/generator/ClassGen.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ public XmlClassGen (XElement pkg, XElement elem)
8383
AddInterface (iname);
8484
break;
8585
case "method":
86-
var synthetic = child.XGetAttribute ("synthetic") == "true";
87-
var finalizer = child.XGetAttribute ("name") == "finalize" &&
88-
child.XGetAttribute ("jni-signature") == "()V";
89-
if (!(synthetic || finalizer))
90-
AddMethod (new XmlMethod (this, child));
86+
AddMethod (new XmlMethod (this, child));
9187
break;
9288
case "constructor":
9389
Ctors.Add (new XmlCtor (this, child));

tools/generator/InterfaceGen.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public XmlInterfaceGen (XElement pkg, XElement elem)
5353
AddInterface (iname);
5454
break;
5555
case "method":
56-
if (child.XGetAttribute ("synthetic") != "true")
57-
AddMethod (new XmlMethod (this, child));
56+
AddMethod (new XmlMethod (this, child));
5857
break;
5958
case "field":
6059
AddField (new XmlField (child));

0 commit comments

Comments
 (0)