-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip interfaces not publicly accessible in authoring scenarios (#1394)
* Add internal COM interfaces to authoring test * Add MixedWinRTClassicCOM authoring tests * Skip interface types not publicly accessible * Minor code refactoring * Suppress diagnostics for not publicly accessible types * Use fully qualified name for [Guid] to avoid conflicts * Remmove collection expressions in projection attributes * Skip processing explicit members of internal interfaces * Skip processing symbols nested in internal types * Add ABI types for AOT generator * Restore original order/filtering to gather interfaces * Fix build errors in AuthoringConsumptionTest * Add TestMixedWinRTCOMWrapper to activation manifest * Fix unit test * Fix typos in ABI method names
- Loading branch information
1 parent
f937163
commit 2f2869c
Showing
7 changed files
with
283 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
src/Authoring/WinRT.SourceGenerator/Extensions/SymbolExtensions.cs
This file contains 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,54 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
|
||
#nullable enable | ||
|
||
namespace Generator; | ||
|
||
/// <summary> | ||
/// Extensions for symbol types. | ||
/// </summary> | ||
internal static class SymbolExtensions | ||
{ | ||
/// <summary> | ||
/// Checks whether a given type symbol is publicly accessible (ie. it's public and not nested in any non public type). | ||
/// </summary> | ||
/// <param name="type">The type symbol to check for public accessibility.</param> | ||
/// <returns>Whether <paramref name="type"/> is publicly accessible.</returns> | ||
public static bool IsPubliclyAccessible(this ITypeSymbol type) | ||
{ | ||
for (ITypeSymbol? currentType = type; currentType is not null; currentType = currentType.ContainingType) | ||
{ | ||
// If any type in the type hierarchy is not public, the type is not public. | ||
// This makes sure to detect public types nested into eg. a private type. | ||
if (currentType.DeclaredAccessibility is not Accessibility.Public) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Checks whether a given symbol is an explicit interface implementation of a member of an internal interface (or more than one). | ||
/// </summary> | ||
/// <param name="symbol">The input member symbol to check.</param> | ||
/// <returns>Whether <paramref name="symbol"/> is an explicit interface implementation of internal interfaces.</returns> | ||
public static bool IsExplicitInterfaceImplementationOfInternalInterfaces(this ISymbol symbol) | ||
{ | ||
static bool IsAnyContainingTypePublic(IEnumerable<ISymbol> symbols) | ||
{ | ||
return symbols.Any(static symbol => symbol.ContainingType!.IsPubliclyAccessible()); | ||
} | ||
|
||
return symbol switch | ||
{ | ||
IMethodSymbol { ExplicitInterfaceImplementations: { Length: > 0 } methods } => !IsAnyContainingTypePublic(methods), | ||
IPropertySymbol { ExplicitInterfaceImplementations: { Length: > 0 } properties } => !IsAnyContainingTypePublic(properties), | ||
IEventSymbol { ExplicitInterfaceImplementations: { Length: > 0 } events } => !IsAnyContainingTypePublic(events), | ||
_ => false | ||
}; | ||
} | ||
} |
This file contains 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 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 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 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 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