public override ExpressionKind Eat(ISnapshot snapshot, IReferenceExpression expression)
        {
            var parentKind = expression.QualifierExpression != null
                ? Eater.Eat(snapshot, expression.QualifierExpression)
                : ExpressionKind.None;

            if (parentKind == ExpressionKind.None)
            {
                var declaredElement = _eatExpressionHelper.GetReferenceElement(expression);

                // TODO: declared element can be method: case: event += obj.Method;
                // TODO: declared element can be parameter
                // TODO: Property(Field) can be Stub, Mock or Target
                if (declaredElement is IProperty)
                {
                    return(_typeEater.EatVariableType(snapshot, (declaredElement as IProperty).Type));
                }

                if (declaredElement is IField)
                {
                    return(_typeEater.EatVariableType(snapshot, (declaredElement as IField).Type));
                }

                if (declaredElement is IEvent)
                {
                    return(ExpressionKind.Stub);
                }

                if (declaredElement is ILocalConstantDeclaration)
                {
                    return(ExpressionKind.Stub);
                }

                if (declaredElement is IVariableDeclaration)
                {
                    return(snapshot.GetVariableKind(declaredElement as IVariableDeclaration));
                }

                if (declaredElement is IClass)
                {
                    return(ExpressionKind.None);
                }

                throw new UnexpectedReferenceTypeException(declaredElement, this, expression);
            }
            else
            {
                return(_kindHelper.ReferenceKindByParentReferenceKind(parentKind));
            }
        }
Exemple #2
0
        public override void Eat(ISnapshot snapshot, ILocalVariableDeclaration variableDeclaration)
        {
            if (variableDeclaration.Initial == null)
            {
                var typeKind = _typeEater.EatVariableType(snapshot, variableDeclaration.Type);
                snapshot.Add(typeKind, variableDeclaration);
                return;
            }

            ExpressionKind kind = _variableInitializerEater.Eat(snapshot, variableDeclaration.Initial);

            if (kind == ExpressionKind.StubCandidate)
            {
                snapshot.Add(ExpressionKind.Stub, variableDeclaration);
                return;
            }

            if (kind == ExpressionKind.TargetCall || kind == ExpressionKind.Assert)
            {
                snapshot.Add(ExpressionKind.Result, variableDeclaration);
                return;
            }

            snapshot.Add(kind, variableDeclaration);
        }