Skip to content

Conversation

@jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Oct 25, 2024

Context: 0aec86a

Commit 0aec86a mentioned:

  • Use of JNIEnv.GetJniName()

    string __id = "(L" + global::Android.Runtime.JNIEnv.GetJniName (GetType ().DeclaringType) + ";)V";
    

    Impacts: NestedTypes.cs

This issue also impacts
java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject.

Update Java.Base to bind the java.util.concurrent package, which will cause AbstractQueuedSynchronizer to be bound, which in turn forces us to update generator to not emit JNIEnv.GetJniName(). Instead of using JNIEnv.GetJniName(Type), use:

JniEnvironment.Runtime.TypeManager.GetTypeSignature (GetType ().DeclaringType).SimpleReference

Update NestedTypes.cs to enable TryJavaInterop1 => true.

Update Java.Base.csproj to ignore C# warning CS0109, as CompletableFuture.handle() is emitted with a new which is not required:

Java.Util.Concurrent.CompletableFuture.cs(629,76): warning CS0109: The member
'CompletableFuture.Handle(IBiFunction?)' does not hide an accessible member.
The new keyword is not required.

Add a test to tests/Java.Base-Tests which tests nested type support.

Update JavaNativeTypeManager.cs so that IsNonStaticInnerClass() supports JavaInterop1-style attributes, not just XAJavaInterop1.

Aside: I updated my local JDK to JDK-17 (from JDK-11), which caused many changes to src/Java.Base-ref.cs, particularly parameter names.

TODO? Update Java.Interop.Tools.JavaCallableWrappers so that non-static inner classes don't have a prefix of their declaring type. This would result in example/MyQueuedSynchronizer$MyConditionObject instead of
example/MyQueuedSynchronizer$MyQueuedSynchronizer_MyConditionObject.

Context: 0aec86a

Commit 0aec86a mentioned:

>  * Use of `JNIEnv.GetJniName()`
>
>        string __id = "(L" + global::Android.Runtime.JNIEnv.GetJniName (GetType ().DeclaringType) + ";)V";
>
>    Impacts: NestedTypes.cs

This issue also impacts
[`java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject`][0].

Update `Java.Base` to bind the `java.util.concurrent` package, which
will cause `AbstractQueuedSynchronizer` to be bound, which in turn
forces us to update `generator` to not emit `JNIEnv.GetJniName()`.
Instead of using `JNIEnv.GetJniName(Type)`, use:

	JniEnvironment.Runtime.TypeManager.GetTypeSignature (GetType ().DeclaringType).SimpleReference

Update NestedTypes.cs to enable `TryJavaInterop1 => true`.

Update `Java.Base.csproj` to ignore C# warning [CS0109][1], as
[`CompletableFuture.handle()`] is emitted with a `new` which is not
required:

	Java.Util.Concurrent.CompletableFuture.cs(629,76): warning CS0109: The member
	'CompletableFuture.Handle(IBiFunction?)' does not hide an accessible member.
	The new keyword is not required.

Add a test to `tests/Java.Base-Tests` which tests nested type support.

Update `JavaNativeTypeManager.cs` so that `IsNonStaticInnerClass()`
supports JavaInterop1-style attributes, not just XAJavaInterop1.

Aside: I updated my local JDK to JDK-17 (from JDK-11), which caused
many changes to `src/Java.Base-ref.cs`, particularly parameter names.

TODO? Update `Java.Interop.Tools.JavaCallableWrappers` so that
non-static inner classes don't have a prefix of their declaring type.
This would result in `example/MyQueuedSynchronizer$MyConditionObject`
instead of
`example/MyQueuedSynchronizer$MyQueuedSynchronizer_MyConditionObject`.

[0]: https://developer.android.com/reference/java/util/concurrent/locks/AbstractQueuedSynchronizer.ConditionObject
[1]: https://learn.microsoft.com/dotnet/csharp/misc/cs0109
[2]: https://developer.android.com/reference/java/util/concurrent/CompletableFuture#handle(java.util.function.BiFunction%3C?%20super%20T,java.lang.Throwable,?%20extends%20U%3E)
if (!type.HasCustomAttributes)
return false;
return type.AnyCustomAttributes (typeof (RegisterAttribute)) ||
type.AnyCustomAttributes ("Java.Interop.JniTypeSignatureAttribute");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to cause any issues for XAJavaInterop1? Do we need to find a way to ensure that this is only used for JavaInterop1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this going to cause any issues for XAJavaInterop1?

No. JavaNativeTypeManager allows obtaining the Java Callable Wrapper type name from a System.Type or Mono.Cecil.TypeDefinition instance. jcw-gen already uses [JniTypeSignature], as does JavaNativeTypeManager:

var attr = type.CustomAttributes.FirstOrDefault (a =>
resolver.Resolve (a.AttributeType)
.FullName == "Java.Interop.JniTypeSignatureAttribute");

The change here is for IsNonStaticInnerClass(), which didn't yet check for [JniTypeSignature].

Do we need to find a way to ensure that this is only used for JavaInterop1?

No.

@jonpryor jonpryor merged commit 2bdf2bc into main Oct 28, 2024
4 checks passed
@jonpryor jonpryor deleted the dev/jonp/jonp-Java.Base-java.util.concurrent branch October 28, 2024 19:20
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 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.

3 participants