Skip to content

Only add getters and setters for type-forwarded properties to public API#1657

Merged
DustinCampbell merged 1 commit intodotnet:masterfrom
DustinCampbell:fix-type-forwarded-properties
Apr 3, 2018
Merged

Only add getters and setters for type-forwarded properties to public API#1657
DustinCampbell merged 1 commit intodotnet:masterfrom
DustinCampbell:fix-type-forwarded-properties

Conversation

@DustinCampbell
Copy link
Copy Markdown
Member

During normal operation, properties are not added to the public API surface area because the analyzer does not register a symbol
action for SymbolKind.Property. This works fine, there is an action registered for SymbolKind.Method, which ensures that getters
and setters are added as expected. Things are a bit different for forwarded types.

In the case of a forwarded type, the public API surface area is discovered by recursively searching members and nested types. However,
this code adds both properties and accessors, resulting in the PublicAPI.Shipped.txt file needs to include an entry for the property
and the accessors, like so:

Microsoft.CodeAnalysis.FileTextLoader.Path.get -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces)
Microsoft.CodeAnalysis.FileTextLoader.Path { get; } -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces)

This change fixes the analyzer to not consider property symbols when recursively searching through forwarded types. However, it still
considers their accessors.

During normal operation, properties are not added to the public API surface area because the analyzer does not register a symbol
action for `SymbolKind.Property`. This works fine, there is an action registered for `SymbolKind.Method`, which ensures that getters
and setters are added as expected. Things are a bit different for forwarded types.

In the case of a forwarded type, the public API surface area is discovered by recursively searching members and nested types. However,
this code adds both properties *and* accessors, resulting in the PublicAPI.Shipped.txt file needs to include an entry for the property
and the accessors, like so:

```
Microsoft.CodeAnalysis.FileTextLoader.Path.get -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces)
Microsoft.CodeAnalysis.FileTextLoader.Path { get; } -> string (forwarded, contained in Microsoft.CodeAnalysis.Workspaces)
```

This change fixes the analyzer to not consider property symbols when recursively searching through forwarded types. However, it still
considers their accessors.
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1657 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1657      +/-   ##
==========================================
+ Coverage   93.44%   93.45%   +<.01%     
==========================================
  Files         731      731              
  Lines      126044   126071      +27     
  Branches     3512     3513       +1     
==========================================
+ Hits       117786   117814      +28     
+ Misses       7472     7471       -1     
  Partials      786      786
Flag Coverage Δ
#debug 93.45% <100%> (ø) ⬆️
Impacted Files Coverage Δ
...alyzers/UnitTests/DeclarePublicAPIAnalyzerTests.cs 94.43% <100%> (+0.14%) ⬆️
...cs.Analyzers/Core/DeclarePublicAPIAnalyzer.Impl.cs 89.94% <100%> (+0.35%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca57b06...48c877a. Read the comment docs.

@DustinCampbell DustinCampbell merged commit 2ab7485 into dotnet:master Apr 3, 2018
DustinCampbell added a commit to DustinCampbell/roslyn that referenced this pull request Apr 3, 2018
Since we're moving this type from Microsoft.CodeAnalysis.Workspaces.Desktop to Microsoft.CodeAnalysis.Workspaces, a type forward is
required. There is currently a bug with the Public API analyzer with properties on forwarded types that I have to work around in the
PublicAPI.Shipped.txt, but a fix is already out for that dotnet/roslyn-analyzers#1657. Once the analyzers are
updated in the roslyn repo, this will get fixed.
sharwell added a commit to sharwell/PublicApiAnalyzer that referenced this pull request Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants