Skip to content

Commit

Permalink
Leverage an existing Roslyn API instead of rolling my own inferior ve…
Browse files Browse the repository at this point in the history
…rsion (#4850)

Co-authored-by: Martin Taillefer <[email protected]>
  • Loading branch information
geeknoid and Martin Taillefer authored Jan 3, 2024
1 parent 3e24058 commit bd8f28a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/Generators/Microsoft.Gen.Logging/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ private void CheckTagNamesAreUnique(LoggingMethod lm, Dictionary<LoggingMethodPa
{
if (ParserUtilities.IsBaseOrIdentity(gm.ReturnType, symbol, _compilation))
{
if (!originType.CanAccess(gm))
if (!sm.Compilation.IsSymbolAccessibleWithin(gm, originType, type))
{
continue;
}
Expand All @@ -679,7 +679,7 @@ private void CheckTagNamesAreUnique(LoggingMethod lm, Dictionary<LoggingMethodPa
{
if (f.AssociatedSymbol == null && ParserUtilities.IsBaseOrIdentity(f.Type, symbol, _compilation))
{
if (!originType.CanAccess(f))
if (!sm.Compilation.IsSymbolAccessibleWithin(f, originType, type))
{
continue;
}
Expand Down
36 changes: 0 additions & 36 deletions src/Generators/Shared/SymbolHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,4 @@ public static string GetFullNamespace(ISymbol symbol)
{
return symbol.ContainingNamespace.IsGlobalNamespace ? string.Empty : symbol.ContainingNamespace.ToString();
}

/// <summary>
/// Can code in a given type access a given member?
/// </summary>
/// <remarks>
/// Note that this implementation assumes that the target member is within the origin type
/// or a base class of the origin type.
/// </remarks>
public static bool CanAccess(this INamedTypeSymbol originType, ISymbol targetMember)
{
if (SymbolEqualityComparer.Default.Equals(originType, targetMember.ContainingType))
{
// target member is from the origin type, we're good
return true;
}

if (targetMember.DeclaredAccessibility == Accessibility.Private)
{
// can't access a private member from a different type
return false;
}

if (SymbolEqualityComparer.Default.Equals(originType.ContainingAssembly, targetMember.ContainingAssembly))
{
// target member is in the same assembly as the origin type, so we're good
return true;
}

if (targetMember.DeclaredAccessibility is Accessibility.Internal or Accessibility.ProtectedAndInternal)
{
// can't access internal members of other assemblies (sorry, we don't support IVT right now)
return false;
}

return true;
}
}

0 comments on commit bd8f28a

Please sign in to comment.