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

[generator] Add 'managedOverride' metadata to allow user to force 'override'/'virtual'. #701

Merged
merged 2 commits into from
Aug 28, 2020

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 28, 2020

Fixes: #681

There are scenarios where generator does not correctly find overridden methods, often due to generic parameters. When these issues happen, the fix is to <remove-node> the offending method and add a fully hand-bound version of it as an Addition. This is a very manual fix to simply add override to a method.

While we would like to eventually fix all these scenarios to "do the right thing", that will be a complex fix(es), and perhaps we will never be able to handle all cases.

For now, we can at least alleviate the pain by adding a metadata attribute that allows the user to override our detection, avoiding the hand-binding.

This new attribute is called managedOverride and allows the user to specify the values virtual or override, forcing us to use the requested modifier instead of generator's usual logic.

<attr path="//method[@name='example']" name="managedOverride">override</attr>
<attr path="//method[@name='example']" name="managedOverride">virtual</attr>

@jpobst jpobst marked this pull request as ready for review August 28, 2020 15:21
{
var xml = @"<api>
<package name='java.lang' jni-name='java/lang'>
<class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/EmptyOverrideClass;' />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This <class/> is very odd -- and apparently something that ParseApiDefinition() doesn't check for -- in that [@name='Object'] is not consistent with [@jni-signature='Ljava/lang/EmptyOverrideClass;']. With [@name='Object'], I would expect [@jni-signature='Ljava/lang/Object;'].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we don't even read the jni-signature attribute, much less do anything with it: https://github.com/xamarin/java.interop/blob/master/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow overriding C# method modifiers
2 participants