Skip to content

Commit

Permalink
[generator] Add string cast to prevent CS1503 (#970)
Browse files Browse the repository at this point in the history
Fixes: #967

Context: dotnet/android-libraries#504
Context: #424
Context: #586
Context: #918

Java generics continues to be a "difficulty" in creating bindings.
Consider [`ActivityResultContracts.RequestPermission`][0]:

	// Java
	public abstract /* partial */ class ActivityResultContract<I, O> {
	    public abstract Intent createIntent(Context context, I input);
	}
	public /* partial */ class /* ActivityResultContracts. */ RequestPermission
	    extends ActivityResultContract<String, Boolean>
	{
	    @OverRide public Intent createIntent(Context context, String input) {…}
	}

The JNI Signature for
`ActivityResultContracts.RequestPermission.createIntent()` is
`(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;`,
i.e. `class-parse` & `generator` believe that the `input` parameter
is of type `String`, which we bind by default as `string`.  Thus:

	// C#
	public abstract partial class ActivityResultContract {
	    public abstract Intent CreateIntent (Context? context, Java.Lang.Object? input) => …
	}
	public partial class /* ActivityResultContracts. */ RequestPermission {
	    public override Intent CreateIntent (Context? context, string? input) => …
	}

This fails to compile with a [CS0115][1]:

	'RequestPermission.CreateIntent(Context?, string?)': no suitable method found to override

as the `input` parameter of `RequestPermission.CreateIntent()` changes
from `Java.Lang.Object?` to `string?`.

We can attempt to address this via Metadata:

	<attr
	  path="/api/package[@name='androidx.activity.result.contract']/class[@name='ActivityResultContracts.RequestPermission']/method[@name='createIntent' and count(parameter)=2 and parameter[1][@type='android.content.Context'] and parameter[2][@type='java.lang.String']]"
	  name="managedType"
	>Java.Lang.Object</attr>

This fixes one error, as `generator` now emits:

	public partial class /* ActivityResultContracts. */ RequestPermission {
	    [Register ("createIntent", "(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;", "")]
	    public override unsafe global::Android.Content.Intent CreateIntent (global::Android.Content.Context context, global::Java.Lang.Object input)
	    {
	        const string __id = "createIntent.(Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;";
	        IntPtr native_input = JNIEnv.NewString (input);
	        try {
	            JniArgumentValue* __args = stackalloc JniArgumentValue [2];
	            __args [0] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
	            __args [1] = new JniArgumentValue (native_input);
	            var __rm = _members.InstanceMethods.InvokeAbstractObjectMethod (__id, this, __args);
	            return global::Java.Lang.Object.GetObject<global::Android.Content.Intent> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
	        } finally {
	            JNIEnv.DeleteLocalRef (native_input);
	            global::System.GC.KeepAlive (context);
	            global::System.GC.KeepAlive (input);
	        }
	    }
	}

The `override` method declaration is correct.

However, this introduces a [CS1503][2] error:

	IntPtr native_input = JNIEnv.NewString (input);
	// Error CS1503 Argument 1: cannot convert from 'Java.Lang.Object' to 'string?'

The workaround is to remove `createIntent()` ~entirely, and manually
bind it, as done in dotnet/android-libraries#512.

Fix this issue by always emitting a cast to `(string)` as
part of the `JNIEnv.NewString()` invocation, instead emitting:

	IntPtr native_input = JNIEnv.NewString ((string?) input);

This works because `Java.Lang.Object` defines an
[explicit conversion to `string?`][3], and if a `Java.Lang.String`
instance is provided to the `input` parameter, it's equivalent to
calling `.ToString()`.

This fix allows the original suggested Metadata solution to work.

[0]: https://developer.android.com/reference/androidx/activity/result/contract/ActivityResultContracts.RequestPermission
[1]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0115
[2]: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs1503
[3]: https://github.com/xamarin/xamarin-android/blob/a58d4e9706455227eabb6e5b5103b25da716688b/src/Mono.Android/Java.Lang/Object.cs#L434-L439
  • Loading branch information
jpobst authored Apr 19, 2022
1 parent 37cff25 commit 05eddd9
Show file tree
Hide file tree
Showing 29 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public unsafe int GetCountForKey (string key)
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public unsafe int GetCountForKey (string key)
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public unsafe string Key {
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public unsafe string Key {
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class MyClass {
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;

IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string?)p0);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_p0);
Expand Down Expand Up @@ -153,7 +153,7 @@ public partial class MyClass {
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")]
set {
const string __id = "set_Key.(Ljava/lang/String;)V";
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string?)value);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_value);
Expand Down Expand Up @@ -253,7 +253,7 @@ public partial class MyClass {
public virtual unsafe int GetCountForKey (string? key)
{
const string __id = "GetCountForKey.(Ljava/lang/String;)I";
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string?)key);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string?)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down Expand Up @@ -303,7 +303,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string?)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class MyClass {
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;

IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string)p0);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_p0);
Expand Down Expand Up @@ -153,7 +153,7 @@ public partial class MyClass {
[Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")]
set {
const string __id = "set_Key.(Ljava/lang/String;)V";
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_value);
Expand Down Expand Up @@ -253,7 +253,7 @@ public partial class MyClass {
public virtual unsafe int GetCountForKey (string key)
{
const string __id = "GetCountForKey.(Ljava/lang/String;)I";
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down Expand Up @@ -303,7 +303,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class MyClass {
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;

IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string)p0);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_p0);
Expand Down Expand Up @@ -193,7 +193,7 @@ public partial class MyClass {
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
Expand Down Expand Up @@ -299,7 +299,7 @@ public partial class MyClass {
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static IntPtr id_ctor_Ljava_lang_String_;
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;

IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string)p0);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_p0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public virtual unsafe int GetCountForKey (string key)
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public virtual unsafe string Key {
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (bar_jfieldId == IntPtr.Zero)
bar_jfieldId = JNIEnv.GetFieldID (class_ref, "bar", "Ljava/lang/String;");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JNIEnv.SetField (((global::Java.Lang.Object) this).Handle, bar_jfieldId, native_value);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public string bar {
set {
if (bar_jfieldId == IntPtr.Zero)
bar_jfieldId = JNIEnv.GetFieldID (class_ref, "bar", "Ljava/lang/String;");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JNIEnv.SetField (((global::Java.Lang.Object) this).Handle, bar_jfieldId, native_value);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down Expand Up @@ -285,7 +285,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
set {
if (id_set_Key_Ljava_lang_String_ == IntPtr.Zero)
id_set_Key_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "set_Key", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args);
Expand Down Expand Up @@ -214,7 +214,7 @@ internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterf
{
if (id_GetCountForKey_Ljava_lang_String_ == IntPtr.Zero)
id_GetCountForKey_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "GetCountForKey", "(Ljava/lang/String;)I");
IntPtr native_key = JNIEnv.NewString (key);
IntPtr native_key = JNIEnv.NewString ((string)key);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_key);
var __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public virtual unsafe string UsePartial (int partial)
public static unsafe string UseThis (string this_)
{
const string __id = "useThis.(Ljava/lang/String;)Ljava/lang/String;";
IntPtr native_this = JNIEnv.NewString (this_);
IntPtr native_this = JNIEnv.NewString ((string)this_);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public unsafe FrameworkMediaCrypto () : base (IntPtr.Zero, JniHandleOwnership.Do
public unsafe bool RequiresSecureDecoderComponent (string p0)
{
const string __id = "requiresSecureDecoderComponent.(Ljava/lang/String;)Z";
IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string)p0);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_p0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public unsafe bool RequiresSecureDecoderComponent (string p0)
{
if (id_requiresSecureDecoderComponent_Ljava_lang_String_ == IntPtr.Zero)
id_requiresSecureDecoderComponent_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "requiresSecureDecoderComponent", "(Ljava/lang/String;)Z");
IntPtr native_p0 = JNIEnv.NewString (p0);
IntPtr native_p0 = JNIEnv.NewString ((string)p0);
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_p0);
var __ret = JNIEnv.CallBooleanMethod (((global::Java.Lang.Object) this).Handle, id_requiresSecureDecoderComponent_Ljava_lang_String_, __args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void n_VoidMethodWithParams_Ljava_lang_String_ILjava_lang_Object_ (IntPtr
public virtual unsafe void VoidMethodWithParams (string astring, int anint, global::Java.Lang.Object anObject)
{
const string __id = "VoidMethodWithParams.(Ljava/lang/String;ILjava/lang/Object;)V";
IntPtr native_astring = JNIEnv.NewString (astring);
IntPtr native_astring = JNIEnv.NewString ((string)astring);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [3];
__args [0] = new JniArgumentValue (native_astring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public override unsafe string SomeString {
[Register ("setSomeString", "(Ljava/lang/String;)V", "GetSetSomeString_Ljava_lang_String_Handler")]
set {
const string __id = "setSomeString.(Ljava/lang/String;)V";
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static unsafe string SomeString {
[Register ("setSomeString", "(Ljava/lang/String;)V", "")]
set {
const string __id = "setSomeString.(Ljava/lang/String;)V";
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public virtual unsafe string Object {
[Register ("SetObject", "(Ljava/lang/String;)V", "GetSetObject_Ljava_lang_String_Handler")]
set {
const string __id = "SetObject.(Ljava/lang/String;)V";
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static unsafe string UseThis (string this_)
{
if (id_useThis_Ljava_lang_String_ == IntPtr.Zero)
id_useThis_Ljava_lang_String_ = JNIEnv.GetStaticMethodID (class_ref, "useThis", "(Ljava/lang/String;)Ljava/lang/String;");
IntPtr native_this = JNIEnv.NewString (this_);
IntPtr native_this = JNIEnv.NewString ((string)this_);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public virtual unsafe void VoidMethodWithParams (string astring, int anint, glob
{
if (id_VoidMethodWithParams_Ljava_lang_String_ILjava_lang_Object_ == IntPtr.Zero)
id_VoidMethodWithParams_Ljava_lang_String_ILjava_lang_Object_ = JNIEnv.GetMethodID (class_ref, "VoidMethodWithParams", "(Ljava/lang/String;ILjava/lang/Object;)V");
IntPtr native_astring = JNIEnv.NewString (astring);
IntPtr native_astring = JNIEnv.NewString ((string)astring);
try {
JValue* __args = stackalloc JValue [3];
__args [0] = new JValue (native_astring);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public override unsafe string SomeString {
set {
if (id_setSomeString_Ljava_lang_String_ == IntPtr.Zero)
id_setSomeString_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "setSomeString", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static unsafe string SomeString {
set {
if (id_setSomeString_Ljava_lang_String_ == IntPtr.Zero)
id_setSomeString_Ljava_lang_String_ = JNIEnv.GetStaticMethodID (class_ref, "setSomeString", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public virtual unsafe string Object {
set {
if (id_SetObject_Ljava_lang_String_ == IntPtr.Zero)
id_SetObject_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "SetObject", "(Ljava/lang/String;)V");
IntPtr native_value = JNIEnv.NewString (value);
IntPtr native_value = JNIEnv.NewString ((string)value);
try {
JValue* __args = stackalloc JValue [1];
__args [0] = new JValue (native_value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public string[] PreCall (CodeGenerationOptions opt, string var_name)
};
}
return new[]{
$"IntPtr {native_name} = JNIEnv.NewString ({managed_name});",
$"IntPtr {native_name} = JNIEnv.NewString ((string{opt.NullableOperator}){managed_name});",
};
}

Expand Down

0 comments on commit 05eddd9

Please sign in to comment.