Skip to content
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

Leverage an existing Roslyn API instead of rolling my own inferior version #4850

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading