Skip to content

Hide Java.Lang.Object members meant only for internal use #4582

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

Closed
bramborman opened this issue Apr 17, 2020 · 6 comments · Fixed by #4583
Closed

Hide Java.Lang.Object members meant only for internal use #4582

bramborman opened this issue Apr 17, 2020 · 6 comments · Fixed by #4583
Assignees
Labels
Area: Bindings Issues in Java Library Binding projects.

Comments

@bramborman
Copy link

Hi, this is not a very important issue, but something I guess would make a dev's life a bit easier :)

I work with Xamarin.Android so I use mostly objects that are bound from Java libs so they inherit from the Java.Lang.Object class. The problem here is that it has a few public members that are intended for internal Java.Interop use only. For instance public IntPtr Handle or public JniObjectReference PeerReference.

So I'm wondering whether it'd be possible to hide these members as they're making an unwanted noise in IntelliSense and could also possibly lead to some confusion or errors when mistakenly used. The best would of course be to make them internal or something like that or, if that's not possible, the EditorBrowsable(EditorBrowsableState.Never) attribute could be added to remove that noise.

@bramborman
Copy link
Author

Also it could be worth adding the [DebuggerBrowsable(DebuggerBrowsableState.Never)] attribute if the members cannot be made internal or so to hide the members when debugging.

@jpobst
Copy link
Contributor

jpobst commented Apr 20, 2020

Unfortunately they cannot be made internal, as they are used by bindings libraries.

I really like your idea to at least hide them from the editor/debugger. I'll look into doing that!

I'm going to move this to the Xamarin.Android repo, as the code for Java.Lang.Object is actually over there.

@jpobst jpobst transferred this issue from dotnet/java-interop Apr 20, 2020
@jpobst jpobst self-assigned this Apr 20, 2020
@jpobst jpobst added this to the Under Consideration milestone Apr 20, 2020
@jpobst jpobst added the Area: Bindings Issues in Java Library Binding projects. label Apr 20, 2020
jonpryor pushed a commit that referenced this issue Apr 22, 2020
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:

![before](https://user-images.githubusercontent.com/179295/79778416-4fc78000-82fe-11ea-840a-fb0b4688d6aa.png)

After:

![after](https://user-images.githubusercontent.com/179295/79778430-535b0700-82fe-11ea-9ff6-d6e41eabcf9a.png)

[0]: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.editorbrowsableattribute
[1]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerbrowsableattribute
jonpryor pushed a commit that referenced this issue Apr 23, 2020
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:

![before](https://user-images.githubusercontent.com/179295/79778416-4fc78000-82fe-11ea-840a-fb0b4688d6aa.png)

After:

![after](https://user-images.githubusercontent.com/179295/79778430-535b0700-82fe-11ea-9ff6-d6e41eabcf9a.png)

[0]: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.editorbrowsableattribute
[1]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debuggerbrowsableattribute
@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.3.99.230.

Fix included on Windows in Visual Studio 2019 version 16.7 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.7 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android SDK version 11.0.0.3.

Fix included on Windows in Visual Studio 2019 version 16.7. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.7. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@bramborman
Copy link
Author

Hi, I just downloaded the latest VS 16.7 and wanted to look at this fix but I found there's a problem with classes that inherit from Java.Lang.Object that override these now hidden properties. For instance Android.App.Activity overrides ThresholdClass so it is then visible in IntelliSense and this fix has no effect :/
I guess the bindings generator will need to be updated too to add these attributes on the overrides.

@jpobst
Copy link
Contributor

jpobst commented Aug 6, 2020

Good point, I added dotnet/java-interop#688 to address this.

jonpryor pushed a commit to dotnet/java-interop that referenced this issue Aug 28, 2020
Fixes: #688

Context: dotnet/android#4582
Context: dotnet/android@3c94f6f
Context: dotnet/android#4582 (comment)

In dotnet/android#4582 we hid "infrastructural" members like
`Java.Lang.Object.ThresholdClass` from the editor and debugger using
`[DebuggerBrowsable(DebuggerBrowsableState.Never)]` and
`[EditorBrowsable(EditorBrowsableState.Never)]`.

However, `generator` output overrides these members, and thus they're
*still* visible from the IDE editor and debugger.

In order to *fully* hide infrastructural members from the editor and
debugger, *every occurrence* of the member must also have
`DebuggerBrowsableAttribute` and `EditorBrowsableAttribute`!

Update `generator` so that all infrastructural members contain the
attributes necessary to hide them from code completion, e.g.

	[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; }
	}

This ensures that the members are in fact hidden from IDEs.
@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Bindings Issues in Java Library Binding projects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants