-
Notifications
You must be signed in to change notification settings - Fork 63
[generator] Support default interface methods. #459
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
54cd216
[generator] Support default interface methods.
jpobst ea8e9d6
[generator] Invalid DIM methods should not invalidate the interface.
jpobst 9fad1dc
[generator] Prevent DIM from creating "virtual sealed" methods.
jpobst aa28dc2
[generator] DIM connectors are located on the interface, not the impl…
jpobst a72ce30
[generator] Prohibit DIM use with codegen-target=XamarinAndroid .
jpobst 12cc41b
[generator] Add a unit test for interface invoker with DIM.
jpobst 26d3bb2
[generator] Call DIM methods as Virtual rather than Nonvirtual.
jpobst c971122
[generator] Remove old refactored property generation code.
jpobst bd8d019
[generator] Remove unneeded DIM check.
jpobst 16def29
[generator] Remove unncessary IJavaPeerable cast.
jpobst 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
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
117 changes: 81 additions & 36 deletions
117
tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
9 changes: 4 additions & 5 deletions
9
...s/XamarinAndroid/WriteInterfaceMethod.txt → ...WriteInterfaceRedeclaredDefaultMethod.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
77 changes: 77 additions & 0 deletions
77
...it-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteDefaultInterfaceMethodInvoker.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,77 @@ | ||
[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); | ||
} | ||
|
||
static Delegate cb_DoDeclaration; | ||
#pragma warning disable 0169 | ||
static Delegate GetDoDeclarationHandler () | ||
{ | ||
if (cb_DoDeclaration == null) | ||
cb_DoDeclaration = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_DoDeclaration); | ||
return cb_DoDeclaration; | ||
} | ||
|
||
static void n_DoDeclaration (IntPtr jnienv, IntPtr native__this) | ||
{ | ||
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); | ||
__this.DoDeclaration (); | ||
} | ||
#pragma warning restore 0169 | ||
|
||
IntPtr id_DoDeclaration; | ||
public unsafe void DoDeclaration () | ||
{ | ||
if (id_DoDeclaration == IntPtr.Zero) | ||
id_DoDeclaration = JNIEnv.GetMethodID (class_ref, "DoDeclaration", "()V"); | ||
JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_DoDeclaration); | ||
} | ||
|
||
} | ||
|
34 changes: 34 additions & 0 deletions
34
...ests/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultMethod.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,34 @@ | ||
// 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)); | ||
|
||
static Delegate cb_DoSomething; | ||
#pragma warning disable 0169 | ||
static Delegate GetDoSomethingHandler () | ||
{ | ||
if (cb_DoSomething == null) | ||
cb_DoSomething = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_DoSomething); | ||
return cb_DoSomething; | ||
} | ||
|
||
static void n_DoSomething (IntPtr jnienv, IntPtr native__this) | ||
{ | ||
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); | ||
__this.DoSomething (); | ||
} | ||
#pragma warning restore 0169 | ||
|
||
// Metadata.xml XPath method reference: path="/api/package[@name='java.code']/interface[@name='IMyInterface']/method[@name='DoSomething' and count(parameter)=0]" | ||
[Register ("DoSomething", "()V", "GetDoSomethingHandler:java.code.IMyInterface, MyAssembly")] | ||
virtual unsafe void DoSomething () | ||
{ | ||
const string __id = "DoSomething.()V"; | ||
try { | ||
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, null); | ||
} finally { | ||
} | ||
} | ||
|
||
} | ||
|
63 changes: 63 additions & 0 deletions
63
...ts/Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceDefaultProperty.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,63 @@ | ||
// 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)); | ||
|
||
static Delegate cb_get_Value; | ||
#pragma warning disable 0169 | ||
static Delegate Getget_ValueHandler () | ||
{ | ||
if (cb_get_Value == null) | ||
cb_get_Value = JNINativeWrapper.CreateDelegate ((Func<IntPtr, IntPtr, int>) n_get_Value); | ||
return cb_get_Value; | ||
} | ||
|
||
static int n_get_Value (IntPtr jnienv, IntPtr native__this) | ||
{ | ||
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); | ||
return __this.Value; | ||
} | ||
#pragma warning restore 0169 | ||
|
||
static Delegate cb_set_Value_I; | ||
#pragma warning disable 0169 | ||
static Delegate Getset_Value_IHandler () | ||
{ | ||
if (cb_set_Value_I == null) | ||
cb_set_Value_I = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr, int>) n_set_Value_I); | ||
return cb_set_Value_I; | ||
} | ||
|
||
static void n_set_Value_I (IntPtr jnienv, IntPtr native__this, int value) | ||
{ | ||
java.code.IMyInterface __this = global::Java.Lang.Object.GetObject<java.code.IMyInterface> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); | ||
__this.Value = value; | ||
} | ||
#pragma warning restore 0169 | ||
|
||
virtual 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:java.code.IMyInterface, MyAssembly")] | ||
get { | ||
const string __id = "get_Value.()I"; | ||
try { | ||
var __rm = _members.InstanceMethods.InvokeVirtualInt32Method (__id, this, 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:java.code.IMyInterface, MyAssembly")] | ||
set { | ||
const string __id = "set_Value.(I)V"; | ||
try { | ||
JniArgumentValue* __args = stackalloc JniArgumentValue [1]; | ||
__args [0] = new JniArgumentValue (value); | ||
_members.InstanceMethods.InvokeVirtualVoidMethod (__id, this, __args); | ||
} finally { | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.