public void GetField_NonFieldAssignment_ReturnsNull()
        {
            Method sample          = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("NonFieldAssignment");
            Block  assignmentBlock = (Block)sample.Body.Statements[0];
            AssignmentStatement assignmentStatement = (AssignmentStatement)assignmentBlock.Statements[1];
            Expression          sampleExpression    = assignmentStatement.Target;
            Field extractedField    = IntrospectionUtility.GetField(sampleExpression);
            bool  extractionCorrect = extractedField == null;

            Assert.That(extractionCorrect, Is.True);
        }
        public void GetField_FieldExpression_ReturnsContainedField()
        {
            Method sample          = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("FieldAssignment");
            Block  assignmentBlock = (Block)sample.Body.Statements[0];
            AssignmentStatement assignmentStatement = (AssignmentStatement)assignmentBlock.Statements[1];
            Expression          sampleExpression    = assignmentStatement.Target;
            Field extractedField = IntrospectionUtility.GetField(sampleExpression);

            Member boundMember       = ((MemberBinding)sampleExpression).BoundMember;
            bool   extractionCorrect = extractedField.UniqueKey == boundMember.UniqueKey;

            Assert.That(extractionCorrect, Is.True);
        }
Exemplo n.º 3
0
        private void ValidateAssignmentOnField(AssignmentStatement assignmentStatement, HandleContext context)
        {
            Field    targetField        = IntrospectionUtility.GetField(assignmentStatement.Target);
            Fragment targetFragmentType = FragmentUtility.GetFragmentType(targetField.Attributes);
            Fragment givenFragmentType  = context.SymbolTable.InferFragmentType(assignmentStatement.Source);

            if (!FragmentUtility.FragmentTypesAssignable(givenFragmentType, targetFragmentType))
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(
                    targetField.UniqueKey,
                    targetField.SourceContext,
                    targetFragmentType,
                    givenFragmentType);
                _blockParserContext.ProblemPipe.AddProblem(problemMetadata);
            }
        }
Exemplo n.º 4
0
        private void AddAssignmentPreCondition(AssignmentStatement assignmentStatement, HandleContext context)
        {
            Field    targetField        = IntrospectionUtility.GetField(assignmentStatement.Target);
            Fragment targetFragmentType = FragmentUtility.GetFragmentType(targetField.Attributes);

            if (targetFragmentType != Fragment.CreateEmpty())
            {
                ProblemMetadata problemMetadata = new ProblemMetadata(
                    assignmentStatement.UniqueKey,
                    assignmentStatement.SourceContext,
                    targetFragmentType,
                    Fragment.CreateNamed("??"));
                string sourceSymbol = IntrospectionUtility.GetVariableName(assignmentStatement.Source);
                if (sourceSymbol != null)
                {
                    AssignabilityPreCondition preCondition = new AssignabilityPreCondition(sourceSymbol, targetFragmentType, problemMetadata);
                    context.PreConditions.Add(preCondition);
                }
            }
        }