private IEnumerable <SyntaxNode> VerifyTryBlock(TryBlockSyntax node, SyntaxNode nextBlock) { if (!node.Statements.Any() && NoCommentsBefore(nextBlock)) { yield return(node.TryStatement); } }
private IEnumerable <SyntaxNode> VisitTryBlock(TryBlockSyntax node) { var result = new List <SyntaxNode>(); if (node.CatchBlocks.Any() && node.FinallyBlock != null) { result.AddRange(VerifyTryAndMostCatches(node)); result.AddRange(VerifyCatchBlock(node.CatchBlocks[node.CatchBlocks.Count - 1], node.FinallyBlock)); result.AddRange(VerifyFinallyBlock(node.FinallyBlock, node.EndTryStatement)); } else if (node.FinallyBlock != null) { result.AddRange(VerifyTryBlock(node, node.FinallyBlock)); result.AddRange(VerifyFinallyBlock(node.FinallyBlock, node.EndTryStatement)); } else if (node.CatchBlocks.Any()) { result.AddRange(VerifyTryAndMostCatches(node)); result.AddRange(VerifyCatchBlock(node.CatchBlocks[node.CatchBlocks.Count - 1], node.EndTryStatement)); } else { throw new InvalidOperationException("Try block must be followed by at least one catch or one finally block"); } return(result); }
public override SyntaxList <StatementSyntax> VisitTryBlock(TryBlockSyntax node) { var cSharpSyntaxNodes = wrappedVisitor.Visit(node); var tryStatementCs = (TryStatementSyntax)cSharpSyntaxNodes.Single(); var tryTokenCs = tryStatementCs.TryKeyword; var tryStatementWithTryTrivia = tryStatementCs.ReplaceToken(tryTokenCs, tryTokenCs.WithConvertedTriviaFrom(node.TryStatement)); var tryStatementWithAllTrivia = triviaConverter.PortConvertedTrivia(node, tryStatementWithTryTrivia); return(cSharpSyntaxNodes.Replace(tryStatementCs, tryStatementWithAllTrivia)); }
private IEnumerable <SyntaxNode> VerifyTryAndMostCatches(TryBlockSyntax node) { var result = new List <SyntaxNode>(); result.AddRange(VerifyTryBlock(node, node.CatchBlocks[0])); // verify all catches except the last one for (int i = 0; i < node.CatchBlocks.Count - 1; i++) { result.AddRange(VerifyCatchBlock(node.CatchBlocks[i], node.CatchBlocks[i + 1])); } return(result); }
public override void VisitTryBlock(TryBlockSyntax node) => counter.CheckNesting(node.TryStatement.TryKeyword, () => base.VisitTryBlock(node));
public override void VisitTryBlock(TryBlockSyntax node) { LogicalLineCount++; base.VisitTryBlock(node); }