protected override bool CoversAssignment(AssignmentStatement assignmentStatement) { Method sourceConstructor = ExtractConstructor(assignmentStatement.Source); bool sourceIsStringBuilderConstructor = sourceConstructor != null && _stringBuilderConstructorFullnames.Contains(sourceConstructor.FullName); return(IntrospectionUtility.IsVariable(assignmentStatement.Target) && sourceIsStringBuilderConstructor); }
public void IsVariable_Indexer_ReturnsTrue() { Method sampleMethod = TestHelper.GetSample <IntrospectionUtility_ClassSample> ("ArrayVariableAndIndexer"); Block sampleBlock = (Block)sampleMethod.Body.Statements[0]; AssignmentStatement sampleAssignment = (AssignmentStatement)sampleBlock.Statements[2]; Expression sample = sampleAssignment.Target; Assert.That(IntrospectionUtility.IsVariable(sample), Is.True); }
public void IsVariable_Method_IsFalse() { Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField"); Block expressionBlock = (Block)sample.Body.Statements[0]; ExpressionStatement expressionStatement = (ExpressionStatement)expressionBlock.Statements[1]; UnaryExpression sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression; MethodCall sampleMethodCall = (MethodCall)sampleUnaryExpression.Operand; bool methodIsVariable = IntrospectionUtility.IsVariable(sampleMethodCall); Assert.That(methodIsVariable, Is.False); }
public void IsVariable_FieldInMembebinding_IsTrue() { Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField"); Block expressionBlock = (Block)sample.Body.Statements[0]; ExpressionStatement expressionStatement = (ExpressionStatement)expressionBlock.Statements[1]; UnaryExpression sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression; MethodCall sampleMethodCall = (MethodCall)sampleUnaryExpression.Operand; Expression sampleExpression = sampleMethodCall.Operands[0]; bool fieldIsVariable = IntrospectionUtility.IsVariable(sampleExpression); Assert.That(fieldIsVariable, Is.True); }
public void IsVariableWithOutParameter_Method_IsFalseAndReturnsNullAsVariableName() { Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField"); Block expressionBlock = (Block)sample.Body.Statements[0]; ExpressionStatement expressionStatement = (ExpressionStatement)expressionBlock.Statements[1]; UnaryExpression sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression; MethodCall sampleMethodCall = (MethodCall)sampleUnaryExpression.Operand; string variableName; bool methodIsVariable = IntrospectionUtility.IsVariable(sampleMethodCall, out variableName); bool correctName = variableName == null; Assert.That(!methodIsVariable && correctName, Is.True); }
public void IsVariableWithOutParameter_FieldInMemberbinding_IsTrueAndReturnsFieldName() { Method sample = TestHelper.GetSample <IntrospectionUtility_ClassSample>("UsingField"); Block expressionBlock = (Block)sample.Body.Statements[0]; ExpressionStatement expressionStatement = (ExpressionStatement)expressionBlock.Statements[1]; UnaryExpression sampleUnaryExpression = (UnaryExpression)expressionStatement.Expression; MethodCall sampleMethodCall = (MethodCall)sampleUnaryExpression.Operand; Expression sampleExpression = sampleMethodCall.Operands[0]; string variableName; bool fieldIsVariable = IntrospectionUtility.IsVariable(sampleExpression, out variableName); bool correctName = variableName == "_field"; Assert.That(fieldIsVariable && correctName, Is.True); }
private void UpdateOutAndRefSymbols(MethodCall methodCall) { Method method = IntrospectionUtility.ExtractMethod(methodCall); for (int i = 0; i < methodCall.Operands.Count; i++) { bool isReturnParameter = IntrospectionUtility.IsVariable(methodCall.Operands[i]) && (method.Parameters[i].IsOut || method.Parameters[i].Type is Reference); if (isReturnParameter) { PassReturnFragmentTypeToContext(methodCall.Operands[i], method.Parameters[i]); } } }
public Fragment InferFragmentType(MethodCall methodCall, ISymbolTable context) { Fragment returnFragment = Fragment.CreateEmpty(); Method method = IntrospectionUtility.ExtractMethod(methodCall); if (Infers(method) && methodCall.Callee is MemberBinding) { MemberBinding memberBinding = (MemberBinding)methodCall.Callee; string variableName; if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName)) { returnFragment = context.GetFragmentType(variableName); } } return(returnFragment); }
public void Analyze(MethodCall methodCall, ISymbolTable context, List <IPreCondition> preConditions) { Method method = IntrospectionUtility.ExtractMethod(methodCall); if (Analyzes(method) && methodCall.Callee is MemberBinding) { MemberBinding memberBinding = (MemberBinding)methodCall.Callee; if (IsFragmentParameterInferenceMethod(method)) { string variableName; if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName)) { Fragment parameterFragment = ParameterFragmentUtility.ParameterFragmentIntersection(methodCall, context); Fragment targetObjectFragment = context.GetFragmentType(variableName); if (targetObjectFragment == Fragment.CreateLiteral() || targetObjectFragment.Undefined) { context.MakeSafe(variableName, parameterFragment); } else { if (targetObjectFragment == Fragment.CreateEmpty() && parameterFragment != Fragment.CreateLiteral()) // && parameterFragment != Fragment.CreateEmpty() { ProblemMetadata problemMetadata = new ProblemMetadata(methodCall.UniqueKey, methodCall.SourceContext, parameterFragment, targetObjectFragment); IPreCondition precondition = new CustomInferencePreCondition(variableName, parameterFragment, problemMetadata); preConditions.Add(precondition); } else if (!FragmentUtility.FragmentTypesAssignable(parameterFragment, targetObjectFragment)) { context.MakeUnsafe(variableName); } } } } else if (!IsSafeMethod(method)) { string variableName; if (IntrospectionUtility.IsVariable(memberBinding.TargetObject, out variableName)) { context.MakeUnsafe(variableName); } } } }
private bool ExpressionIsVariableFromPrecedingBlock(Expression operand, out string variableName) { return(IntrospectionUtility.IsVariable(operand, out variableName) && !_symbolTable.Contains(variableName)); }