-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java Callable Wrappers via custom attributes #833
Comments
This is an interesting idea. One of the scenarios I've been hitting is as follows. We have the following Java interface which we want to bind. public interface SplitInstallStateUpdatedListener
implements StateUpdatedListener<SplitInstallSessionState> {
onStateUpdate(SplitInstallSessionState state)
} In order to bind this what tends to happen is we change the [JavaTypeParameters(new[] { "StateT" })]
[Register("com/google/android/play/core/listener/StateUpdatedListener", "", "Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerInvoker")]
public interface IStateUpdatedListener : IJavaObject, IDisposable, IJavaPeerable
{
[Register("onStateUpdate", "(Ljava/lang/Object;)V", "GetOnStateUpdate_Ljava_lang_Object_Handler:Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerInvoker, Xamarin.Google.Android.Play.Core")]
void OnStateUpdate(Java.Lang.Object p0);
} So we then try to "implement" this interface in an app public class Listener : Java.Lang.Object, ISplitInstallStateUpdatedListener
{
public void OnStateUpdate(Object p0)
{
}
} The problem starts when we JCW gets generated from the C# code. It will produce the following package crc64cbac1eb14a70596e;
public class Listener
extends java.lang.Object
implements
mono.android.IGCUserPeer,
com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener,
com.google.android.play.core.listener.StateUpdatedListener
{
/** @hide */
public static final String __md_methods;
static {
__md_methods =
"n_onStateUpdate:(Ljava/lang/Object;)V:GetOnStateUpdate_Ljava_lang_Object_Handler:Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerInvoker, Xamarin.Google.Android.Play.Core\n" +
"";
mono.android.Runtime.register ("DynamicAssetsExample.Listener, DynamicAssetsExample", Listener.class, __md_methods);
}
public Listener ()
{
super ();
if (getClass () == Listener.class)
mono.android.TypeManager.Activate ("DynamicAssetsExample.Listener, DynamicAssetsExample", "", this, new java.lang.Object[] { });
}
public void onStateUpdate (java.lang.Object p0)
{
n_onStateUpdate (p0);
}
private native void n_onStateUpdate (java.lang.Object p0);
private java.util.ArrayList refList;
public void monodroidAddReference (java.lang.Object obj)
{
if (refList == null)
refList = new java.util.ArrayList ();
refList.add (obj);
}
public void monodroidClearReferences ()
{
if (refList != null)
refList.clear ();
}
} and then the following error.
So part of this will work I think. The public void onStateUpdate (java.lang.Object p0) So perhaps in addition to this we need an additional attribute which can be placed either on Methods or Parameters to change the JCW type? |
We have the However, I don't think it'll solve your problem. Your problem is that, eventually, you'll have a Java API which accepts public class UsesListener {
public void method(StateUpdatedListener<SplitInstallSessionState> listener);
} Someone will want to call UsesListener.Method(new MyListener()); at which point they would also need to do "all this" as part of their :-( |
Java Callable Wrappers are (currently) generated by parsing an IL Type Definition for a
Java.Lang.Object
subclass (though see also Issue #540), and contain Java source which "mirror" the managed type, "forwarding" the base class, implemented interfaces, overridden methods, and[Export]
methods.It may be useful if the Java generation process could be extended via custom attributes, overriding the defaults.
Add the following two custom attributes:
and update https://github.com/xamarin/java.interop/tree/main/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers so that if the above attributes are present, they override the default behavior. This would allow:
which would generate the Java Callable Wrapper:
The text was updated successfully, but these errors were encountered: