-
Notifications
You must be signed in to change notification settings - Fork 64
[generator] Use DIM to support static interface methods. #487
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...Tests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteStaticInterfaceMethod.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| [Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| public abstract class MyInterface : Java.Lang.Object { | ||
|
|
||
| internal MyInterface () | ||
| { | ||
| } | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]" | ||
| [Register ("DoSomething", "()V", "")] | ||
| public static unsafe void DoSomething () | ||
| { | ||
| const string __id = "DoSomething.()V"; | ||
| try { | ||
| _members.StaticMethods.InvokeVoidMethod (__id, null); | ||
| } finally { | ||
| } | ||
| } | ||
|
|
||
|
|
||
| static new readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (MyInterface)); | ||
| } | ||
|
|
||
| [Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| [global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.")] | ||
| public abstract class MyInterfaceConsts : MyInterface { | ||
|
|
||
| private MyInterfaceConsts () | ||
| { | ||
| } | ||
| } | ||
|
|
||
| // Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" | ||
| [Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] | ||
| public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
| static new readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true); | ||
|
|
||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]" | ||
| [Register ("DoSomething", "()V", "")] | ||
| public static unsafe void DoSomething () | ||
| { | ||
| const string __id = "DoSomething.()V"; | ||
| try { | ||
| _members.StaticMethods.InvokeVoidMethod (__id, null); | ||
| } finally { | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| [global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { | ||
|
|
||
| internal static new readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker)); | ||
|
|
||
| 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; } | ||
| } | ||
|
|
||
| IntPtr class_ref; | ||
|
|
||
| public static IMyInterface GetObject (IntPtr handle, JniHandleOwnership transfer) | ||
| { | ||
| return global::Java.Lang.Object.GetObject<IMyInterface> (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), "java.code.IMyInterface")); | ||
| 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 IMyInterfaceInvoker (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); | ||
| } | ||
|
|
||
| } | ||
|
|
||
31 changes: 31 additions & 0 deletions
31
...sts/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteStaticInterfaceProperty.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" | ||
| [Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] | ||
| public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
| static new readonly JniPeerMembers _members = new JniPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true); | ||
|
|
||
| static unsafe int Value { | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Value' and count(parameter)=0]" | ||
| [Register ("get_Value", "()I", "Getget_ValueHandler")] | ||
| get { | ||
| const string __id = "get_Value.()I"; | ||
| try { | ||
| var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); | ||
| return __rm; | ||
| } finally { | ||
| } | ||
| } | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Value' and count(parameter)=1 and parameter[1][@type='int']]" | ||
| [Register ("set_Value", "(I)V", "Getset_Value_IHandler")] | ||
jpobst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set { | ||
| const string __id = "set_Value.(I)V"; | ||
| try { | ||
| JniArgumentValue* __args = stackalloc JniArgumentValue [1]; | ||
| __args [0] = new JniArgumentValue (value); | ||
| _members.StaticMethods.InvokeVoidMethod (__id, __args); | ||
| } finally { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
101 changes: 101 additions & 0 deletions
101
...sts/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteStaticInterfaceMethod.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| [Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| public abstract class MyInterface : Java.Lang.Object { | ||
|
|
||
| internal MyInterface () | ||
| { | ||
| } | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]" | ||
| [Register ("DoSomething", "()V", "")] | ||
| public static unsafe void DoSomething () | ||
| { | ||
| const string __id = "DoSomething.()V"; | ||
| try { | ||
| _members.StaticMethods.InvokeVoidMethod (__id, null); | ||
| } finally { | ||
| } | ||
| } | ||
|
|
||
|
|
||
| static new readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (MyInterface)); | ||
| } | ||
|
|
||
| [Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| [global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.")] | ||
| public abstract class MyInterfaceConsts : MyInterface { | ||
jpobst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private MyInterfaceConsts () | ||
| { | ||
| } | ||
| } | ||
|
|
||
| // Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" | ||
| [Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] | ||
| public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
| static new readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true); | ||
|
|
||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]" | ||
| [Register ("DoSomething", "()V", "")] | ||
| public static unsafe void DoSomething () | ||
| { | ||
| const string __id = "DoSomething.()V"; | ||
| try { | ||
| _members.StaticMethods.InvokeVoidMethod (__id, null); | ||
| } finally { | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| [global::Android.Runtime.Register ("java/code/IMyInterface", DoNotGenerateAcw=true)] | ||
| internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { | ||
|
|
||
| internal static new readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterfaceInvoker)); | ||
|
|
||
| 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; } | ||
| } | ||
|
|
||
| IntPtr class_ref; | ||
|
|
||
| public static IMyInterface GetObject (IntPtr handle, JniHandleOwnership transfer) | ||
| { | ||
| return global::Java.Lang.Object.GetObject<IMyInterface> (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), "java.code.IMyInterface")); | ||
| 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 IMyInterfaceInvoker (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); | ||
| } | ||
|
|
||
| } | ||
|
|
||
31 changes: 31 additions & 0 deletions
31
...s/Unit-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteStaticInterfaceProperty.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Metadata.xml XPath interface reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']" | ||
| [Register ("java/code/IMyInterface", "", "java.code.IMyInterfaceInvoker")] | ||
| public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
| static new readonly JniPeerMembers _members = new XAPeerMembers ("java/code/IMyInterface", typeof (IMyInterface), isInterface: true); | ||
|
|
||
| static unsafe int Value { | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='get_Value' and count(parameter)=0]" | ||
| [Register ("get_Value", "()I", "Getget_ValueHandler")] | ||
| get { | ||
| const string __id = "get_Value.()I"; | ||
| try { | ||
| var __rm = _members.StaticMethods.InvokeInt32Method (__id, null); | ||
| return __rm; | ||
| } finally { | ||
| } | ||
| } | ||
| // Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='set_Value' and count(parameter)=1 and parameter[1][@type='int']]" | ||
| [Register ("set_Value", "(I)V", "Getset_Value_IHandler")] | ||
| set { | ||
| const string __id = "set_Value.(I)V"; | ||
| try { | ||
| JniArgumentValue* __args = stackalloc JniArgumentValue [1]; | ||
| __args [0] = new JniArgumentValue (value); | ||
| _members.StaticMethods.InvokeVoidMethod (__id, __args); | ||
| } finally { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we emitting an empty
MyInterfaceConststype? If the interface had some constants, that would be one thing, but it doesn't...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
MyInterfaceConststype is always generated if we generate theMyInterfaceclass. It does not attempt to detect why we are writing aMyInterfaceclass.Logic for determining if we are writing a
MyInterfaceclass:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we alter that logic? Particularly considering that the generated type is
[Obsolete](lol?), and there's no reason for the type to exist in a C#8 default-interface-members world order?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically a break if an existing library enables DIM, so we discussed making these
[Obsolete(error:true)]so maybe eventually we could remove them. (For a separate PR.)