Beispiel #1
0
            private bool CheckStatement(StatementSyntax statement)
            {
                Contract.ThrowIfNull(statement);

                // This is either an embedded statement or parented by a block.
                // If we're parented by a block, then that block will be the scope
                // of the new variable. Otherwise the scope is the statement itself.
                if (statement.Parent.IsKind(SyntaxKind.Block, out BlockSyntax? block))
                {
                    // Check if the local is accessed before assignment
                    // in the subsequent statements. If so, this can't
                    // be converted to pattern-matching.
                    if (LocalFlowsIn(firstStatement: statement.GetNextStatement(),
                                     lastStatement: block.Statements.Last()))
                    {
                        return(false);
                    }

                    return(!IsAccessedOutOfScope(scope: block));
                }
                else
                {
                    return(!IsAccessedOutOfScope(scope: statement));
                }
            }
Beispiel #2
0
            private void AddFollowingRelevantExpressions(CancellationToken cancellationToken)
            {
                var line = _syntaxTree.GetText(cancellationToken).Lines.IndexOf(_position);

                // If there's are more statements following us on the same line, then add them as
                // well.
                for (var nextStatement = _parentStatement.GetNextStatement();
                     nextStatement != null && _syntaxTree.GetText(cancellationToken).Lines.IndexOf(nextStatement.SpanStart) == line;
                     nextStatement = nextStatement.GetNextStatement())
                {
                    AddRelevantExpressions(nextStatement, _expressions, includeDeclarations: false);
                }
            }
Beispiel #3
0
        protected State GetNextState(StatementSyntax node)
        {
            var nextState = currentState.NextState;
            var next      = node.GetNextStatement();

            if (next != null && !(next is EmptyStatementSyntax))
            {
                nextState = new State(this)
                {
                    NextState = currentState.NextState, Germ = currentState.Germ
                };
            }
            return(nextState);
        }
 protected State GetNextState(StatementSyntax node)
 {
     var nextState = currentState.NextState;
     var next = node.GetNextStatement();
     if (next != null && !(next is EmptyStatementSyntax))
     {
         nextState = new State(this) { NextState = currentState.NextState, Germ = currentState.Germ };
     }
     return nextState;
 }