Beispiel #1
0
 private IEnumerable <SyntaxNode> VisitWhileBlock(WhileBlockSyntax node)
 {
     if (!node.Statements.Any() && NoCommentsBefore(node.EndWhileStatement))
     {
         yield return(node.WhileStatement);
     }
 }
 public override void VisitWhileBlock(WhileBlockSyntax node) =>
 counter.CheckNesting(node.WhileStatement.WhileKeyword, () => base.VisitWhileBlock(node));
Beispiel #3
0
 public override void VisitWhileBlock(WhileBlockSyntax node)
 {
     State.IncreaseComplexityByNestingPlusOne(node.WhileStatement.WhileKeyword);
     State.VisitWithNesting(node, base.VisitWhileBlock);
 }
Beispiel #4
0
 public override void VisitWhileBlock(WhileBlockSyntax node)
 {
     LogicalLineCount++;
     base.VisitWhileBlock(node);
 }
        private WhileLoop TraverseWhileLoop(WhileBlockSyntax wbs, ref int returnCnt, bool nested = false)
        {
            WhileLoop whileLoop = new WhileLoop();
            whileLoop.IsNested = nested;
            WhileStatementSyntax wss = wbs.WhileStatement;

            foreach (SyntaxNode sn in wss.Condition.DescendantNodesAndSelf())
            {
                if (sn is BinaryExpressionSyntax)
                {
                    whileLoop.ConditionCount++;
                }
                else if (sn is IdentifierNameSyntax)
                {
                    Variables variable = new Variables();
                    variable.IsReferenced = true;

                    variable.Name = (sn as IdentifierNameSyntax).Identifier.ValueText;
                    whileLoop.AccessedVars.Add(variable);
                }
            }

            foreach (StatementSyntax ss in wbs.Statements)
            {
                if (ss is AssignmentStatementSyntax)
                {
                    //TODO: need to look at more than just then name!
                    Method tempMethod = TraverseAccessVars(ss as AssignmentStatementSyntax);

                    whileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    whileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is LocalDeclarationStatementSyntax)
                {
                    Method tempMethod = TraverseVarDecls(ss as LocalDeclarationStatementSyntax);
                        whileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables);
                        whileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                }
                else if (ss is SingleLineIfStatementSyntax)
                {
                    Decisions decision = TraverseIfStatement(ss as SingleLineIfStatementSyntax, ref returnCnt, true);
                    whileLoop.Nested.AddRange(decision.IfStatements);
                    whileLoop.Nested.AddRange(decision.ElseStatements);
                }
                else if (ss is MultiLineIfBlockSyntax)
                {
                    Decisions decisions = TraverseMultiIfStatement(ss as MultiLineIfBlockSyntax, ref returnCnt, true);
                    whileLoop.Nested.AddRange(decisions.IfStatements);
                    whileLoop.Nested.AddRange(decisions.ElseStatements);
                }
                else if (ss is ElseStatementSyntax)
                {
                    whileLoop.Nested.Add(TravsereElseStatement(ss as ElseStatementSyntax, ref returnCnt, true));
                }
                else if (ss is ForBlockSyntax)
                {
                    Decisions tempDecision = TraverseForStatement(ss as ForBlockSyntax, ref returnCnt, true);
                    whileLoop.Nested.AddRange(tempDecision.IfStatements);
                    whileLoop.Nested.AddRange(tempDecision.ElseStatements);
                    whileLoop.Nested.AddRange(tempDecision.ForEachStatements);
                    whileLoop.Nested.AddRange(tempDecision.ForStatements);
                    whileLoop.Nested.AddRange(tempDecision.WhileLoops);
                    whileLoop.Nested.AddRange(tempDecision.DoWhileLoops);
                    whileLoop.Nested.AddRange(tempDecision.Catches);
                    whileLoop.Nested.AddRange(tempDecision.SwitchStatements);
                }
                else if (ss is SelectBlockSyntax)
                {
                    whileLoop.Nested.Add(TraverseSwitchStatement(ss as SelectBlockSyntax, ref returnCnt, true));
                }
                else if (ss is DoLoopBlockSyntax)
                {
                    whileLoop.Nested.Add(TraverseDoWhileLoop(ss as DoLoopBlockSyntax, ref returnCnt, true));
                }
                else if (ss is WhileBlockSyntax)
                {
                    whileLoop.Nested.Add(TraverseWhileLoop(ss as WhileBlockSyntax, ref returnCnt, true));
                }
                else if (ss is CallStatementSyntax)
                {
                    whileLoop.InvokedMethods.Add(TraverseInvokedMethod(ss as CallStatementSyntax));
                }
                else if (ss is ReturnStatementSyntax)
                {
                    Method tempMethod = TraverseReturnStatement(ss as ReturnStatementSyntax);
                    whileLoop.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                    whileLoop.AccessedVars.AddRange(tempMethod.AccessedVariables);
                    returnCnt++;
                }
            }
            return whileLoop;
        }