-
Notifications
You must be signed in to change notification settings - Fork 54
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
Conversation
03f8edf
to
3b5f684
Compare
<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'> |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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}")) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
3b5f684
to
595625f
Compare
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.
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)
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>
#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]>
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 aclass
.Extend our
skipInvokerMethods
support to cover interfaces as well.