private bool IsEmptyStatementRange(StatementRange statementRange)
        {
            if (!statementRange.IsEmpty)
            {
                var parent = statementRange.Parent;
                if (!IsStatementContainer(parent))
                {
                    Debug.Assert(statementRange.FirstStatement == statementRange.LastStatement);
                    return(statementRange.FirstStatement.DescendantNodesAndSelf().All(IsNoOpSyntaxNode));
                }

                var statements = GetStatements(parent);
                var firstIndex = statements.IndexOf(statementRange.FirstStatement);
                var lastIndex  = statements.IndexOf(statementRange.LastStatement);
                for (var i = firstIndex; i <= lastIndex; i++)
                {
                    if (!statements[i].DescendantNodesAndSelf().All(IsNoOpSyntaxNode))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        private static void AnalyzeControlFlow(
            SemanticModel semanticModel,
            StatementRange statementRange,
            out bool endPointIsReachable,
            out SyntaxNode?singleExitPoint)
        {
            var flow = semanticModel.AnalyzeControlFlow(
                statementRange.FirstStatement,
                statementRange.LastStatement);

            endPointIsReachable = flow.EndPointIsReachable;
            singleExitPoint     = flow.ExitPoints.Length == 1 ? flow.ExitPoints[0] : null;
        }
        protected override bool IsSingleStatementStatementRange(StatementRange statementRange)
        {
            if (statementRange.IsEmpty)
            {
                return(false);
            }

            if ((object)statementRange.FirstStatement != (object)statementRange.LastStatement)
            {
                return(false);
            }

            return(IsSingleStatement(statementRange.FirstStatement));
Beispiel #4
0
        protected override bool IsSingleStatementStatementRange(StatementRange statementRange)
        {
            if (statementRange.IsEmpty)
            {
                return(false);
            }

            if ((object)statementRange.FirstStatement != (object)statementRange.LastStatement)
            {
                return(false);
            }

            return(isSingleStatement(statementRange.FirstStatement));

            bool isSingleStatement(StatementSyntax statement)
            {
                if (statement is BlockSyntax block)
                {
                    return(block.Statements.Count == 1 && isSingleStatement(block.Statements[0]));
                }

                return(true);
            }
        }
 protected abstract bool IsSingleStatementStatementRange(StatementRange statementRange);
 public MonoDocumentContext(string fileName, int startLine, int startColumn)
 {
     _fileName = fileName;
     _currentStatementRange = RoslynHelper.GetStatementRange(fileName, startLine, startColumn);
 }
 public MonoDocumentContext(string fileName, int startLine, int startColumn)
 {
     _fileName = fileName;
     _currentStatementRange = RoslynHelper.GetStatementRange(fileName, startLine, startColumn);
 }