-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[ApiDiff] Update symbol filtering code to be able to load a list of strings or a list of files #46255
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
Merged
Merged
[ApiDiff] Update symbol filtering code to be able to load a list of strings or a list of files #46255
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
22800b0
Allow creating symbol filters from files or from lists more clearly, …
carlossanlop e9c29aa
Update src places where symbol filtering is currently used.
carlossanlop 4fcb4a7
Update test places where symbol filtering is used.
carlossanlop c9190fc
Remove unnecesary ProjectReference
carlossanlop 493beff
Inline private method in DocIdSymbolFilter and document public APIs.
carlossanlop ce6e15b
Triple slash for SymbolFilterFactory.
carlossanlop 76e959b
nit
carlossanlop 9198d3d
Add symbol filter factory tests
carlossanlop 6bb3f1a
count() -> length
carlossanlop bd8079a
Named parameters for readability
carlossanlop 731117d
Add an optional accessibility symbol filter argument to symbol filter…
carlossanlop 648df8a
Fix build failure in GenAPI test using SymbolFilterFactory
carlossanlop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
88 changes: 88 additions & 0 deletions
88
src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/SymbolFilterFactory.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Microsoft.DotNet.ApiSymbolExtensions.Filtering; | ||
|
||
/// <summary> | ||
/// A factory class to create symbol filters. | ||
/// </summary> | ||
public static class SymbolFilterFactory | ||
{ | ||
/// <summary> | ||
/// Creates a composite filter to exclude APIs using the DocIDs provided in the specifed file paths. | ||
/// </summary> | ||
/// <param name="apiExclusionFilePaths">A collection of paths where the exclusion files should be searched.</param> | ||
/// <param name="accessibilitySymbolFilter">An optional custom accessibility symbol filter to use.</param> | ||
/// <param name="respectInternals">Whether to include internal symbols or not.</param> | ||
/// <param name="includeEffectivelyPrivateSymbols">Whether to include effectively private symbols or not.</param> | ||
/// <param name="includeExplicitInterfaceImplementationSymbols">Whether to include explicit interface implementation symbols or not.</param> | ||
/// <param name="includeImplicitSymbolFilter">Whether to include implicit symbols or not.</param> | ||
/// <returns>An instance of the symbol filter.</returns> | ||
public static ISymbolFilter GetFilterFromFiles(string[]? apiExclusionFilePaths, | ||
AccessibilitySymbolFilter? accessibilitySymbolFilter = null, | ||
bool respectInternals = false, | ||
bool includeEffectivelyPrivateSymbols = true, | ||
bool includeExplicitInterfaceImplementationSymbols = true, | ||
bool includeImplicitSymbolFilter = true) | ||
{ | ||
DocIdSymbolFilter? docIdSymbolFilter = | ||
apiExclusionFilePaths?.Length > 0 ? | ||
DocIdSymbolFilter.CreateFromFiles(apiExclusionFilePaths) : null; | ||
|
||
return GetCompositeSymbolFilter(docIdSymbolFilter, accessibilitySymbolFilter, respectInternals, includeEffectivelyPrivateSymbols, includeExplicitInterfaceImplementationSymbols, includeImplicitSymbolFilter); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a composite filter to exclude APIs using the DocIDs provided in the specifed list. | ||
/// </summary> | ||
/// <param name="apiExclusionList">A collection of exclusion list.</param> | ||
/// <param name="accessibilitySymbolFilter">An optional custom accessibility symbol filter to use.</param> | ||
/// <param name="respectInternals">Whether to include internal symbols or not.</param> | ||
/// <param name="includeEffectivelyPrivateSymbols">Whether to include effectively private symbols or not.</param> | ||
/// <param name="includeExplicitInterfaceImplementationSymbols">Whether to include explicit interface implementation symbols or not.</param> | ||
/// <param name="includeImplicitSymbolFilter">Whether to include implicit symbols or not.</param> | ||
/// <returns>An instance of the symbol filter.</returns> | ||
public static ISymbolFilter GetFilterFromList(string[]? apiExclusionList, | ||
AccessibilitySymbolFilter? accessibilitySymbolFilter = null, | ||
bool respectInternals = false, | ||
bool includeEffectivelyPrivateSymbols = true, | ||
bool includeExplicitInterfaceImplementationSymbols = true, | ||
bool includeImplicitSymbolFilter = true) | ||
{ | ||
DocIdSymbolFilter? docIdSymbolFilter = | ||
apiExclusionList?.Count() > 0 ? | ||
DocIdSymbolFilter.CreateFromLists(apiExclusionList) : null; | ||
|
||
return GetCompositeSymbolFilter(docIdSymbolFilter, accessibilitySymbolFilter, respectInternals, includeEffectivelyPrivateSymbols, includeExplicitInterfaceImplementationSymbols, includeImplicitSymbolFilter); | ||
} | ||
|
||
private static ISymbolFilter GetCompositeSymbolFilter(DocIdSymbolFilter? customFilter, | ||
AccessibilitySymbolFilter? accessibilitySymbolFilter, | ||
bool respectInternals, | ||
bool includeEffectivelyPrivateSymbols, | ||
bool includeExplicitInterfaceImplementationSymbols, | ||
bool includeImplicitSymbolFilter) | ||
{ | ||
accessibilitySymbolFilter ??= new( | ||
respectInternals, | ||
includeEffectivelyPrivateSymbols, | ||
includeExplicitInterfaceImplementationSymbols); | ||
|
||
CompositeSymbolFilter filter = new(); | ||
|
||
if (customFilter != null) | ||
{ | ||
filter.Add(customFilter); | ||
} | ||
if (includeImplicitSymbolFilter) | ||
{ | ||
filter.Add(new ImplicitSymbolFilter()); | ||
carlossanlop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
filter.Add(accessibilitySymbolFilter); | ||
|
||
return filter; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.