未验证 提交 3fb1c096 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #48132 from Youssef1313/patch-38

Add InitAccessorDeclaration to InvertIfCodeRefactoringProvider
......@@ -793,5 +793,49 @@ void M()
}
}");
}
[Theory, Trait(Traits.Feature, Traits.Features.CodeActionsInvertIf)]
[InlineData("get")]
[InlineData("set")]
[InlineData("init")]
public async Task IfWithoutElse_InPropertyAccessors(string accessor)
{
await TestInRegularAndScriptAsync(
$@"class C
{{
private bool _b;
public string Prop
{{
{accessor}
{{
[||]if (_b)
{{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}}
}}
}}
}}",
$@"class C
{{
private bool _b;
public string Prop
{{
{accessor}
{{
if (!_b)
{{
return;
}}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}}
}}
}}");
}
}
}
......@@ -66,27 +66,17 @@ protected override StatementSyntax GetElseBody(IfStatementSyntax ifNode)
protected override bool CanControlFlowOut(SyntaxNode node)
{
switch (node.Kind())
switch (node)
{
case SyntaxKind.SwitchSection:
case SyntaxKind.LocalFunctionStatement:
case SyntaxKind.SetAccessorDeclaration:
case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.ConstructorDeclaration:
case SyntaxKind.DestructorDeclaration:
case SyntaxKind.OperatorDeclaration:
case SyntaxKind.ConversionOperatorDeclaration:
case SyntaxKind.AnonymousMethodExpression:
case SyntaxKind.SimpleLambdaExpression:
case SyntaxKind.ParenthesizedLambdaExpression:
case SyntaxKind.DoStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachVariableStatement:
case SwitchSectionSyntax:
case LocalFunctionStatementSyntax:
case AccessorDeclarationSyntax:
case MemberDeclarationSyntax:
case AnonymousFunctionExpressionSyntax:
case CommonForEachStatementSyntax:
case DoStatementSyntax:
case WhileStatementSyntax:
case ForStatementSyntax:
return false;
}
......@@ -108,31 +98,21 @@ protected override SyntaxList<StatementSyntax> GetStatements(SyntaxNode node)
protected override int GetJumpStatementRawKind(SyntaxNode node)
{
switch (node.Kind())
switch (node)
{
case SyntaxKind.SwitchSection:
case SwitchSectionSyntax:
return (int)SyntaxKind.BreakStatement;
case SyntaxKind.LocalFunctionStatement:
case SyntaxKind.SetAccessorDeclaration:
case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.ConstructorDeclaration:
case SyntaxKind.DestructorDeclaration:
case SyntaxKind.OperatorDeclaration:
case SyntaxKind.ConversionOperatorDeclaration:
case SyntaxKind.AnonymousMethodExpression:
case SyntaxKind.SimpleLambdaExpression:
case SyntaxKind.ParenthesizedLambdaExpression:
case LocalFunctionStatementSyntax:
case AccessorDeclarationSyntax:
case MemberDeclarationSyntax:
case AnonymousFunctionExpressionSyntax:
return (int)SyntaxKind.ReturnStatement;
case SyntaxKind.DoStatement:
case SyntaxKind.WhileStatement:
case SyntaxKind.ForStatement:
case SyntaxKind.ForEachStatement:
case SyntaxKind.ForEachVariableStatement:
case CommonForEachStatementSyntax:
case DoStatementSyntax:
case WhileStatementSyntax:
case ForStatementSyntax:
return (int)SyntaxKind.ContinueStatement;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册