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] Extend skipInvokerMethods support to interfaces. #1202

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Mar 5, 2024

Context: #1086

#1086 added the metadata attribute skipInvokerMethods to allow us to suppress generation of invoker methods for a class.

The AndroidX Media3 binding hits an issue where we generate incorrect generics in an invoker type. However this is an invoker type for an interface instead of a class.

Extend our skipInvokerMethods support to cover interfaces as well.

@jpobst jpobst force-pushed the skip-interface-invokers branch from 03f8edf to 3b5f684 Compare March 5, 2024 23:35
@jpobst jpobst marked this pull request as ready for review March 5, 2024 23:47
@jpobst jpobst requested a review from jonpryor March 5, 2024 23:47
<class abstract='false' deprecated='not deprecated' final='false' name='Object' static='false' visibility='public' jni-signature='Ljava/lang/Object;' />
</package>
<package name='com.xamarin.android' jni-name='com/xamarin/android'>
<interface abstract='false' deprecated='not deprecated' extends='java.lang.Object' extends-generic-aware='java.lang.Object' jni-extends='Ljava/lang/Object;' final='false' name='MyInterface' static='false' visibility='public' jni-signature='Lcom/xamarin/android/MyInterface;' skipInvokerMethods='com/xamarin/android/MyInterface.countAffectedRows()I'>
Copy link
Member

@jonpryor jonpryor Mar 6, 2024

Choose a reason for hiding this comment

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

Generally (always?) //interface/@abstract will be true, not false. (At least, I can find no instances of such a thing in api-34.xml.)

@@ -331,6 +331,10 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
!options.SupportNestedInterfaceTypes
};

if (elem.Attribute ("skipInvokerMethods")?.Value is string skip)
Copy link
Member

Choose a reason for hiding this comment

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

This should be split out into a helper method, and CreateClass() updated to use the helper method, as I can't imagine any reason why the semantics for skipInvokerMethods should differ between classes and interfaces.

{
foreach (var m in methods) {
if (skipInvokers.Contains ($"{m.DeclaringType.RawJniName}.{m.JavaName}{m.JniSignature}"))
Copy link
Member

Choose a reason for hiding this comment

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

"Ditto" here: I'd be happier if ClassInvokerClass and InterfaceInvokerClass used the same method to generate the $"m.DeclaringType.RawJniName}.{m.JavaName}{m.JniSignature}" string.

@@ -331,6 +331,10 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
!options.SupportNestedInterfaceTypes
};

if (elem.Attribute ("skipInvokerMethods")?.Value is string skip)
foreach (var m in skip.Split (new char [] { ',', ' ', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
iface.SkippedInvokerMethods.Add (m);
Copy link
Member

Choose a reason for hiding this comment

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

It occurs to me: should we "sanity check" this value, asserting that it contains one ., one (, and one )? (And maybe even verify that (…)… constitutes a valid JNI method signature, according to e.g. JniMemberSignature.GetParameterCountFromMethodSignature() + a return type sanity check.)

This request might be a step "too far" for this PR -- as opposed to my other comments, which I think are closer to "code hygiene" and code deduplication -- but this thought hadn't occurred to me before.

@jpobst jpobst force-pushed the skip-interface-invokers branch from 3b5f684 to 595625f Compare March 6, 2024 17:58
@jonpryor jonpryor merged commit a7e09b7 into main Mar 6, 2024
4 checks passed
@jonpryor jonpryor deleted the skip-interface-invokers branch March 6, 2024 18:20
jonpryor pushed a commit that referenced this pull request Mar 6, 2024
Context: 73ebad2
Context: dotnet/android-libraries#779

Commit 73ebad2 added support for the metadata attribute
`//class[@skipInvokerMethods]`, which allowed us to suppress generation
of invoker methods for a class.

The AndroidX Media3 binding in dotnet/android-libraries#779 hits a similar
issue wherein we generate incorrect generics on an invoker type.
However, this is an invoker type for an *`interface`*, not a `class`.

Extend our `skipInvokerMethods` support so that it can be used as
`//interface[@skipInvokerMethods]` as well.
jonpryor added a commit to dotnet/android that referenced this pull request Mar 6, 2024
Context: dotnet/java-interop#1203

Does It Build™?

Changes: dotnet/java-interop@bec0326...e557044

  * dotnet/java-interop@e557044f: [generator] Extend `skipInvokerMethods` support to interfaces. (dotnet/java-interop#1202)
jonpryor pushed a commit to dotnet/android that referenced this pull request Mar 7, 2024
Changes: dotnet/java-interop@14a9470...a7e09b7

  * dotnet/java-interop@a7e09b7b: [generator] Extend `skipInvokerMethods` support to interfaces. (dotnet/java-interop#1202)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
jonpryor added a commit that referenced this pull request Mar 7, 2024
#1203)

Context: 73ebad2
Context: dotnet/android-libraries#779

Commit 73ebad2 added support for the metadata attribute
`//class[@skipInvokerMethods]`, which allowed us to suppress generation
of invoker methods for a class.

The AndroidX Media3 binding in dotnet/android-libraries#779 hits a similar
issue wherein we generate incorrect generics on an invoker type.
However, this is an invoker type for an *`interface`*, not a `class`.

Extend our `skipInvokerMethods` support so that it can be used as
`//interface[@skipInvokerMethods]` as well.

Co-authored-by: Jonathan Pobst <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 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.

2 participants