Skip to content

Commit

Permalink
! Checked parent accessibility of nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 18, 2018
1 parent 57de934 commit cb3acff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions Codist/Helpers/CodeAnalysisHelper.Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ static Comparer<ISymbol> CreateSymbolComparer() {
public static IEnumerable<ISymbol> FindDeclarationMatchName(this Compilation compilation, string symbolName, bool fullMatch, bool matchCase, CancellationToken cancellationToken = default) {
var filter = CreateNameFilter(symbolName, fullMatch, matchCase);
foreach (var type in compilation.GlobalNamespace.GetAllTypes(cancellationToken)) {
if (type.IsAccessible() && filter(type.Name)) {
if (type.IsAccessible(true) == false) {
continue;
}
if (filter(type.Name)) {
yield return type;
}
if (cancellationToken.IsCancellationRequested) {
Expand All @@ -183,7 +186,7 @@ public static IEnumerable<ISymbol> FindDeclarationMatchName(this Compilation com
foreach (var member in type.GetMembers()) {
if (member.Kind != SymbolKind.NamedType
&& member.CanBeReferencedByName
&& member.IsAccessible()
&& member.IsAccessible(false)
&& filter(member.Name)) {
yield return member;
}
Expand Down Expand Up @@ -653,12 +656,13 @@ public static void GoToSource(this SyntaxReference loc) {
CodistPackage.DTE.OpenFile(loc.SyntaxTree.FilePath, pos.Line + 1, pos.Character + 1);
}

public static bool IsAccessible(this ISymbol symbol) {
public static bool IsAccessible(this ISymbol symbol, bool checkContainingType) {
return symbol != null
&& (symbol.DeclaredAccessibility == Accessibility.Public
|| symbol.DeclaredAccessibility == Accessibility.Protected
|| symbol.DeclaredAccessibility == Accessibility.ProtectedOrInternal
|| symbol.ContainingAssembly.GetSourceType() != AssemblySource.Metadata);
|| symbol.ContainingAssembly.GetSourceType() != AssemblySource.Metadata)
&& (checkContainingType == false || symbol.ContainingType == null || symbol.ContainingType.IsAccessible(true));
}
#endregion

Expand Down
6 changes: 3 additions & 3 deletions Codist/QuickInfo/CSharpQuickInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static void ShowNamespaceInfo(IList<object> qiContent, SyntaxNode node, INamespa
if (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.NamespaceTypes) == false) {
return;
}
var namespaces = nsSymbol.GetNamespaceMembers().ToImmutableArray().Sort(Comparer<INamespaceSymbol>.Create((x, y) => String.Compare(x.Name, y.Name)));
var namespaces = nsSymbol.GetNamespaceMembers().ToImmutableArray().Sort(Comparer<INamespaceSymbol>.Create((x, y) => String.Compare(x.Name, y.Name, StringComparison.Ordinal)));
if (namespaces.Length > 0) {
var info = new StackPanel();
info.Add(new ThemedTipText("Namespace:", true));
Expand Down Expand Up @@ -753,7 +753,7 @@ static StackPanel ShowStringInfo(string sv) {
static void ShowAttributes(IList<object> qiContent, ImmutableArray<AttributeData> attrs, int position) {
var info = new StackPanel().Add(new ThemedTipText("Attribute:", true));
foreach (var item in attrs) {
if (item.AttributeClass.IsAccessible() == false) {
if (item.AttributeClass.IsAccessible(true) == false) {
continue;
}
info.Children.Add(_SymbolFormatter.ToUIText(new ThemedTipText(), item));
Expand All @@ -771,7 +771,7 @@ static void ShowBaseType(IList<object> qiContent, ITypeSymbol typeSymbol, int po
var info = new ThemedTipText("Base type: ", true)
.AddSymbol(baseType, null, _SymbolFormatter.Class);
while (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.BaseTypeInheritence) && (baseType = baseType.BaseType) != null) {
if (baseType.IsAccessible() && baseType.IsCommonClass() == false) {
if (baseType.IsAccessible(false) && baseType.IsCommonClass() == false) {
info.Append(" - ").AddSymbol(baseType, null, _SymbolFormatter.Class);
}
}
Expand Down

0 comments on commit cb3acff

Please sign in to comment.