Ejemplo n.º 1
0
        //private Method TraverseStatementSyntax(StatementSyntax ss)
        //{
        //    Method retMethod = new Method();
        //    //TODO
        //    //Get catches for decisions
        //    if (ss is DoStatementSyntax)
        //    {
        //        DoWhileLoop dwl = TraverseDoStatements(ss as DoStatementSyntax);
        //        dwl.IsNested = true;
        //        retMethod.Decisions.DoWhileLoops.Add(dwl);
        //    }
        //    else if (ss is ExpressionStatementSyntax)
        //    {
        //        Method tempMethod = TraverseExpressionStatementSyntax(ss as ExpressionStatementSyntax);
        //        retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
        //        retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
        //    }
        //    else if (ss is ForEachStatementSyntax)
        //    {
        //        ForEachStatement fes = TraverseForEachStatements(ss as ForEachStatementSyntax);
        //        fes.IsNested = true;
        //        retMethod.Decisions.ForEachStatements.Add(fes);
        //    }
        //    else if (ss is ForStatementSyntax)
        //    {
        //        ForStatement fs = TraverseForStatements(ss as ForStatementSyntax);
        //        fs.IsNested = true;
        //        retMethod.Decisions.ForStatements.Add(fs);
        //    }
        //    else if (ss is IfStatementSyntax)
        //    {
        //        IfStatement ifstm = TraverseIfStatements(ss as IfStatementSyntax);
        //        ifstm.IsNested = true;
        //        retMethod.Decisions.IfStatements.Add(ifstm);
        //    }
        //    else if (ss is LocalDeclarationStatementSyntax)
        //    {
        //        Model.Type tempType = new Model.Type();
        //        LocalDeclarationStatementSyntax ldss = ss as LocalDeclarationStatementSyntax;
        //        if (ldss.Declaration != null)
        //        {
        //            VariableDeclarationSyntax vds = ldss.Declaration;
        //            tempType.Name = vds.Type.ToString();
        //            tempType.IsKnownType = true;
        //            tempType.IsNotUserDefined = true;
        //        }
        //        Method tempMethod = TransverseAccessVars(ss as LocalDeclarationStatementSyntax);
        //        //NOT SURE if this will work but here goes
        //        tempMethod.AccessedVariables[0].Type = tempType;
        //        retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
        //        retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
        //    }
        //    else if (ss is SwitchStatementSyntax)
        //    {
        //        SwitchStatement switchStm = TraverseSwitchStatements(ss as SwitchStatementSyntax);
        //        switchStm.IsNested = true;
        //        retMethod.Decisions.SwitchStatements.Add(switchStm);
        //    }
        //    else if (ss is WhileStatementSyntax)
        //    {
        //        WhileLoop wl = TraverseWhileLoops(ss as WhileStatementSyntax);
        //        wl.IsNested = true;
        //        retMethod.Decisions.WhileLoops.Add(wl);
        //    }
        //    return retMethod;
        //}
        private Method TraverseExpressionStatementSyntax(ExpressionStatementSyntax ess)
        {
            Method retMethod = new Method();

            if (ess.HasLeadingTrivia)
            {
                SetOuterComments(retMethod, ess.GetLeadingTrivia().ToFullString());
            }

            if (ess.HasTrailingTrivia)
            {
                SetInnerComments(retMethod, ess.GetTrailingTrivia().ToFullString());
            }

            var vars = from aVar in ess.ChildNodes().OfType<BinaryExpressionSyntax>() select aVar;
            foreach (BinaryExpressionSyntax bes in vars)
            {
                Method tempMethod = TraverseBinaryExpression(bes);
                retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
                retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            var invokedMethods = from aInvokedMethod in ess.ChildNodes().OfType<InvocationExpressionSyntax>() select aInvokedMethod;
            foreach (InvocationExpressionSyntax ies in invokedMethods)
            {
                Method tempMethod = TraverseInvocationExpression(ies);
                retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
                retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
            }
            var postfixUnaryExpressions = from aPostfixUnaryExpression in ess.ChildNodes().OfType<PostfixUnaryExpressionSyntax>() select aPostfixUnaryExpression;
            foreach (PostfixUnaryExpressionSyntax pues in postfixUnaryExpressions)
            {
                Method tempMethod = TraversePostfixUnaryExpressions(pues);
                retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
                retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            var prefixUnaryExpressions = from aPrefixUnaryExpressions in ess.ChildNodes().OfType<PrefixUnaryExpressionSyntax>() select aPrefixUnaryExpressions;
            foreach (PrefixUnaryExpressionSyntax pues in prefixUnaryExpressions)
            {
                Method tempMethod = TraversePrefixUnaryExpressions(pues);
                retMethod.AccessedVariables.AddRange(tempMethod.AccessedVariables);
                retMethod.InvokedMethods.AddRange(tempMethod.InvokedMethods);
            }
            return retMethod;
        }