-
Notifications
You must be signed in to change notification settings - Fork 564
[Mono.Android] Hide "internal" members of JLO from IDEs. #4583
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| ### Tidier IntelliSense suggestions for Java.Lang.Object subclasses | ||
|
|
||
| `Java.Lang.Object` contains several properties and methods that are | ||
| required to be `public` to support bindings, but are not intended | ||
| to be called by users. Use `[EditorBrowser]` to hide them from | ||
| IntelliSense, making it easier to find useful members. | ||
|
|
||
| [IntelliSense cleanup)[images/4583.png] | ||
|
|
||
| ### Issues fixed | ||
|
|
||
| #### IDE compatibility | ||
|
|
||
| * [GitHub 4582](https://github.com/xamarin/xamarin-android/issues/4582): | ||
| Some `Java.Lang.Object` properties and methods like `Handle` and | ||
| `PeerReference` appeared in IntelliSense suggestions even though they were | ||
| primarily intended for use only in generated code. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| using Java.Interop; | ||
|
|
||
| using Android.Runtime; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace Java.Lang { | ||
|
|
||
|
|
@@ -91,21 +93,27 @@ internal void SetHandleOnDeserialized (StreamingContext context) | |
| } | ||
|
|
||
| #if JAVA_INTEROP | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public int JniIdentityHashCode { | ||
| get {return (int) key_handle;} | ||
| } | ||
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public JniObjectReference PeerReference { | ||
| get { | ||
| return new JniObjectReference (handle, (JniObjectReferenceType) handle_type); | ||
| } | ||
| } | ||
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public virtual JniPeerMembers JniPeerMembers { | ||
| get { return _members; } | ||
| } | ||
| #endif // JAVA_INTEROP | ||
|
|
||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public IntPtr Handle { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this also hide usage of private Java.Lang.Object foo;
//...
if (foo != null && foo.Handle != IntPtr.Zero) {
//...
}If so, maybe we shouldn't hide Xamarin.Forms uses
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it would hide But that's just an assumption and it's certainly up for discussion.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also might use |
||
| get { | ||
| if (weak_handle != IntPtr.Zero) | ||
|
|
@@ -115,10 +123,14 @@ public IntPtr Handle { | |
| } | ||
| } | ||
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| protected virtual IntPtr ThresholdClass { | ||
| get { return Class.Object; } | ||
| } | ||
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| protected virtual System.Type ThresholdType { | ||
| get { return typeof (Java.Lang.Object); } | ||
| } | ||
|
|
@@ -154,6 +166,7 @@ void IJavaPeerable.DisposeUnlessReferenced () | |
| } | ||
| } | ||
|
|
||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public void UnregisterFromRuntime () | ||
| { | ||
| JNIEnv.AndroidValueManager.RemovePeer (this, key_handle); | ||
|
|
@@ -231,6 +244,7 @@ internal static void Dispose (IJavaPeerable instance, ref IntPtr handle, IntPtr | |
| } | ||
| } | ||
|
|
||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| protected void SetHandle (IntPtr value, JniHandleOwnership transfer) | ||
| { | ||
| JNIEnv.AndroidValueManager.AddPeer (this, value, transfer, out handle); | ||
|
|
@@ -287,6 +301,7 @@ internal static IJavaPeerable GetObject (IntPtr handle, JniHandleOwnership trans | |
| return Java.Interop.TypeManager.CreateInstance (handle, transfer, type); | ||
| } | ||
|
|
||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public T[] ToArray<T>() | ||
| { | ||
| return JNIEnv.GetArray<T>(Handle); | ||
|
|
||
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.
I would think that when debugging you would want something to designate "object identity", e.g. to easily answer "are these two variables referring to the same instance"?
Is this (still?) a desirable/useful feature? If so, what property would best be expose to the debugger?
JniIdentityHashCodeis useful if there are *separateJava.Lang.Objectinstances wrapping the same Java instance, whileHandleandPeerReferenceare good for seeing distinct wrappers.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.
Agree, but just wondering whether that couldn't be implemented in VS debugger the same way it is for .NET objects? This way we wouldn't have to check complex ids and hashes and it would feel more native to devs imo.
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.
I didn't know that was a feature that existed.
That said, I assume that Make Object ID only works for identical instances. If you have two different C# instances which wrap the same Java instance -- presumably a rare but still possible scenario -- then Make Object ID wouldn't help.
JniIdentityHashCodecould.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.
Well that's not exactly what I mean... I mean if there could be added a new similar functionality, probably another context menu option specialized for this usecase, something like Make Java object ID that wouldn't care about the .NET instance but about the native Java instance probably using the mentioned
JniIdentityHashCodeproperty. That would make looking for Java instance equality much easier compared to writing down some hash codes or so. I've heard something that in .NET 5 there should me a more native interoperability with Java (and I believe that Java.Interop is the thing to be used for that?) so if that's true, this change would benefit not only Xamarin.Android users.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.
I suspect the primary reason .NET has
Make Object IDis because .NET objects do not inherently have an ID and thus you cannot tell if 2 objects are the same. We already have that information easily available with these fields. In essence, they had to build a workaround for something we already have.Adding
Make Java object IDfor both VS2019 and VSMac would be a decent amount of work for a different team (Android IDE team). I suspect it will be placed in their backlog at much lower priority than the other tasks they have and probably never implemented.As such, let's keep these properties visible to the debugger. Overall this is still a good win by cleaning up the IntelliSense dropdown and some of the Debugger window.
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.
You're right, the effort wouldn't be worth the outcome especially since it's imo something devs don't do really often.