Skip to content

[generator] Support XML defined enums with no JNI info. #659

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

Merged
merged 2 commits into from
Jun 9, 2020

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jun 5, 2020

Fixes #515.

Our CSV format for specifying enums supports creating enum fields that do not map to a JNI field. This is often used to add a None enum field to a Java [Flags] enum:

0,,0,Android.AccessibilityServices.AccessibilityServiceCapabilities,None

However our XML format does not support this because it considers the jni-class/jni-interface and jni-name attributes mandatory when translating the XML format to CSV format.

We can lift this restriction and correctly generate the needed CSV format so that users using the XML format can add arbitrary enums that generator knows about.

So this is now supported:

<mapping clr-enum-type='Android.Support.V4.App.FragmentTagType' bitfield='true'>
  <field clr-name='Name' value='0' />
  <field clr-name='Id' value='1' />
  <field clr-name='Tag' value='2' />
</mapping>

in addition to the old requirements:

<mapping jni-interface='android/support/v4/app/FragmentActivity$FragmentTag' clr-enum-type='Android.Support.V4.App.FragmentTagType' bitfield='true'>
  <field jni-name='Fragment_name' clr-name='Name' value='0' />
  <field jni-name='Fragment_id' clr-name='Id' value='1' />
  <field jni-name='Fragment_tag' clr-name='Tag' value='2' />
</mapping>

@jpobst jpobst marked this pull request as ready for review June 5, 2020 16:28
@jonpryor jonpryor merged commit 267c3f3 into master Jun 9, 2020
@jonpryor jonpryor deleted the no-jni-enums branch June 9, 2020 14:43
jonpryor pushed a commit that referenced this pull request Jun 11, 2020
Fixes: #515

Our `.csv` format for specifying enums allows creating enum fields that
do not map to a JNI field.  This is often used to add a `None` enum
field to a Java `[Flags]` enum:

	0,,0,Android.AccessibilityServices.AccessibilityServiceCapabilities,None

However our XML format does not support this because it considers the
(`//mapping/@jni-class` or `//mapping/@jni-interface`) and
`//mapping/@jni-name` attributes to be mandatory when translating the
XML format to `.csv` format.

We can remove this restriction and correctly generate the needed `.csv`
format so that users using the XML format can add arbitrary enums that
`generator` knows about, permitting:

	<mapping clr-enum-type='Android.Support.V4.App.FragmentTagType' bitfield='true'>
	  <field clr-name='Name' value='0' />
	  <field clr-name='Id' value='1' />
	  <field clr-name='Tag' value='2' />
	</mapping>

in addition to the previously required:

	<mapping jni-interface='android/support/v4/app/FragmentActivity$FragmentTag' clr-enum-type='Android.Support.V4.App.FragmentTagType' bitfield='true'>
	  <field jni-name='Fragment_name' clr-name='Name' value='0' />
	  <field jni-name='Fragment_id' clr-name='Id' value='1' />
	  <field jni-name='Fragment_tag' clr-name='Tag' value='2' />
	</mapping>
@jpobst jpobst added this to the 10.4 (16.7 / 8.7) milestone Jun 15, 2020
@jpobst
Copy link
Contributor Author

jpobst commented Jun 15, 2020

Release Notes

- [Java.Interop GitHub PR 659](https://github.com/xamarin/java.interop/pull/659):
  Add support for defining new enum members for bindings projects that do not have a 
  corresponding Java implementation.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
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.

Custom enum and enum-method-mappings
2 participants