From 8a44bbdb3da65bab0f8c20fb5652e1454e21f839 Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Fri, 21 Feb 2020 09:17:16 -0600 Subject: [PATCH] [generator] Bind protected nested types. --- .../Xamarin.Test.PublicClass.cs | 88 +++++++++++++++++++ .../AccessModifiers/AccessModifiers.xml | 8 ++ .../Xamarin.Test.PublicClass.cs | 80 +++++++++++++++++ tools/generator/CodeGenerator.cs | 2 +- 4 files changed, 177 insertions(+), 1 deletion(-) diff --git a/tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicClass.cs b/tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicClass.cs index edac242f8..5a07663e5 100644 --- a/tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicClass.cs +++ b/tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicClass.cs @@ -9,6 +9,94 @@ namespace Xamarin.Test { [global::Android.Runtime.Register ("xamarin/test/PublicClass", DoNotGenerateAcw=true)] public partial class PublicClass : global::Java.Lang.Object { + // Metadata.xml XPath interface reference: path="/api/package[@name='xamarin.test']/interface[@name='PublicClass.ProtectedInterface']" + [Register ("xamarin/test/PublicClass$ProtectedInterface", "", "Xamarin.Test.PublicClass/IProtectedInterfaceInvoker")] + protected internal partial interface IProtectedInterface : IJavaObject, IJavaPeerable { + + // Metadata.xml XPath method reference: path="/api/package[@name='xamarin.test']/interface[@name='PublicClass.ProtectedInterface']/method[@name='foo' and count(parameter)=0]" + [Register ("foo", "()V", "GetFooHandler:Xamarin.Test.PublicClass/IProtectedInterfaceInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")] + void Foo (); + + } + + [global::Android.Runtime.Register ("xamarin/test/PublicClass$ProtectedInterface", DoNotGenerateAcw=true)] + internal partial class IProtectedInterfaceInvoker : global::Java.Lang.Object, IProtectedInterface { + + static readonly JniPeerMembers _members = new JniPeerMembers ("xamarin/test/PublicClass$ProtectedInterface", typeof (IProtectedInterfaceInvoker)); + + static IntPtr java_class_ref { + get { return _members.JniPeerType.PeerReference.Handle; } + } + + public override global::Java.Interop.JniPeerMembers JniPeerMembers { + get { return _members; } + } + + protected override IntPtr ThresholdClass { + get { return class_ref; } + } + + protected override global::System.Type ThresholdType { + get { return _members.ManagedPeerType; } + } + + new IntPtr class_ref; + + public static IProtectedInterface GetObject (IntPtr handle, JniHandleOwnership transfer) + { + return global::Java.Lang.Object.GetObject (handle, transfer); + } + + static IntPtr Validate (IntPtr handle) + { + if (!JNIEnv.IsInstanceOf (handle, java_class_ref)) + throw new InvalidCastException (string.Format ("Unable to convert instance of type '{0}' to type '{1}'.", + JNIEnv.GetClassNameFromInstance (handle), "xamarin.test.PublicClass.ProtectedInterface")); + return handle; + } + + protected override void Dispose (bool disposing) + { + if (this.class_ref != IntPtr.Zero) + JNIEnv.DeleteGlobalRef (this.class_ref); + this.class_ref = IntPtr.Zero; + base.Dispose (disposing); + } + + public IProtectedInterfaceInvoker (IntPtr handle, JniHandleOwnership transfer) : base (Validate (handle), transfer) + { + IntPtr local_ref = JNIEnv.GetObjectClass (((global::Java.Lang.Object) this).Handle); + this.class_ref = JNIEnv.NewGlobalRef (local_ref); + JNIEnv.DeleteLocalRef (local_ref); + } + + static Delegate cb_foo; +#pragma warning disable 0169 + static Delegate GetFooHandler () + { + if (cb_foo == null) + cb_foo = JNINativeWrapper.CreateDelegate ((Action) n_Foo); + return cb_foo; + } + + static void n_Foo (IntPtr jnienv, IntPtr native__this) + { + global::Xamarin.Test.PublicClass.IProtectedInterface __this = global::Java.Lang.Object.GetObject (jnienv, native__this, JniHandleOwnership.DoNotTransfer); + __this.Foo (); + } +#pragma warning restore 0169 + + IntPtr id_foo; + public unsafe void Foo () + { + if (id_foo == IntPtr.Zero) + id_foo = JNIEnv.GetMethodID (class_ref, "foo", "()V"); + JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_foo); + } + + } + + static readonly JniPeerMembers _members = new JniPeerMembers ("xamarin/test/PublicClass", typeof (PublicClass)); internal static new IntPtr class_ref { get { diff --git a/tests/generator-Tests/expected/AccessModifiers/AccessModifiers.xml b/tests/generator-Tests/expected/AccessModifiers/AccessModifiers.xml index aab5faeb3..cae0ae1fe 100644 --- a/tests/generator-Tests/expected/AccessModifiers/AccessModifiers.xml +++ b/tests/generator-Tests/expected/AccessModifiers/AccessModifiers.xml @@ -23,6 +23,11 @@ /* package */ static interface OnPressedChangeListener { void onPressedChanged (); } + + // This nested type should be generated because it is protected + protected interface ProtectedInterface { + void foo (); + } } --> @@ -33,6 +38,9 @@ + + +