Skip to content

Commit

Permalink
Fix add accessibility for file types (#62275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jun 30, 2022
1 parent 332fa0a commit fa2182b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,5 +611,71 @@ internal class C : I<C>

await test.RunAsync();
}

[Theory, Trait(Traits.Feature, Traits.Features.CodeActionsAddAccessibilityModifiers)]
[InlineData("class")]
[InlineData("struct")]
[InlineData("record")]
[InlineData("record struct")]
[InlineData("interface")]
[InlineData("enum")]
[WorkItem(62259, "https://github.com/dotnet/roslyn/issues/62259")]
public async Task TestFileDeclaration(string declarationKind)
{
var source = $"file {declarationKind} C {{ }}";

await new VerifyCS.Test
{
TestCode = source,
FixedCode = source,
LanguageVersion = LanguageVersion.Preview,
}.RunAsync();
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddAccessibilityModifiers)]
[WorkItem(62259, "https://github.com/dotnet/roslyn/issues/62259")]
public async Task TestFileDelegate()
{
var source = "file delegate void M();";

await new VerifyCS.Test
{
TestCode = source,
FixedCode = source,
LanguageVersion = LanguageVersion.Preview,
}.RunAsync();
}

[Theory, Trait(Traits.Feature, Traits.Features.CodeActionsAddAccessibilityModifiers)]
[InlineData("class")]
[InlineData("struct")]
[InlineData("record")]
[InlineData("record struct")]
[InlineData("interface")]
[InlineData("enum")]
[WorkItem(62259, "https://github.com/dotnet/roslyn/issues/62259")]
public async Task TestNestedFileDeclaration(string declarationKind)
{
var source = $$"""
file class C1
{
{{declarationKind}} [|C2|] { }
}
""";

var fixedSource = $$"""
file class C1
{
private {{declarationKind}} C2 { }
}
""";

await new VerifyCS.Test
{
TestCode = source,
FixedCode = fixedSource,
LanguageVersion = LanguageVersion.Preview,
}.RunAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public bool CanHaveAccessibility(SyntaxNode declaration)
case SyntaxKind.InterfaceDeclaration:
case SyntaxKind.EnumDeclaration:
case SyntaxKind.DelegateDeclaration:
return !((MemberDeclarationSyntax)declaration).Modifiers.Any(SyntaxKind.FileKeyword);

case SyntaxKind.FieldDeclaration:
case SyntaxKind.EventFieldDeclaration:
case SyntaxKind.GetAccessorDeclaration:
Expand Down

0 comments on commit fa2182b

Please sign in to comment.