Skip to content

Handle properties with getter or setter only [Obsolete] attribute #1033

Closed
@jpobst

Description

@jpobst

When we are converting Java getter/setter pairs to C# properties, we can hit an interesting scenario where a getter may be @Deprecated and the setter is not, or vice versa:

  public boolean hasOptionsMenu () { ... }

  @Deprecated
  public void setHasOptionsMenu (boolean hasMenu) { ... }

C# has traditionally not allowed [Obsolete] to be placed on just a get or a set, it can only be placed on the entire property.

  [Obsolete]
  public bool HasOptionsMenu { get; set; }

This can lead to confusion because using the getter will report an obsolete warning when it is not obsolete. Thus, for properties, we only add [Obsolete] in 2 cases:

  • The get is obsolete and there is no set
  • Both the get and set are obsolete

We have this comment in our code:

// Unlike [Register], [Obsolete] cannot be put on property accessors, so we can apply them only under limited condition...

However, the compiler team has determined that preventing [Obsolete] on property accessors was a bug, and has fixed it in C# 8: dotnet/roslyn#32571.

Thus we can update generator to support scenarios in which only the Java getter or setter is marked as @Deprecated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementProposed change to current functionalitygeneratorIssues binding a Java library (generator, class-parse, etc.)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions