Skip to content
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

Bindings of abstract methods should be [Obsolete] if Java method is @Deprecated #969

Closed
jonpryor opened this issue Apr 15, 2022 · 0 comments · Fixed by #1011
Closed

Bindings of abstract methods should be [Obsolete] if Java method is @Deprecated #969

jonpryor opened this issue Apr 15, 2022 · 0 comments · Fixed by #1011
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)
Milestone

Comments

@jonpryor
Copy link
Member

Context: #968
Context: #968 (comment)

PR #968 "uncovered" that if you have a Java abstract method which is deprecated:

public abstract class Example {
    @Deprecated
    public abstract void m();
}

then the C# binding is not [Obsolete], and the *Invoker override is [Obsolete]:

// Binding
public abstract partial class Example : Java.Lang.Object {
    [Register ()]
    public abstract void M();
}

internal partial class ExampleInvoker : Example {
    [Obsolete]
    public override void M() =>}

This state of affairs results in a CS0809 warning:

Error CS0809: Obsolete member 'ExampleInvoker.M()' overrides non-obsolete member 'Example.M()'

PR #968 fixed this warning for CodeGenerationTarget.JavaInterop1.

Should this also be done for CodeGenerationTarget.XAJavaInterop1?

@jpobst jpobst added enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.) labels May 2, 2022
@jpobst jpobst added this to the 7.0.0 milestone May 12, 2022
@jpobst jpobst removed their assignment May 12, 2022
jonpryor pushed a commit that referenced this issue Jul 14, 2022
Fixes: #969

If you have a Java `abstract` method which is deprecated:

	// Java
	public abstract class Example {
	    @deprecated
	    public abstract void m();
	}

then the C# binding is *not* `[Obsolete]`, *and* the `*Invoker`
override *is* `[Obsolete]`:

	// Binding
	public abstract partial class Example : Java.Lang.Object {
	    // Note: *not* [Obsolete]
	    [Register (…)]
	    public abstract void M();
	}

	internal partial class ExampleInvoker : Example {
	    [Obsolete]
	    public override void M() => …
	}

This state of affairs results in a [CS0809 warning][0]:

	warning CS0809: Obsolete member 'ExampleInvoker.M()' overrides non-obsolete member 'Example.M()'

Commit 37cff25 added a fix for this for `JavaInterop1` output, asking:

> TODO: should this change be done for *all* codegen targets?

The answer: Yes.

Expand the fix from 37cff25 to apply to `XAJavaInterop1` codegen,
and add unit tests for this scenario.

[0]: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0809
jonpryor pushed a commit to dotnet/android that referenced this issue Jul 19, 2022
Fixes: dotnet/java-interop#969
Fixes: dotnet/java-interop#982
Fixes: dotnet/java-interop#984

Changes: dotnet/java-interop@fadbb82...032f1e7

  * dotnet/java-interop@032f1e71: [Xamarin.Android.Tools.Bytecode-Tests] Fix BuildClasses (#1013)
  * dotnet/java-interop@0eaa47e1: [Java.Interop.Tools.JavaCallableWrappers] NRT Support (#1012)
  * dotnet/java-interop@45fe3928: [generator] BG8403 when type name matches enclosing namespace name (#1010)
  * dotnet/java-interop@fe60483b: [generator] Mark abstract methods as [Obsolete] if needed (#1011)
  * dotnet/java-interop@275fa755: [generator] Kotlin metadata can apply to multiple Java method (#1009)
  * dotnet/java-interop@3ff6f8fb: [Java.Base] Fix CS0108 Warnings (#1008)

Of note is dotnet/java-interop@fe60483b, which can cause public
members to become marked as `[Obsolete]`.  These members *always*
should have been `[Obsolete]`, but weren't.  (Oops.)  This also
required changes to the `Mono.Android` API-compat checks.

Also of note is dotnet/java-interop@45fe3928, which introduces a new
BG8403 binding warning when a bound type has the same name as its
enclosing namespace name-part, e.g. `Example.View.View`.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Proposed change to current functionality generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants