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

Only show public interfaces in generated syntax #7696

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests and a few fixes
  • Loading branch information
dotMorten committed Nov 5, 2021
commit 4b36f7a9fb86f134cbd5d8ffaad3758a308aba2e
Original file line number Diff line number Diff line change
Expand Up @@ -1197,11 +1197,11 @@ private BaseListSyntax GetBaseTypeList(INamedTypeSymbol symbol)
IReadOnlyList<INamedTypeSymbol> baseTypeList;
if (symbol.TypeKind != TypeKind.Class || symbol.BaseType == null || symbol.BaseType.GetDocumentationCommentId() == "T:System.Object")
{
baseTypeList = symbol.AllInterfaces;
baseTypeList = symbol.AllInterfaces.Where(s=>s.DeclaredAccessibility != Accessibility.Internal).ToList();
}
else
{
baseTypeList = new[] { symbol.BaseType }.Concat(symbol.AllInterfaces).ToList();
baseTypeList = new[] { symbol.BaseType }.Concat(symbol.AllInterfaces.Where(s => s.DeclaredAccessibility != Accessibility.Internal)).ToList();
}
if (baseTypeList.Count == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ private SyntaxList<InheritsStatementSyntax> GetInheritsList(INamedTypeSymbol sym

private SyntaxList<ImplementsStatementSyntax> GetImplementsList(INamedTypeSymbol symbol)
{
if (symbol.AllInterfaces.Any())
if (symbol.AllInterfaces.Where(t=>t.DeclaredAccessibility == Accessibility.Public).Any())
{
return SyntaxFactory.SingletonList(SyntaxFactory.ImplementsStatement(
(from t in symbol.AllInterfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,29 @@ public interface IFooBar : IBar { }
Assert.Equal(new[] { "public", "interface" }, ifoobar.Modifiers[SyntaxLanguage.CSharp]);
}

[Fact]
public void TestGenerateMetadataWithInternalInterfaceAndInherits()
{
string code = @"
namespace Test1
{
public class Foo : IFoo { }
internal interface IFoo { }
}
";
MetadataItem output = GenerateYamlMetadata(CreateCompilationFromCSharpCode(code));
Assert.Single(output.Items);

var foo = output.Items[0].Items[0];
Assert.NotNull(foo);
Assert.Equal("Foo", foo.DisplayNames[SyntaxLanguage.CSharp]);
Assert.Equal("Foo", foo.DisplayNamesWithType[SyntaxLanguage.CSharp]);
Assert.Equal("Test1.Foo", foo.DisplayQualifiedNames[SyntaxLanguage.CSharp]);
Assert.Equal("public class Foo", foo.Syntax.Content[SyntaxLanguage.CSharp]);
Assert.Equal(new[] { "public", "class" }, foo.Modifiers[SyntaxLanguage.CSharp]);
Assert.Null(foo.Implements);
}

[Trait("Related", "Generic")]
[Trait("Related", "Inheritance")]
[Trait("Related", "Reference")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,30 @@ End Namespace
}
}

[Fact]
public void TestGenerateMetadataWithInternalInterfaceAndInherits()
{
string code = @"
Namespace Test1
Public Class Foo
Implements IFoo
End Class
Internal Interface IFoo
End Interface
";
MetadataItem output = GenerateYamlMetadata(CreateCompilationFromVBCode(code));
Assert.Single(output.Items);

var foo = output.Items[0].Items[0];
Assert.NotNull(foo);
Assert.Equal("Foo", foo.DisplayNames[SyntaxLanguage.VB]);
Assert.Equal("Foo", foo.DisplayNamesWithType[SyntaxLanguage.VB]);
Assert.Equal("Test1.Foo", foo.DisplayQualifiedNames[SyntaxLanguage.VB]);
Assert.Equal("Public Class Foo", foo.Syntax.Content[SyntaxLanguage.VB]);
Assert.Equal(new[] { "Public", "Class" }, foo.Modifiers[SyntaxLanguage.VB]);
Assert.Null(foo.Implements);
}

[Trait("Related", "Generic")]
[Fact]
public void TestGenereateMetadataWithDelegate()
Expand Down