-
Notifications
You must be signed in to change notification settings - Fork 60
[generator] Ensure non-constant static interface fields are generated as interface properties. #831
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
126 changes: 126 additions & 0 deletions
126
...Unit-Tests/CodeGeneratorExpectedResults/JavaInterop1/WriteInterfaceFieldAsDimProperty.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,126 @@ | ||
[Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
public abstract class MyInterface : Java.Lang.Object { | ||
internal MyInterface () | ||
{ | ||
} | ||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NATIVE_VISUAL_ID']" | ||
[Register ("EGL_NATIVE_VISUAL_ID")] | ||
public const int EglNativeVisualId = (int) 12334; | ||
|
||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NO_SURFACE']" | ||
[Register ("EGL_NO_SURFACE")] | ||
public static int EglNoSurface { | ||
get { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
var __v = _members.StaticFields.GetInt32Value (__id); | ||
return __v; | ||
} | ||
set { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
try { | ||
_members.StaticFields.SetValue (__id, value); | ||
} finally { | ||
} | ||
} | ||
} | ||
|
||
static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/MyInterface", typeof (MyInterface)); | ||
|
||
} | ||
|
||
[Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
[global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.", error: true)] | ||
public abstract class MyInterfaceConsts : MyInterface { | ||
private MyInterfaceConsts () | ||
{ | ||
} | ||
|
||
} | ||
|
||
// Metadata.xml XPath interface reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']" | ||
[Register ("com/xamarin/android/MyInterface", "", "Com.Xamarin.Android.IMyInterfaceInvoker")] | ||
public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
private static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/MyInterface", typeof (IMyInterface), isInterface: true); | ||
|
||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NO_SURFACE']" | ||
[Register ("EGL_NO_SURFACE")] | ||
public static int EglNoSurface { | ||
get { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
var __v = _members.StaticFields.GetInt32Value (__id); | ||
return __v; | ||
} | ||
set { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
try { | ||
_members.StaticFields.SetValue (__id, value); | ||
} finally { | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
[global::Android.Runtime.Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { | ||
static readonly JniPeerMembers _members = new JniPeerMembers ("com/xamarin/android/MyInterface", typeof (IMyInterfaceInvoker)); | ||
|
||
static IntPtr java_class_ref { | ||
get { return _members.JniPeerType.PeerReference.Handle; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
public override global::Java.Interop.JniPeerMembers JniPeerMembers { | ||
get { return _members; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
protected override IntPtr ThresholdClass { | ||
get { return class_ref; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
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 ($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'com.xamarin.android.MyInterface'."); | ||
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); | ||
} | ||
|
||
} |
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
126 changes: 126 additions & 0 deletions
126
...it-Tests/CodeGeneratorExpectedResults/XAJavaInterop1/WriteInterfaceFieldAsDimProperty.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,126 @@ | ||
[Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
public abstract class MyInterface : Java.Lang.Object { | ||
internal MyInterface () | ||
{ | ||
} | ||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NATIVE_VISUAL_ID']" | ||
[Register ("EGL_NATIVE_VISUAL_ID")] | ||
public const int EglNativeVisualId = (int) 12334; | ||
|
||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NO_SURFACE']" | ||
[Register ("EGL_NO_SURFACE")] | ||
public static int EglNoSurface { | ||
get { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
var __v = _members.StaticFields.GetInt32Value (__id); | ||
return __v; | ||
} | ||
set { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
try { | ||
_members.StaticFields.SetValue (__id, value); | ||
} finally { | ||
} | ||
} | ||
} | ||
|
||
static readonly JniPeerMembers _members = new XAPeerMembers ("com/xamarin/android/MyInterface", typeof (MyInterface)); | ||
|
||
} | ||
|
||
[Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
[global::System.Obsolete ("Use the 'MyInterface' type. This type will be removed in a future release.", error: true)] | ||
public abstract class MyInterfaceConsts : MyInterface { | ||
private MyInterfaceConsts () | ||
{ | ||
} | ||
|
||
} | ||
|
||
// Metadata.xml XPath interface reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']" | ||
[Register ("com/xamarin/android/MyInterface", "", "Com.Xamarin.Android.IMyInterfaceInvoker")] | ||
public partial interface IMyInterface : IJavaObject, IJavaPeerable { | ||
private static readonly JniPeerMembers _members = new XAPeerMembers ("com/xamarin/android/MyInterface", typeof (IMyInterface), isInterface: true); | ||
|
||
|
||
// Metadata.xml XPath field reference: path="/api/package[@name='com.xamarin.android']/interface[@name='MyInterface']/field[@name='EGL_NO_SURFACE']" | ||
[Register ("EGL_NO_SURFACE")] | ||
public static int EglNoSurface { | ||
get { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
var __v = _members.StaticFields.GetInt32Value (__id); | ||
return __v; | ||
} | ||
set { | ||
const string __id = "EGL_NO_SURFACE.I"; | ||
|
||
try { | ||
_members.StaticFields.SetValue (__id, value); | ||
} finally { | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
[global::Android.Runtime.Register ("com/xamarin/android/MyInterface", DoNotGenerateAcw=true)] | ||
internal partial class IMyInterfaceInvoker : global::Java.Lang.Object, IMyInterface { | ||
static readonly JniPeerMembers _members = new XAPeerMembers ("com/xamarin/android/MyInterface", typeof (IMyInterfaceInvoker)); | ||
|
||
static IntPtr java_class_ref { | ||
get { return _members.JniPeerType.PeerReference.Handle; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
public override global::Java.Interop.JniPeerMembers JniPeerMembers { | ||
get { return _members; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
protected override IntPtr ThresholdClass { | ||
get { return class_ref; } | ||
} | ||
|
||
[global::System.Diagnostics.DebuggerBrowsable (global::System.Diagnostics.DebuggerBrowsableState.Never)] | ||
[global::System.ComponentModel.EditorBrowsable (global::System.ComponentModel.EditorBrowsableState.Never)] | ||
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 ($"Unable to convert instance of type '{JNIEnv.GetClassNameFromInstance (handle)}' to type 'com.xamarin.android.MyInterface'."); | ||
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); | ||
} | ||
|
||
} |
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
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.
Shouldn't this interface declaration also contain:
I would expect the
IMyInterface
type to "mirror"/contain the same members as theMyInterface
type, yetIMyInterface.EglNativeVisualId
doesn't exist.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.
Interface constants are gated behind
-lang-features=interface-constants
, which isn't enabled in this test suite.I went back and forth on this and decided that "static interface fields" falls more under
default-interface-methods
thaninterface-constants
. DIM is poorly named and really means "default AND static interface members" in this context.