コード例 #1
0
        private void FromIfThrowToRequires(IPrecondition assertion, bool isGeneric)
        {
            // Convertion from if-throw precondition to Contract.Requires
            // contains following steps:
            // 1. Negate condition from the if statement (because if (s == null) throw ANE means that Contract.Requires(s != null))
            // 2. Create Contract.Requires expression (with all optional generic argument and optional message
            // 3. Add required using statements if necessary (for Contract class and Exception type)
            // 4. Replace if-throw statement with newly created contract statement

            var ifThrowAssertion = (IfThrowPrecondition)assertion;

            ICSharpExpression negatedExpression =
                CSharpExpressionUtil.CreateLogicallyNegatedExpression(ifThrowAssertion.IfStatement.Condition);

            Contract.Assert(negatedExpression != null);

            string predicateCheck = negatedExpression.GetText();

            ICSharpStatement newStatement = null;

            if (isGeneric)
            {
                newStatement = CreateGenericContractRequires(ifThrowAssertion.ExceptionTypeName, predicateCheck,
                                                             ifThrowAssertion.Message);
            }
            else
            {
                newStatement = CreateNonGenericContractRequires(predicateCheck, ifThrowAssertion.Message);
            }

            ReplaceStatements(ifThrowAssertion.CSharpStatement, newStatement);
        }
コード例 #2
0
 protected override void AppendTooltip(AddressOfMarshalByRefObjectWarning highlighting, CSharpColorizer colorizer)
 {
     colorizer.AppendPlainText("Passing '");
     colorizer.AppendDeclaredElement(highlighting.Field, EmptySubstitution.INSTANCE, PresenterOptions.QualifiedName, highlighting.ReferenceExpression);
     colorizer.AppendPlainText("' as '");
     colorizer.AppendKeyword(CSharpExpressionUtil.GetKindOfExplicitVariableReferenceCapture(highlighting.ReferenceExpression));
     colorizer.AppendPlainText("' argument may cause a runtime exception because it is a field of a marshal-by-reference class");
 }
コード例 #3
0
            protected override IIfStatement CreateStatement(CSharpElementFactory factory, ICSharpExpression expression)
            {
                var template  = "if($0)" + EmbeddedStatementBracesTemplate;
                var statement = (IIfStatement)factory.CreateStatement(template, expression);

                var negated = CSharpExpressionUtil.CreateLogicallyNegatedExpression(statement.Condition);

                statement.Condition.ReplaceBy(negated.NotNull());

                return(statement);
            }
コード例 #4
0
 private IDeclarationStatement GetDeclarationStatement(IList <ICSharpExpression> usages, IExpectedTypeConstraint typeConstraint)
 {
     try
     {
         var factory        = CSharpElementFactory.GetInstance(_referenceExpression.GetPsiModule());
         var statement      = CreateStubDeclaration(factory, typeConstraint);
         var insertLocation = CSharpExpressionUtil.GetStatementToBeVisibleFromAll(usages);
         return(StatementUtil.InsertStatement(statement, ref insertLocation, true));
     }
     catch (Exception ex)
     {
         File.AppendAllText("c:\\temp\\MillimanPluginErrors.txt", "Exception on " + DateTime.Now + "\n" + ex + "\n\n");
         throw;
     }
 }
コード例 #5
0
 protected override ICSharpExpression CreateExpression(CSharpElementFactory factory, ICSharpExpression expression)
 {
     return(CSharpExpressionUtil.CreateLogicallyNegatedExpression(expression));
 }