/// <summary>
        /// update info based on the expression
        /// </summary>
        /// <param name="exp"></param>
        public void UpdateByExpression(Expression exp)
        {
            if (exp is VariableDeclaration)
            {
                //variable declaration expression
                var          vdExp = (VariableDeclaration)exp;
                VariableInfo vi    = new VariableInfo(vdExp);
                VariablesInfo.Add(vi);

                //update if it contains assignment
                if (vdExp.Initializer != null)
                {
                    var subExps = new List <Expression>();
                    if (vdExp.Initializer.Components.Count == 0)
                    {
                        subExps.Add(vdExp.Initializer);
                    }
                    else
                    {
                        subExps = vdExp.Initializer.Components.ToList();
                    }
                    UpdateAssignmentExpRightHand(subExps, 0, vi, false);
                    //TO DO: ex. = new school()
                }
            }
            else if (exp is MethodCall)
            {
                //Method call expression
                var mcExp = (MethodCall)exp;
                UpdateMethodCall(mcExp);
            }
            else
            {
                //Update the expression
                var subExps = exp.Components.ToList();

                int curPos = 0;

                // Checks keyword new
                if (subExps.Count > 0)
                {
                    var oUse = subExps.ElementAt(0) as OperatorUse;
                    if (oUse != null && oUse.Text == "new")
                    {
                        if (InReturnStmt > 0)
                        {
                            IsReturnNewObj = true;
                        }
                        curPos++;
                    }
                }
                UpdateByExpToTheEnd(subExps, curPos);
            }
        }
Exemple #2
0
        /// <summary>
        /// update info based on the expression
        /// </summary>
        /// <param name="exp"></param>
        public void UpdateByExpression(Expression exp)
        {
            if (exp is VariableDeclaration)
            {
                //variable declaration expression
                var          vdExp = (VariableDeclaration)exp;
                VariableInfo vi    = new VariableInfo(vdExp);
                VariablesInfo.Add(vi);

                //update if it contains assignment
                if (vdExp.Initializer != null)
                {
                    var subExps = new List <Expression>();
                    if (vdExp.Initializer.Components.Count == 0)
                    {
                        subExps.Add(vdExp.Initializer);
                    }
                    else
                    {
                        subExps = vdExp.Initializer.Components.ToList();
                    }
                    UpdateAssignmentExpRightHand(subExps, 0, vi.Variable, false);
                    //TO DO: ex. = new school()
                }
                else
                {
                    //Special process,  since Linq is not in Srcml.net
                    if (vdExp.Location.EndingLineNumber - vdExp.Location.StartingLineNumber > 1)
                    {
                        var assignedVar = vdExp;
                        HashSet <VariableDeclaration> AssigningVars = new HashSet <VariableDeclaration>();
                        Statement stmt         = vdExp.ParentStatement;
                        var       assigningVar = this.VAssignmentManager.FindMostComplecatedVD();
                        if (assigningVar != null)
                        {
                            AssigningVars.Add(assigningVar);
                        }
                        if (AssigningVars.Count > 0 && stmt != null)
                        {
                            VAssignmentManager.AddNewRelations(assignedVar, AssigningVars, stmt);
                        }
                    }
                }
            }
            else if (exp is MethodCall)
            {
                //Method call expression
                var mcExp = (MethodCall)exp;
                UpdateMethodCall(mcExp);
            }
            else
            {
                //Update the expression
                var subExps = exp.Components.ToList();

                int curPos = 0;

                // Checks keyword new
                if (subExps.Count > 0)
                {
                    var oUse = subExps.ElementAt(0) as OperatorUse;
                    if (oUse != null && oUse.Text == "new")
                    {
                        if (InReturnStmt > 0)
                        {
                            IsReturnNewObj = true;
                        }
                        curPos++;
                    }
                }
                UpdateByExpToTheEnd(subExps, curPos);
            }
        }