-
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
Conversation
2188fc6 to
36a246a
Compare
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public IntPtr 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.
Would this also hide usage of Handle like:
private Java.Lang.Object foo;
//...
if (foo != null && foo.Handle != IntPtr.Zero) {
//...
}If so, maybe we shouldn't hide Handle as developers might often use it?
Xamarin.Forms uses Handle in these extension methods a lot:
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.
Yes, it would hide Handle in that case (from Intellisense). My gut says users wouldn't be using Handle if they are writing applications or libraries. (The authors of XF itself are a special case.)
But that's just an assumption and it's certainly up for discussion.
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 also might use Handle if you are working with JNI directly? Some folks might do that?
| #if JAVA_INTEROP | ||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] | ||
| [EditorBrowsable (EditorBrowsableState.Never)] | ||
| public int JniIdentityHashCode { |
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? JniIdentityHashCode is useful if there are *separate Java.Lang.Object instances wrapping the same Java instance, while Handle and PeerReference are 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. JniIdentityHashCode could.
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 JniIdentityHashCode property. 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 ID is 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 ID for 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.
|
We should give |
src/Mono.Android/Java.Lang/Object.cs
Outdated
| } | ||
|
|
||
| #if JAVA_INTEROP | ||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] |
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 property should be shown to the debugger.
src/Mono.Android/Java.Lang/Object.cs
Outdated
| } | ||
| #endif // JAVA_INTEROP | ||
|
|
||
| [DebuggerBrowsable (DebuggerBrowsableState.Never)] |
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 property should be shown to the debugger.
|
Just remembered about the |
|
Addressed feedback to let the debugger see a couple of instance identifiers, and added The only member on |
brendanzagaeski
left a comment
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.
Draft release notes
This looks like a nice user-facing behavior improvement. After the full set of types to adjust is settled, when you get a chance, you can add a draft release note for it to Documentation/release-notes/4583.md based on the PR description. I think the screenshots from the PR description could be nice to include in the note too. They can go in Documentation/release-notes/images/ as 4583-before.png and 4583-after.png or any other names you like. Thanks much!
The note can optionally include a separate section for the issue fixed, like:
### Tidier IntelliSense suggestions for Java.Lang.Object subclasses
`Java.Lang.Object` contains...
### 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.
Fixes: #4582 `Java.Lang.Object` and `Java.Lang.Throwable` contain various `public` and `protected` members that are required by our bindings, such as the `Handle` and `PeerReference` properties. We cannot make them `internal` because our bindings need them, but we can make them "invisible" to users using IDEs by applying the attributes: * [`[EditorBrowsable (EditorBrowsableState.Never)]`][0] * [`[DebuggerBrowsable (DebuggerBrowsableState.Never)]`][1] This will prevent them from showing up in IntelliSense and debugger displays, as they should not be used by users. Note they are still usable if needed, they simply do not show up in IntelliSense. You have to type them out manually. Intellisense for a class deriving JLO before:  After:  [0]: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.editorbrowsableattribute [1]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerbrowsableattribute
Fixes #4582.
Java.Lang.Objectcontains variouspublicandprotectedmembers that are required by our bindings, such asJ.L.Object.HandleandJ.L.Object.PeerReference. We cannot make theminternalbecause our bindings need them, but we can make them "invisible" to users using IDEs by applying[EditorBrowsable (Never)]and[DebuggerBrowsable (Never)]. This will prevent them from showing up in Intellisense and debugger displays, as they should not be used by users.Note they are still usable if needed, they simply do not show up in Intellisense. You have to type them out manually.
Intellisense for a class deriving JLO before:

After:
