From a730a4ffd8b4818bb6ea805cf4de7b60333b301d Mon Sep 17 00:00:00 2001 From: mblowey <5872539+mblowey@users.noreply.github.com> Date: Fri, 10 Apr 2020 00:50:23 -0400 Subject: [PATCH 1/2] Modified the generator tool so that it no longer adds a 'new' modifier to internal fields (like class_ref) when the class's base is in an external assembly. - This prevents a CS0109 warnings during binding generation. - Updated expected generator output files for existing tests. - Added two new tests that verify the expected output when the base class is in an external assembly and when the base class is in the same assembly as the derived class. --- Java.Interop.sln | 19 +- .../JavaInterop1/WriteClass.txt | 2 +- .../JavaInterop1/WriteClassExternalBase.txt | 337 +++++++++++++++ .../JavaInterop1/WriteClassInternalBase.txt | 337 +++++++++++++++ ...iteKotlinUnsignedArrayTypeMethodsClass.txt | 2 +- ...KotlinUnsignedArrayTypePropertiesClass.txt | 2 +- .../WriteKotlinUnsignedTypeMethodsClass.txt | 2 +- ...WriteKotlinUnsignedTypePropertiesClass.txt | 2 +- .../XAJavaInterop1/WriteClass.txt | 2 +- .../XAJavaInterop1/WriteClassExternalBase.txt | 337 +++++++++++++++ .../XAJavaInterop1/WriteClassInternalBase.txt | 337 +++++++++++++++ .../XamarinAndroid/WriteClass.txt | 4 +- .../XamarinAndroid/WriteClassExternalBase.txt | 392 ++++++++++++++++++ .../XamarinAndroid/WriteClassInternalBase.txt | 392 ++++++++++++++++++ .../Unit-Tests/CodeGeneratorTests.cs | 42 ++ .../Unit-Tests/SupportTypes.cs | 21 + .../CodeGenerator.cs | 15 +- 17 files changed, 2219 insertions(+), 26 deletions(-) create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt create mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt diff --git a/Java.Interop.sln b/Java.Interop.sln index 6cd82464e..499dcc396 100644 --- a/Java.Interop.sln +++ b/Java.Interop.sln @@ -5,13 +5,13 @@ VisualStudioVersion = 16.0.29424.173 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{C8F58966-94BF-407F-914A-8654F8B8AE3B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.JniMarshalMethodGenerator", "tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj", "{D1295A8F-4F42-461D-A046-564476C10002}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.JniMarshalMethodGenerator", "tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj", "{D1295A8F-4F42-461D-A046-564476C10002}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logcat-parse", "tools\logcat-parse\logcat-parse.csproj", "{7387E151-48E3-4885-B2CA-A74434A34045}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "logcat-parse", "tools\logcat-parse\logcat-parse.csproj", "{7387E151-48E3-4885-B2CA-A74434A34045}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "class-parse", "tools\class-parse\class-parse.csproj", "{38C762AB-8FD1-44DE-9855-26AAE7129DC3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "class-parse", "tools\class-parse\class-parse.csproj", "{38C762AB-8FD1-44DE-9855-26AAE7129DC3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "generator", "tools\generator\generator.csproj", "{D14A1B5C-2060-4930-92BE-F7190256C735}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generator", "tools\generator\generator.csproj", "{D14A1B5C-2060-4930-92BE-F7190256C735}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{4C173212-371D-45D8-BA83-9226194F48DC}" EndProject @@ -59,11 +59,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generator-Tests", "tests\ge EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{D5A93398-AEB1-49F3-89DC-3904A47DB0C7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello", "samples\Hello\Hello.csproj", "{F3ECB73D-9263-4E42-A5B4-3FC0D1D829F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hello", "samples\Hello\Hello.csproj", "{F3ECB73D-9263-4E42-A5B4-3FC0D1D829F9}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build-Tools", "Build-Tools", "{172B608B-E6F3-41CC-9949-203A76BA247C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jnienv-gen", "build-tools\jnienv-gen\jnienv-gen.csproj", "{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "jnienv-gen", "build-tools\jnienv-gen\jnienv-gen.csproj", "{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Java.Interop.NamingCustomAttributes", "src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.shproj", "{FE789F04-5E95-42C5-AEF1-E33F8DF06B3F}" EndProject @@ -73,7 +73,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Cecil", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Diagnostics", "src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj", "{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.JavaCallableWrappers-Tests", "tests\Java.Interop.Tools.JavaCallableWrappers-Tests\Java.Interop.Tools.JavaCallableWrappers-Tests.csproj", "{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}" EndProject @@ -89,8 +89,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "param-name-importer", "tool EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution - src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 4 - src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d1295a8f-4f42-461d-a046-564476c10002}*SharedItemsImports = 4 + src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5 + src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d1295a8f-4f42-461d-a046-564476c10002}*SharedItemsImports = 5 + src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d18fcf91-8876-48a0-a693-2dc1e7d3d80a}*SharedItemsImports = 5 src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{fe789f04-5e95-42c5-aef1-e33f8df06b3f}*SharedItemsImports = 13 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt index 8c6217d1b..4c7d4d3f8 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt new file mode 100644 index 000000000..e82fa8243 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt @@ -0,0 +1,337 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); + internal static IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } + } + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [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); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + public virtual unsafe int GetCountForKey (string key) + { + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt new file mode 100644 index 000000000..263b921ae --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt @@ -0,0 +1,337 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); + internal static new IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } + } + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [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); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + public virtual unsafe int GetCountForKey (string key) + { + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypeMethodsClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypeMethodsClass.txt index 47247bb27..6dc50ca2f 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypeMethodsClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypeMethodsClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypePropertiesClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypePropertiesClass.txt index d6f7093ca..3f2241de6 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypePropertiesClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedArrayTypePropertiesClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypeMethodsClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypeMethodsClass.txt index b03f98129..6526f804a 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypeMethodsClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypeMethodsClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypePropertiesClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypePropertiesClass.txt index 113e4c242..f7fb28ed9 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypePropertiesClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteKotlinUnsignedTypePropertiesClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt index 5936c52fc..cb6feb756 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt new file mode 100644 index 000000000..f4f0f0e7a --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt @@ -0,0 +1,337 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); + internal static IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } + } + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [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); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + public virtual unsafe int GetCountForKey (string key) + { + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt new file mode 100644 index 000000000..e3d3054a8 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt @@ -0,0 +1,337 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); + internal static new IntPtr class_ref { + get { + return _members.JniPeerType.PeerReference.Handle; + } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "()V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, null); + } finally { + } + } + + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + const string __id = "(Ljava/lang/String;)V"; + + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_p0); + var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); + SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); + _members.InstanceMethods.FinishCreateInstance (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + const string __id = "get_Count.()I"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + const string __id = "set_Count.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + const string __id = "get_Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [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); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_value); + _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + const string __id = "get_StaticCount.()I"; + try { + var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); + return __rm; + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + const string __id = "set_StaticCount.(I)V"; + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (value); + _members.StaticMethods.InvokeVoidMethod (__id, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + public virtual unsafe int GetCountForKey (string key) + { + const string __id = "GetCountForKey.(Ljava/lang/String;)I"; + IntPtr native_key = JNIEnv.NewString (key); + try { + JniArgumentValue* __args = stackalloc JniArgumentValue [1]; + __args [0] = new JniArgumentValue (native_key); + var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); + return __rm; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + const string __id = "Key.()Ljava/lang/String;"; + try { + var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); + return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + const string __id = "StaticMethod.()V"; + try { + _members.StaticMethods.InvokeVoidMethod (__id, null); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClass.txt index 4e9c67151..d0233db96 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClass.txt @@ -2,8 +2,8 @@ [global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] public partial class MyClass { - internal static new IntPtr java_class_handle; - internal static new IntPtr class_ref { + internal static IntPtr java_class_handle; + internal static IntPtr class_ref { get { return JNIEnv.FindClass ("java/code/MyClass", ref java_class_handle); } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt new file mode 100644 index 000000000..edcab106f --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt @@ -0,0 +1,392 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + internal static IntPtr java_class_handle; + internal static IntPtr class_ref { + get { + return JNIEnv.FindClass ("java/code/MyClass", ref java_class_handle); + } + } + + protected override IntPtr ThresholdClass { + get { return class_ref; } + } + + protected override global::System.Type ThresholdType { + get { return typeof (MyClass); } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + static IntPtr id_ctor; + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + if (((object) this).GetType () != typeof (MyClass)) { + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "()V"), + JniHandleOwnership.TransferLocalRef); + global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "()V"); + return; + } + + if (id_ctor == IntPtr.Zero) + id_ctor = JNIEnv.GetMethodID (class_ref, "", "()V"); + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor), + JniHandleOwnership.TransferLocalRef); + JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor); + } finally { + } + } + + static IntPtr id_ctor_Ljava_lang_String_; + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_p0); + if (((object) this).GetType () != typeof (MyClass)) { + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "(Ljava/lang/String;)V", __args), + JniHandleOwnership.TransferLocalRef); + global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "(Ljava/lang/String;)V", __args); + return; + } + + if (id_ctor_Ljava_lang_String_ == IntPtr.Zero) + id_ctor_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "", "(Ljava/lang/String;)V"); + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor_Ljava_lang_String_, __args), + JniHandleOwnership.TransferLocalRef); + JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor_Ljava_lang_String_, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + static IntPtr id_get_Count; + static IntPtr id_set_Count_I; + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + if (id_get_Count == IntPtr.Zero) + id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); + else + return JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Count", "()I")); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + if (id_set_Count_I == IntPtr.Zero) + id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + + if (((object) this).GetType () == ThresholdType) + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); + else + JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Count", "(I)V"), __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + static IntPtr id_get_Key; + static IntPtr id_set_Key_Ljava_lang_String_; + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + else + return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] + 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); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + + if (((object) this).GetType () == ThresholdType) + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + else + JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Key", "(Ljava/lang/String;)V"), __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + static IntPtr id_get_StaticCount; + static IntPtr id_set_StaticCount_I; + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + if (id_get_StaticCount == IntPtr.Zero) + id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I"); + try { + return JNIEnv.CallStaticIntMethod (class_ref, id_get_StaticCount); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + if (id_set_StaticCount_I == IntPtr.Zero) + id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V"); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallStaticVoidMethod (class_ref, id_set_StaticCount_I, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + static IntPtr id_GetCountForKey_Ljava_lang_String_; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + 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); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + + int __ret; + if (((object) this).GetType () == ThresholdType) + __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + else + __ret = JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "GetCountForKey", "(Ljava/lang/String;)I"), __args); + return __ret; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + static IntPtr id_Key; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); + else + return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + static IntPtr id_StaticMethod; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + if (id_StaticMethod == IntPtr.Zero) + id_StaticMethod = JNIEnv.GetStaticMethodID (class_ref, "StaticMethod", "()V"); + try { + JNIEnv.CallStaticVoidMethod (class_ref, id_StaticMethod); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt new file mode 100644 index 000000000..b198d5a66 --- /dev/null +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt @@ -0,0 +1,392 @@ +// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" +[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] +public partial class MyClass : Java.Lang.Object { + + internal static new IntPtr java_class_handle; + internal static new IntPtr class_ref { + get { + return JNIEnv.FindClass ("java/code/MyClass", ref java_class_handle); + } + } + + protected override IntPtr ThresholdClass { + get { return class_ref; } + } + + protected override global::System.Type ThresholdType { + get { return typeof (MyClass); } + } + + protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} + + static IntPtr id_ctor; + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" + [Register (".ctor", "()V", "")] + unsafe MyClass () + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + try { + if (((object) this).GetType () != typeof (MyClass)) { + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "()V"), + JniHandleOwnership.TransferLocalRef); + global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "()V"); + return; + } + + if (id_ctor == IntPtr.Zero) + id_ctor = JNIEnv.GetMethodID (class_ref, "", "()V"); + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor), + JniHandleOwnership.TransferLocalRef); + JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor); + } finally { + } + } + + static IntPtr id_ctor_Ljava_lang_String_; + // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register (".ctor", "(Ljava/lang/String;)V", "")] + unsafe MyClass (string p0) + : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) + { + if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) + return; + + IntPtr native_p0 = JNIEnv.NewString (p0); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_p0); + if (((object) this).GetType () != typeof (MyClass)) { + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "(Ljava/lang/String;)V", __args), + JniHandleOwnership.TransferLocalRef); + global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "(Ljava/lang/String;)V", __args); + return; + } + + if (id_ctor_Ljava_lang_String_ == IntPtr.Zero) + id_ctor_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "", "(Ljava/lang/String;)V"); + SetHandle ( + global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor_Ljava_lang_String_, __args), + JniHandleOwnership.TransferLocalRef); + JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor_Ljava_lang_String_, __args); + } finally { + JNIEnv.DeleteLocalRef (native_p0); + } + } + + static Delegate cb_get_Count; +#pragma warning disable 0169 + static Delegate Getget_CountHandler () + { + if (cb_get_Count == null) + cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); + return cb_get_Count; + } + + static int n_get_Count (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.Count; + } +#pragma warning restore 0169 + + static Delegate cb_set_Count_I; +#pragma warning disable 0169 + static Delegate Getset_Count_IHandler () + { + if (cb_set_Count_I == null) + cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); + return cb_set_Count_I; + } + + static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Count = value; + } +#pragma warning restore 0169 + + static IntPtr id_get_Count; + static IntPtr id_set_Count_I; + public virtual unsafe int Count { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" + [Register ("get_Count", "()I", "Getget_CountHandler")] + get { + if (id_get_Count == IntPtr.Zero) + id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); + else + return JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Count", "()I")); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] + set { + if (id_set_Count_I == IntPtr.Zero) + id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + + if (((object) this).GetType () == ThresholdType) + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); + else + JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Count", "(I)V"), __args); + } finally { + } + } + } + + static Delegate cb_get_Key; +#pragma warning disable 0169 + static Delegate Getget_KeyHandler () + { + if (cb_get_Key == null) + cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); + return cb_get_Key; + } + + static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key); + } +#pragma warning restore 0169 + + static Delegate cb_set_Key_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate Getset_Key_Ljava_lang_String_Handler () + { + if (cb_set_Key_Ljava_lang_String_ == null) + cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); + return cb_set_Key_Ljava_lang_String_; + } + + static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); + __this.Key = value; + } +#pragma warning restore 0169 + + static IntPtr id_get_Key; + static IntPtr id_set_Key_Ljava_lang_String_; + public virtual unsafe string Key { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" + [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] + get { + if (id_get_Key == IntPtr.Zero) + id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); + else + return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] + 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); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_value); + + if (((object) this).GetType () == ThresholdType) + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); + else + JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Key", "(Ljava/lang/String;)V"), __args); + } finally { + JNIEnv.DeleteLocalRef (native_value); + } + } + } + + static IntPtr id_get_StaticCount; + static IntPtr id_set_StaticCount_I; + public static unsafe int StaticCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" + [Register ("get_StaticCount", "()I", "")] + get { + if (id_get_StaticCount == IntPtr.Zero) + id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I"); + try { + return JNIEnv.CallStaticIntMethod (class_ref, id_get_StaticCount); + } finally { + } + } + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_StaticCount", "(I)V", "")] + set { + if (id_set_StaticCount_I == IntPtr.Zero) + id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V"); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (value); + JNIEnv.CallStaticVoidMethod (class_ref, id_set_StaticCount_I, __args); + } finally { + } + } + } + + static Delegate cb_get_AbstractCount; +#pragma warning disable 0169 + static Delegate Getget_AbstractCountHandler () + { + if (cb_get_AbstractCount == null) + cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); + return cb_get_AbstractCount; + } + + static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return __this.AbstractCount; + } +#pragma warning restore 0169 + + static Delegate cb_set_AbstractCount_I; +#pragma warning disable 0169 + static Delegate Getset_AbstractCount_IHandler () + { + if (cb_set_AbstractCount_I == null) + cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); + return cb_set_AbstractCount_I; + } + + static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractCount = value; + } +#pragma warning restore 0169 + + public abstract int AbstractCount { + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" + [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" + [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; + } + + static Delegate cb_GetCountForKey_Ljava_lang_String_; +#pragma warning disable 0169 + static Delegate GetGetCountForKey_Ljava_lang_String_Handler () + { + if (cb_GetCountForKey_Ljava_lang_String_ == null) + cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); + return cb_GetCountForKey_Ljava_lang_String_; + } + + static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); + int __ret = __this.GetCountForKey (key); + return __ret; + } +#pragma warning restore 0169 + + static IntPtr id_GetCountForKey_Ljava_lang_String_; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" + [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] + 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); + try { + JValue* __args = stackalloc JValue [1]; + __args [0] = new JValue (native_key); + + int __ret; + if (((object) this).GetType () == ThresholdType) + __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); + else + __ret = JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "GetCountForKey", "(Ljava/lang/String;)I"), __args); + return __ret; + } finally { + JNIEnv.DeleteLocalRef (native_key); + } + } + + static Delegate cb_Key; +#pragma warning disable 0169 + static Delegate GetKeyHandler () + { + if (cb_Key == null) + cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); + return cb_Key; + } + + static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + return JNIEnv.NewString (__this.Key ()); + } +#pragma warning restore 0169 + + static IntPtr id_Key; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" + [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] + public virtual unsafe string Key () + { + if (id_Key == IntPtr.Zero) + id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); + try { + + if (((object) this).GetType () == ThresholdType) + return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); + else + return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); + } finally { + } + } + + static IntPtr id_StaticMethod; + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" + [Register ("StaticMethod", "()V", "")] + public static unsafe void StaticMethod () + { + if (id_StaticMethod == IntPtr.Zero) + id_StaticMethod = JNIEnv.GetStaticMethodID (class_ref, "StaticMethod", "()V"); + try { + JNIEnv.CallStaticVoidMethod (class_ref, id_StaticMethod); + } finally { + } + } + + static Delegate cb_AbstractMethod; +#pragma warning disable 0169 + static Delegate GetAbstractMethodHandler () + { + if (cb_AbstractMethod == null) + cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); + return cb_AbstractMethod; + } + + static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) + { + var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.AbstractMethod (); + } +#pragma warning restore 0169 + + // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" + [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] + public abstract void AbstractMethod (); + +} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs index 2ea239e11..c57b61428 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs @@ -1016,5 +1016,47 @@ public void WritePropertyExplicitInterfaceParameterName () var result = writer.ToString ().NormalizeLineEndings (); Assert.False (result.Contains ("p0")); } + + [Test] + public void WriteClassExternalBase () + { + // Tests the case where a class inherits from a class that is not in the same assembly. + // Specifically, the internal class_ref field does NOT need the new modifier. + // - This prevents a CS0109 warning from being generated. + + options.SymbolTable.AddType (new TestClass(null, "Java.Lang.Object")); + + var @class = SupportTypeBuilder.CreateClassWithBase ("java.code.MyClass", "Java.Lang.Object", options); + @class.Validate (options, new GenericParameterDefinitionList (), generator.Context); + + generator.Context.ContextTypes.Push (@class); + generator.WriteClass (@class, string.Empty, new GenerationInfo ("", "", "MyAssembly")); + generator.Context.ContextTypes.Pop (); + + Assert.AreEqual (GetTargetedExpected (nameof (WriteClassExternalBase)), writer.ToString ().NormalizeLineEndings ()); + } + + [Test] + public void WriteClassInternalBase () + { + // Tests the case where a class inherits from Java.Lang.Object and is in the same assembly. + // Specifically, the internal class_ref field does need the new modifier. + // - This prevents a CS0108 warning from being generated. + + options.SymbolTable.AddType (new TestClass (null, "Java.Lang.Object")); + + var @class = SupportTypeBuilder.CreateClassWithBase ("java.code.MyClass", "Java.Lang.Object", options); + @class.Validate (options, new GenericParameterDefinitionList (), generator.Context); + + // FromXml is set to true when a class is set to true when the api.xml contains an entry for the class. + // Therefore, if a class's base has FromXml set to true, the class and its base will be in the same C# assembly. + @class.BaseGen.FromXml = true; + + generator.Context.ContextTypes.Push (@class); + generator.WriteClass (@class, string.Empty, new GenerationInfo ("", "", "MyAssembly")); + generator.Context.ContextTypes.Pop (); + + Assert.AreEqual (GetTargetedExpected (nameof (WriteClassInternalBase)), writer.ToString ().NormalizeLineEndings ()); + } } } diff --git a/tests/generator-Tests/Unit-Tests/SupportTypes.cs b/tests/generator-Tests/Unit-Tests/SupportTypes.cs index ed9f4cb1d..5df474357 100644 --- a/tests/generator-Tests/Unit-Tests/SupportTypes.cs +++ b/tests/generator-Tests/Unit-Tests/SupportTypes.cs @@ -236,6 +236,27 @@ public static TestClass CreateClass (string className, CodeGenerationOptions opt return @class; } + public static TestClass CreateClassWithBase(string className, string baseName, CodeGenerationOptions options) + { + var @class = new TestClass (baseName, className); + + var ctor_name = className.Contains ('.') ? className.Substring (className.LastIndexOf ('.')) : className; + @class.Ctors.Add (CreateConstructor (@class, ctor_name, options)); + @class.Ctors.Add (CreateConstructor (@class, ctor_name, options, new Parameter ("p0", "java.lang.String", "string", false))); + + @class.Properties.Add (CreateProperty (@class, "Count", "int", options)); + @class.Properties.Add (CreateProperty (@class, "Key", "java.lang.String", options)); + @class.Properties.Add (CreateProperty (@class, "StaticCount", "int", options, true)); + @class.Properties.Add (CreateProperty (@class, "AbstractCount", "int", options, false, true)); + + @class.Methods.Add (CreateMethod (@class, "GetCountForKey", options, "int", false, parameters: new Parameter ("key", "java.lang.String", "string", false))); + @class.Methods.Add (CreateMethod (@class, "Key", options, "java.lang.String")); + @class.Methods.Add (CreateMethod (@class, "StaticMethod", options, "void", true)); + @class.Methods.Add (CreateMethod (@class, "AbstractMethod", options, "void", false, true)); + + return @class; + } + public static TestClass CreateClassWithProperty (string className, string classJavaName, string propertyName, string propertyType, CodeGenerationOptions options) { var @class = new TestClass (className, classJavaName); diff --git a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs index 66d469ac0..0b593bd36 100644 --- a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs +++ b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs @@ -126,15 +126,12 @@ public void WriteClass (ClassGen @class, string indent, GenerationInfo gen_info) writer.WriteLine (); } - bool requireNew = @class.InheritsObject; - if (!requireNew) { - for (var bg = @class.BaseGen; bg != null && bg is ClassGen classGen && classGen.FromXml; bg = bg.BaseGen) { - if (bg.InheritsObject) { - requireNew = true; - break; - } - } - } + // @class.InheritsObject is true unless @class refers to java.lang.Object or java.lang.Throwable. (see ClassGen constructor) + // If @class's base class is defined in the same api.xml file, then it requires the new keyword to overshadow the internal + // members of its baseclass since the two classes will be defined in the same assembly. If the base class is not from the + // same api.xml file, the new keyword is not needed because the internal access modifier already prevents it from being seen. + bool baseFromSameAssembly = @class?.BaseGen?.FromXml ?? false; + bool requireNew = @class.InheritsObject && baseFromSameAssembly; WriteClassHandle (@class, indent, requireNew); WriteClassConstructors (@class, indent + "\t"); From 1c4dfc8285224ace9709a24f9d248e1302215bea Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Thu, 23 Apr 2020 11:09:36 -0500 Subject: [PATCH 2/2] Simplify unit tests. --- Java.Interop.sln | 19 +- .../JavaInterop1/WriteClassExternalBase.txt | 337 --------------- .../JavaInterop1/WriteClassInternalBase.txt | 337 --------------- .../XAJavaInterop1-NRT/WriteClass.txt | 2 +- .../XAJavaInterop1/WriteClassExternalBase.txt | 337 --------------- .../XAJavaInterop1/WriteClassInternalBase.txt | 337 --------------- .../XamarinAndroid/WriteClassExternalBase.txt | 392 ------------------ .../XamarinAndroid/WriteClassInternalBase.txt | 392 ------------------ .../Unit-Tests/CodeGeneratorTests.cs | 14 +- .../Unit-Tests/SupportTypes.cs | 25 +- 10 files changed, 21 insertions(+), 2171 deletions(-) delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt delete mode 100644 tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt diff --git a/Java.Interop.sln b/Java.Interop.sln index 499dcc396..6cd82464e 100644 --- a/Java.Interop.sln +++ b/Java.Interop.sln @@ -5,13 +5,13 @@ VisualStudioVersion = 16.0.29424.173 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{C8F58966-94BF-407F-914A-8654F8B8AE3B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.JniMarshalMethodGenerator", "tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj", "{D1295A8F-4F42-461D-A046-564476C10002}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.JniMarshalMethodGenerator", "tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj", "{D1295A8F-4F42-461D-A046-564476C10002}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "logcat-parse", "tools\logcat-parse\logcat-parse.csproj", "{7387E151-48E3-4885-B2CA-A74434A34045}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logcat-parse", "tools\logcat-parse\logcat-parse.csproj", "{7387E151-48E3-4885-B2CA-A74434A34045}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "class-parse", "tools\class-parse\class-parse.csproj", "{38C762AB-8FD1-44DE-9855-26AAE7129DC3}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "class-parse", "tools\class-parse\class-parse.csproj", "{38C762AB-8FD1-44DE-9855-26AAE7129DC3}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generator", "tools\generator\generator.csproj", "{D14A1B5C-2060-4930-92BE-F7190256C735}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "generator", "tools\generator\generator.csproj", "{D14A1B5C-2060-4930-92BE-F7190256C735}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{4C173212-371D-45D8-BA83-9226194F48DC}" EndProject @@ -59,11 +59,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generator-Tests", "tests\ge EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{D5A93398-AEB1-49F3-89DC-3904A47DB0C7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hello", "samples\Hello\Hello.csproj", "{F3ECB73D-9263-4E42-A5B4-3FC0D1D829F9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hello", "samples\Hello\Hello.csproj", "{F3ECB73D-9263-4E42-A5B4-3FC0D1D829F9}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build-Tools", "Build-Tools", "{172B608B-E6F3-41CC-9949-203A76BA247C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "jnienv-gen", "build-tools\jnienv-gen\jnienv-gen.csproj", "{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jnienv-gen", "build-tools\jnienv-gen\jnienv-gen.csproj", "{6410DA0F-5E14-4FC0-9AEE-F4C542C96C7A}" EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Java.Interop.NamingCustomAttributes", "src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.shproj", "{FE789F04-5E95-42C5-AEF1-E33F8DF06B3F}" EndProject @@ -73,7 +73,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Cecil", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.Diagnostics", "src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj", "{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.JavaCallableWrappers-Tests", "tests\Java.Interop.Tools.JavaCallableWrappers-Tests\Java.Interop.Tools.JavaCallableWrappers-Tests.csproj", "{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}" EndProject @@ -89,9 +89,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "param-name-importer", "tool EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution - src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 5 - src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d1295a8f-4f42-461d-a046-564476c10002}*SharedItemsImports = 5 - src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d18fcf91-8876-48a0-a693-2dc1e7d3d80a}*SharedItemsImports = 5 + src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{58b564a1-570d-4da2-b02d-25bddb1a9f4f}*SharedItemsImports = 4 + src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{d1295a8f-4f42-461d-a046-564476c10002}*SharedItemsImports = 4 src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems*{fe789f04-5e95-42c5-aef1-e33f8df06b3f}*SharedItemsImports = 13 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt deleted file mode 100644 index e82fa8243..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassExternalBase.txt +++ /dev/null @@ -1,337 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static IntPtr class_ref { - get { - return _members.JniPeerType.PeerReference.Handle; - } - } - - public override global::Java.Interop.JniPeerMembers JniPeerMembers { - get { return _members; } - } - - protected override IntPtr ThresholdClass { - get { return _members.JniPeerType.PeerReference.Handle; } - } - - protected override global::System.Type ThresholdType { - get { return _members.ManagedPeerType; } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "()V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, null); - } finally { - } - } - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "(Ljava/lang/String;)V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_p0); - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - const string __id = "get_Count.()I"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - const string __id = "set_Count.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - const string __id = "get_Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [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); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - const string __id = "get_StaticCount.()I"; - try { - var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - const string __id = "set_StaticCount.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.StaticMethods.InvokeVoidMethod (__id, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - public virtual unsafe int GetCountForKey (string key) - { - const string __id = "GetCountForKey.(Ljava/lang/String;)I"; - IntPtr native_key = JNIEnv.NewString (key); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_key); - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); - return __rm; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - const string __id = "Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - const string __id = "StaticMethod.()V"; - try { - _members.StaticMethods.InvokeVoidMethod (__id, null); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt deleted file mode 100644 index 263b921ae..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteClassInternalBase.txt +++ /dev/null @@ -1,337 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - static readonly JniPeerMembers _members = new JniPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { - get { - return _members.JniPeerType.PeerReference.Handle; - } - } - - public override global::Java.Interop.JniPeerMembers JniPeerMembers { - get { return _members; } - } - - protected override IntPtr ThresholdClass { - get { return _members.JniPeerType.PeerReference.Handle; } - } - - protected override global::System.Type ThresholdType { - get { return _members.ManagedPeerType; } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "()V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, null); - } finally { - } - } - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "(Ljava/lang/String;)V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_p0); - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - const string __id = "get_Count.()I"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - const string __id = "set_Count.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - const string __id = "get_Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [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); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - const string __id = "get_StaticCount.()I"; - try { - var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - const string __id = "set_StaticCount.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.StaticMethods.InvokeVoidMethod (__id, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - public virtual unsafe int GetCountForKey (string key) - { - const string __id = "GetCountForKey.(Ljava/lang/String;)I"; - IntPtr native_key = JNIEnv.NewString (key); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_key); - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); - return __rm; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - const string __id = "Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - const string __id = "StaticMethod.()V"; - try { - _members.StaticMethods.InvokeVoidMethod (__id, null); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt index 01ea5c4e6..fd438b72d 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1-NRT/WriteClass.txt @@ -3,7 +3,7 @@ public partial class MyClass { static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { + internal static IntPtr class_ref { get { return _members.JniPeerType.PeerReference.Handle; } diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt deleted file mode 100644 index f4f0f0e7a..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassExternalBase.txt +++ /dev/null @@ -1,337 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static IntPtr class_ref { - get { - return _members.JniPeerType.PeerReference.Handle; - } - } - - public override global::Java.Interop.JniPeerMembers JniPeerMembers { - get { return _members; } - } - - protected override IntPtr ThresholdClass { - get { return _members.JniPeerType.PeerReference.Handle; } - } - - protected override global::System.Type ThresholdType { - get { return _members.ManagedPeerType; } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "()V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, null); - } finally { - } - } - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "(Ljava/lang/String;)V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_p0); - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - const string __id = "get_Count.()I"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - const string __id = "set_Count.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - const string __id = "get_Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [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); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - const string __id = "get_StaticCount.()I"; - try { - var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - const string __id = "set_StaticCount.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.StaticMethods.InvokeVoidMethod (__id, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - public virtual unsafe int GetCountForKey (string key) - { - const string __id = "GetCountForKey.(Ljava/lang/String;)I"; - IntPtr native_key = JNIEnv.NewString (key); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_key); - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); - return __rm; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - const string __id = "Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - const string __id = "StaticMethod.()V"; - try { - _members.StaticMethods.InvokeVoidMethod (__id, null); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt deleted file mode 100644 index e3d3054a8..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteClassInternalBase.txt +++ /dev/null @@ -1,337 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - static readonly JniPeerMembers _members = new XAPeerMembers ("java/code/MyClass", typeof (MyClass)); - internal static new IntPtr class_ref { - get { - return _members.JniPeerType.PeerReference.Handle; - } - } - - public override global::Java.Interop.JniPeerMembers JniPeerMembers { - get { return _members; } - } - - protected override IntPtr ThresholdClass { - get { return _members.JniPeerType.PeerReference.Handle; } - } - - protected override global::System.Type ThresholdType { - get { return _members.ManagedPeerType; } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "()V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), null); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, null); - } finally { - } - } - - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - const string __id = "(Ljava/lang/String;)V"; - - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_p0); - var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args); - SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef); - _members.InstanceMethods.FinishCreateInstance (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - const string __id = "get_Count.()I"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - const string __id = "set_Count.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - const string __id = "get_Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [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); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_value); - _members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - const string __id = "get_StaticCount.()I"; - try { - var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); - return __rm; - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - const string __id = "set_StaticCount.(I)V"; - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (value); - _members.StaticMethods.InvokeVoidMethod (__id, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - public virtual unsafe int GetCountForKey (string key) - { - const string __id = "GetCountForKey.(Ljava/lang/String;)I"; - IntPtr native_key = JNIEnv.NewString (key); - try { - JniArgumentValue* __args = stackalloc JniArgumentValue [1]; - __args [0] = new JniArgumentValue (native_key); - var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, __args); - return __rm; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - const string __id = "Key.()Ljava/lang/String;"; - try { - var __rm = _members.InstanceMethods.InvokeVirtualObjectMethod (__id, this, null); - return JNIEnv.GetString (__rm.Handle, JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - const string __id = "StaticMethod.()V"; - try { - _members.StaticMethods.InvokeVoidMethod (__id, null); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt deleted file mode 100644 index edcab106f..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassExternalBase.txt +++ /dev/null @@ -1,392 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - internal static IntPtr java_class_handle; - internal static IntPtr class_ref { - get { - return JNIEnv.FindClass ("java/code/MyClass", ref java_class_handle); - } - } - - protected override IntPtr ThresholdClass { - get { return class_ref; } - } - - protected override global::System.Type ThresholdType { - get { return typeof (MyClass); } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - static IntPtr id_ctor; - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - if (((object) this).GetType () != typeof (MyClass)) { - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "()V"), - JniHandleOwnership.TransferLocalRef); - global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "()V"); - return; - } - - if (id_ctor == IntPtr.Zero) - id_ctor = JNIEnv.GetMethodID (class_ref, "", "()V"); - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor), - JniHandleOwnership.TransferLocalRef); - JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor); - } finally { - } - } - - static IntPtr id_ctor_Ljava_lang_String_; - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_p0); - if (((object) this).GetType () != typeof (MyClass)) { - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "(Ljava/lang/String;)V", __args), - JniHandleOwnership.TransferLocalRef); - global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "(Ljava/lang/String;)V", __args); - return; - } - - if (id_ctor_Ljava_lang_String_ == IntPtr.Zero) - id_ctor_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "", "(Ljava/lang/String;)V"); - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor_Ljava_lang_String_, __args), - JniHandleOwnership.TransferLocalRef); - JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor_Ljava_lang_String_, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - static IntPtr id_get_Count; - static IntPtr id_set_Count_I; - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - if (id_get_Count == IntPtr.Zero) - id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); - else - return JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Count", "()I")); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - if (id_set_Count_I == IntPtr.Zero) - id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (value); - - if (((object) this).GetType () == ThresholdType) - JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); - else - JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Count", "(I)V"), __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - static IntPtr id_get_Key; - static IntPtr id_set_Key_Ljava_lang_String_; - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - if (id_get_Key == IntPtr.Zero) - id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); - else - return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] - 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); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_value); - - if (((object) this).GetType () == ThresholdType) - JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); - else - JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Key", "(Ljava/lang/String;)V"), __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - static IntPtr id_get_StaticCount; - static IntPtr id_set_StaticCount_I; - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - if (id_get_StaticCount == IntPtr.Zero) - id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I"); - try { - return JNIEnv.CallStaticIntMethod (class_ref, id_get_StaticCount); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - if (id_set_StaticCount_I == IntPtr.Zero) - id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V"); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (value); - JNIEnv.CallStaticVoidMethod (class_ref, id_set_StaticCount_I, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - static IntPtr id_GetCountForKey_Ljava_lang_String_; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - 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); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_key); - - int __ret; - if (((object) this).GetType () == ThresholdType) - __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); - else - __ret = JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "GetCountForKey", "(Ljava/lang/String;)I"), __args); - return __ret; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - static IntPtr id_Key; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - if (id_Key == IntPtr.Zero) - id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); - else - return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - static IntPtr id_StaticMethod; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - if (id_StaticMethod == IntPtr.Zero) - id_StaticMethod = JNIEnv.GetStaticMethodID (class_ref, "StaticMethod", "()V"); - try { - JNIEnv.CallStaticVoidMethod (class_ref, id_StaticMethod); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt b/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt deleted file mode 100644 index b198d5a66..000000000 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorExpectedResults/XamarinAndroid/WriteClassInternalBase.txt +++ /dev/null @@ -1,392 +0,0 @@ -// Metadata.xml XPath class reference: path="/api/package[@name='java.code']/class[@name='MyClass']" -[global::Android.Runtime.Register ("java/code/MyClass", DoNotGenerateAcw=true)] -public partial class MyClass : Java.Lang.Object { - - internal static new IntPtr java_class_handle; - internal static new IntPtr class_ref { - get { - return JNIEnv.FindClass ("java/code/MyClass", ref java_class_handle); - } - } - - protected override IntPtr ThresholdClass { - get { return class_ref; } - } - - protected override global::System.Type ThresholdType { - get { return typeof (MyClass); } - } - - protected MyClass (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {} - - static IntPtr id_ctor; - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=0]" - [Register (".ctor", "()V", "")] - unsafe MyClass () - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - try { - if (((object) this).GetType () != typeof (MyClass)) { - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "()V"), - JniHandleOwnership.TransferLocalRef); - global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "()V"); - return; - } - - if (id_ctor == IntPtr.Zero) - id_ctor = JNIEnv.GetMethodID (class_ref, "", "()V"); - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor), - JniHandleOwnership.TransferLocalRef); - JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor); - } finally { - } - } - - static IntPtr id_ctor_Ljava_lang_String_; - // Metadata.xml XPath constructor reference: path="/api/package[@name='java.code']/class[@name='MyClass']/constructor[@name='MyClass' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register (".ctor", "(Ljava/lang/String;)V", "")] - unsafe MyClass (string p0) - : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer) - { - if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero) - return; - - IntPtr native_p0 = JNIEnv.NewString (p0); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_p0); - if (((object) this).GetType () != typeof (MyClass)) { - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (((object) this).GetType (), "(Ljava/lang/String;)V", __args), - JniHandleOwnership.TransferLocalRef); - global::Android.Runtime.JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, "(Ljava/lang/String;)V", __args); - return; - } - - if (id_ctor_Ljava_lang_String_ == IntPtr.Zero) - id_ctor_Ljava_lang_String_ = JNIEnv.GetMethodID (class_ref, "", "(Ljava/lang/String;)V"); - SetHandle ( - global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor_Ljava_lang_String_, __args), - JniHandleOwnership.TransferLocalRef); - JNIEnv.FinishCreateInstance (((global::Java.Lang.Object) this).Handle, class_ref, id_ctor_Ljava_lang_String_, __args); - } finally { - JNIEnv.DeleteLocalRef (native_p0); - } - } - - static Delegate cb_get_Count; -#pragma warning disable 0169 - static Delegate Getget_CountHandler () - { - if (cb_get_Count == null) - cb_get_Count = JNINativeWrapper.CreateDelegate ((Func) n_get_Count); - return cb_get_Count; - } - - static int n_get_Count (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.Count; - } -#pragma warning restore 0169 - - static Delegate cb_set_Count_I; -#pragma warning disable 0169 - static Delegate Getset_Count_IHandler () - { - if (cb_set_Count_I == null) - cb_set_Count_I = JNINativeWrapper.CreateDelegate ((Action) n_set_Count_I); - return cb_set_Count_I; - } - - static void n_set_Count_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.Count = value; - } -#pragma warning restore 0169 - - static IntPtr id_get_Count; - static IntPtr id_set_Count_I; - public virtual unsafe int Count { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Count' and count(parameter)=0]" - [Register ("get_Count", "()I", "Getget_CountHandler")] - get { - if (id_get_Count == IntPtr.Zero) - id_get_Count = JNIEnv.GetMethodID (class_ref, "get_Count", "()I"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_get_Count); - else - return JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Count", "()I")); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Count' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_Count", "(I)V", "Getset_Count_IHandler")] - set { - if (id_set_Count_I == IntPtr.Zero) - id_set_Count_I = JNIEnv.GetMethodID (class_ref, "set_Count", "(I)V"); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (value); - - if (((object) this).GetType () == ThresholdType) - JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Count_I, __args); - else - JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Count", "(I)V"), __args); - } finally { - } - } - } - - static Delegate cb_get_Key; -#pragma warning disable 0169 - static Delegate Getget_KeyHandler () - { - if (cb_get_Key == null) - cb_get_Key = JNINativeWrapper.CreateDelegate ((Func) n_get_Key); - return cb_get_Key; - } - - static IntPtr n_get_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key); - } -#pragma warning restore 0169 - - static Delegate cb_set_Key_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate Getset_Key_Ljava_lang_String_Handler () - { - if (cb_set_Key_Ljava_lang_String_ == null) - cb_set_Key_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Action) n_set_Key_Ljava_lang_String_); - return cb_set_Key_Ljava_lang_String_; - } - - static void n_set_Key_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var value = JNIEnv.GetString (native_value, JniHandleOwnership.DoNotTransfer); - __this.Key = value; - } -#pragma warning restore 0169 - - static IntPtr id_get_Key; - static IntPtr id_set_Key_Ljava_lang_String_; - public virtual unsafe string Key { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_Key' and count(parameter)=0]" - [Register ("get_Key", "()Ljava/lang/String;", "Getget_KeyHandler")] - get { - if (id_get_Key == IntPtr.Zero) - id_get_Key = JNIEnv.GetMethodID (class_ref, "get_Key", "()Ljava/lang/String;"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_get_Key), JniHandleOwnership.TransferLocalRef); - else - return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "get_Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_Key' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("set_Key", "(Ljava/lang/String;)V", "Getset_Key_Ljava_lang_String_Handler")] - 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); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_value); - - if (((object) this).GetType () == ThresholdType) - JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_set_Key_Ljava_lang_String_, __args); - else - JNIEnv.CallNonvirtualVoidMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "set_Key", "(Ljava/lang/String;)V"), __args); - } finally { - JNIEnv.DeleteLocalRef (native_value); - } - } - } - - static IntPtr id_get_StaticCount; - static IntPtr id_set_StaticCount_I; - public static unsafe int StaticCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_StaticCount' and count(parameter)=0]" - [Register ("get_StaticCount", "()I", "")] - get { - if (id_get_StaticCount == IntPtr.Zero) - id_get_StaticCount = JNIEnv.GetStaticMethodID (class_ref, "get_StaticCount", "()I"); - try { - return JNIEnv.CallStaticIntMethod (class_ref, id_get_StaticCount); - } finally { - } - } - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_StaticCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_StaticCount", "(I)V", "")] - set { - if (id_set_StaticCount_I == IntPtr.Zero) - id_set_StaticCount_I = JNIEnv.GetStaticMethodID (class_ref, "set_StaticCount", "(I)V"); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (value); - JNIEnv.CallStaticVoidMethod (class_ref, id_set_StaticCount_I, __args); - } finally { - } - } - } - - static Delegate cb_get_AbstractCount; -#pragma warning disable 0169 - static Delegate Getget_AbstractCountHandler () - { - if (cb_get_AbstractCount == null) - cb_get_AbstractCount = JNINativeWrapper.CreateDelegate ((Func) n_get_AbstractCount); - return cb_get_AbstractCount; - } - - static int n_get_AbstractCount (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return __this.AbstractCount; - } -#pragma warning restore 0169 - - static Delegate cb_set_AbstractCount_I; -#pragma warning disable 0169 - static Delegate Getset_AbstractCount_IHandler () - { - if (cb_set_AbstractCount_I == null) - cb_set_AbstractCount_I = JNINativeWrapper.CreateDelegate ((Action) n_set_AbstractCount_I); - return cb_set_AbstractCount_I; - } - - static void n_set_AbstractCount_I (IntPtr jnienv, IntPtr native__this, int value) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractCount = value; - } -#pragma warning restore 0169 - - public abstract int AbstractCount { - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='get_AbstractCount' and count(parameter)=0]" - [Register ("get_AbstractCount", "()I", "Getget_AbstractCountHandler")] get; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='set_AbstractCount' and count(parameter)=1 and parameter[1][@type='int']]" - [Register ("set_AbstractCount", "(I)V", "Getset_AbstractCount_IHandler")] set; - } - - static Delegate cb_GetCountForKey_Ljava_lang_String_; -#pragma warning disable 0169 - static Delegate GetGetCountForKey_Ljava_lang_String_Handler () - { - if (cb_GetCountForKey_Ljava_lang_String_ == null) - cb_GetCountForKey_Ljava_lang_String_ = JNINativeWrapper.CreateDelegate ((Func) n_GetCountForKey_Ljava_lang_String_); - return cb_GetCountForKey_Ljava_lang_String_; - } - - static int n_GetCountForKey_Ljava_lang_String_ (IntPtr jnienv, IntPtr native__this, IntPtr native_key) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - var key = JNIEnv.GetString (native_key, JniHandleOwnership.DoNotTransfer); - int __ret = __this.GetCountForKey (key); - return __ret; - } -#pragma warning restore 0169 - - static IntPtr id_GetCountForKey_Ljava_lang_String_; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='GetCountForKey' and count(parameter)=1 and parameter[1][@type='java.lang.String']]" - [Register ("GetCountForKey", "(Ljava/lang/String;)I", "GetGetCountForKey_Ljava_lang_String_Handler")] - 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); - try { - JValue* __args = stackalloc JValue [1]; - __args [0] = new JValue (native_key); - - int __ret; - if (((object) this).GetType () == ThresholdType) - __ret = JNIEnv.CallIntMethod (((global::Java.Lang.Object) this).Handle, id_GetCountForKey_Ljava_lang_String_, __args); - else - __ret = JNIEnv.CallNonvirtualIntMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "GetCountForKey", "(Ljava/lang/String;)I"), __args); - return __ret; - } finally { - JNIEnv.DeleteLocalRef (native_key); - } - } - - static Delegate cb_Key; -#pragma warning disable 0169 - static Delegate GetKeyHandler () - { - if (cb_Key == null) - cb_Key = JNINativeWrapper.CreateDelegate ((Func) n_Key); - return cb_Key; - } - - static IntPtr n_Key (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - return JNIEnv.NewString (__this.Key ()); - } -#pragma warning restore 0169 - - static IntPtr id_Key; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='Key' and count(parameter)=0]" - [Register ("Key", "()Ljava/lang/String;", "GetKeyHandler")] - public virtual unsafe string Key () - { - if (id_Key == IntPtr.Zero) - id_Key = JNIEnv.GetMethodID (class_ref, "Key", "()Ljava/lang/String;"); - try { - - if (((object) this).GetType () == ThresholdType) - return JNIEnv.GetString (JNIEnv.CallObjectMethod (((global::Java.Lang.Object) this).Handle, id_Key), JniHandleOwnership.TransferLocalRef); - else - return JNIEnv.GetString (JNIEnv.CallNonvirtualObjectMethod (((global::Java.Lang.Object) this).Handle, ThresholdClass, JNIEnv.GetMethodID (ThresholdClass, "Key", "()Ljava/lang/String;")), JniHandleOwnership.TransferLocalRef); - } finally { - } - } - - static IntPtr id_StaticMethod; - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='StaticMethod' and count(parameter)=0]" - [Register ("StaticMethod", "()V", "")] - public static unsafe void StaticMethod () - { - if (id_StaticMethod == IntPtr.Zero) - id_StaticMethod = JNIEnv.GetStaticMethodID (class_ref, "StaticMethod", "()V"); - try { - JNIEnv.CallStaticVoidMethod (class_ref, id_StaticMethod); - } finally { - } - } - - static Delegate cb_AbstractMethod; -#pragma warning disable 0169 - static Delegate GetAbstractMethodHandler () - { - if (cb_AbstractMethod == null) - cb_AbstractMethod = JNINativeWrapper.CreateDelegate ((Action) n_AbstractMethod); - return cb_AbstractMethod; - } - - static void n_AbstractMethod (IntPtr jnienv, IntPtr native__this) - { - var __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); - __this.AbstractMethod (); - } -#pragma warning restore 0169 - - // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/class[@name='MyClass']/method[@name='AbstractMethod' and count(parameter)=0]" - [Register ("AbstractMethod", "()V", "GetAbstractMethodHandler")] - public abstract void AbstractMethod (); - -} diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs index c57b61428..44edc2110 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs @@ -1024,16 +1024,18 @@ public void WriteClassExternalBase () // Specifically, the internal class_ref field does NOT need the new modifier. // - This prevents a CS0109 warning from being generated. - options.SymbolTable.AddType (new TestClass(null, "Java.Lang.Object")); + options.SymbolTable.AddType (new TestClass (null, "Java.Lang.Object")); - var @class = SupportTypeBuilder.CreateClassWithBase ("java.code.MyClass", "Java.Lang.Object", options); + var @class = SupportTypeBuilder.CreateClass ("java.code.MyClass", options, "Java.Lang.Object"); @class.Validate (options, new GenericParameterDefinitionList (), generator.Context); generator.Context.ContextTypes.Push (@class); generator.WriteClass (@class, string.Empty, new GenerationInfo ("", "", "MyAssembly")); generator.Context.ContextTypes.Pop (); - Assert.AreEqual (GetTargetedExpected (nameof (WriteClassExternalBase)), writer.ToString ().NormalizeLineEndings ()); + var result = writer.ToString ().NormalizeLineEndings (); + Assert.True (result.Contains ("internal static IntPtr class_ref")); + Assert.False (result.Contains ("internal static new IntPtr class_ref")); } [Test] @@ -1045,7 +1047,7 @@ public void WriteClassInternalBase () options.SymbolTable.AddType (new TestClass (null, "Java.Lang.Object")); - var @class = SupportTypeBuilder.CreateClassWithBase ("java.code.MyClass", "Java.Lang.Object", options); + var @class = SupportTypeBuilder.CreateClass ("java.code.MyClass", options, "Java.Lang.Object"); @class.Validate (options, new GenericParameterDefinitionList (), generator.Context); // FromXml is set to true when a class is set to true when the api.xml contains an entry for the class. @@ -1056,7 +1058,9 @@ public void WriteClassInternalBase () generator.WriteClass (@class, string.Empty, new GenerationInfo ("", "", "MyAssembly")); generator.Context.ContextTypes.Pop (); - Assert.AreEqual (GetTargetedExpected (nameof (WriteClassInternalBase)), writer.ToString ().NormalizeLineEndings ()); + var result = writer.ToString ().NormalizeLineEndings (); + Assert.True (result.Contains ("internal static new IntPtr class_ref")); + Assert.False (result.Contains ("internal static IntPtr class_ref")); } } } diff --git a/tests/generator-Tests/Unit-Tests/SupportTypes.cs b/tests/generator-Tests/Unit-Tests/SupportTypes.cs index 5df474357..a4e4b5335 100644 --- a/tests/generator-Tests/Unit-Tests/SupportTypes.cs +++ b/tests/generator-Tests/Unit-Tests/SupportTypes.cs @@ -215,30 +215,9 @@ public TestInterface (string argsType, string javaName) : base (new TestBaseSupp static class SupportTypeBuilder { - public static TestClass CreateClass (string className, CodeGenerationOptions options) + public static TestClass CreateClass (string className, CodeGenerationOptions options, string baseClass = "Object") { - var @class = new TestClass ("Object", className); - - var ctor_name = className.Contains ('.') ? className.Substring (className.LastIndexOf ('.')) : className; - @class.Ctors.Add (CreateConstructor (@class, ctor_name, options)); - @class.Ctors.Add (CreateConstructor (@class, ctor_name, options, new Parameter ("p0", "java.lang.String", "string", false))); - - @class.Properties.Add (CreateProperty (@class, "Count", "int", options)); - @class.Properties.Add (CreateProperty (@class, "Key", "java.lang.String", options)); - @class.Properties.Add (CreateProperty (@class, "StaticCount", "int", options, true)); - @class.Properties.Add (CreateProperty (@class, "AbstractCount", "int", options, false, true)); - - @class.Methods.Add (CreateMethod (@class, "GetCountForKey", options, "int", false, parameters: new Parameter ("key", "java.lang.String", "string", false))); - @class.Methods.Add (CreateMethod (@class, "Key", options, "java.lang.String")); - @class.Methods.Add (CreateMethod (@class, "StaticMethod", options, "void", true)); - @class.Methods.Add (CreateMethod (@class, "AbstractMethod", options, "void", false, true)); - - return @class; - } - - public static TestClass CreateClassWithBase(string className, string baseName, CodeGenerationOptions options) - { - var @class = new TestClass (baseName, className); + var @class = new TestClass (baseClass, className); var ctor_name = className.Contains ('.') ? className.Substring (className.LastIndexOf ('.')) : className; @class.Ctors.Add (CreateConstructor (@class, ctor_name, options));