[generator] Fix UnsupportedOSPlatform for property setters when base has getter-only#1374
Open
jonathanpeppers wants to merge 4 commits intomainfrom
Open
[generator] Fix UnsupportedOSPlatform for property setters when base has getter-only#1374jonathanpeppers wants to merge 4 commits intomainfrom
UnsupportedOSPlatform for property setters when base has getter-only#1374jonathanpeppers wants to merge 4 commits intomainfrom
Conversation
…e has getter-only Context: dotnet/android#10510 (comment) When a derived class has a property setter with `ApiRemovedSince`, but the base class only has a getter (no setter), clear the setter's `ApiRemovedSince` if the base getter is not removed. Also handle standalone `setXxx` methods that correspond to base class properties. Fixes `CA1416` warning for `ListView.Adapter.set` being incorrectly marked as unsupported on `android15.0`.
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect UnsupportedOSPlatform attribute generation for property setters when the base class only has a getter. The fix addresses CA1416 warnings by clearing ApiRemovedSince on derived class setters when the base property (accessed via its getter) is not marked as removed.
Key Changes:
- Adds logic to handle property setters in derived classes when base class has getter-only properties
- Adds handling for standalone
setXxxmethods that correspond to base class properties - Includes test coverage for the property setter scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs | Adds three conditional blocks to clear ApiRemovedSince on setters: one for class properties (lines 369-373), one for standalone setter methods (lines 380-393), and one for interface properties (lines 441-444) |
| tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs | Adds test UnsupportedOSPlatformIgnoresPropertySetterOverridesWhenBaseHasGetterOnly to verify the fix for ListView.Adapter scenario |
Updated property override logic to match base properties by name only, allowing for covariant return and contravariant parameter types. This prevents incorrectly marking overridden getters/setters as removed when the base property is not removed, even if the return or parameter types differ. Added a unit test to verify that [UnsupportedOSPlatform] is not applied in these covariant override scenarios.
…# names When a derived class property has a different C# name than the base class property but the same Java getter/setter names (e.g., ListView.Adapter vs AdapterView.RawAdapter both using getAdapter/setAdapter), the ApiRemovedSince fixup now correctly matches by Java method name instead of only by C# property name. This prevents incorrect [UnsupportedOSPlatformAttribute] generation on property accessors when the base class accessor is still available.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: dotnet/android#10510 (comment)
When a derived class has a property setter with
ApiRemovedSince, but the base class only has a getter (no setter), clear the setter'sApiRemovedSinceif the base getter is not removed. Also handle standalonesetXxxmethods that correspond to base class properties.Fixes
CA1416warning forListView.Adapter.setbeing incorrectly marked as unsupported onandroid15.0.