internal ContractEnsures(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) { _contractResultArgument = predicateExpression.Predicates.Select(p => p.Argument) .OfType<ContractResultPredicateArgument>() .FirstOrDefault(); }
private IfThrowPrecondition(IIfStatement ifStatement, PredicateExpression predicateExpression, Message message, IClrTypeName exceptionTypeName) : base(ifStatement, predicateExpression, message) { Contract.Requires(ifStatement != null); Contract.Requires(exceptionTypeName != null); _ifStatement = ifStatement; _exceptionTypeName = exceptionTypeName; }
protected ContractStatement(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) { Contract.Requires(statement != null); Contract.Requires(predicateExpression != null); Contract.Requires(message != null); _statement = statement; _predicateExpression = predicateExpression; _message = message; }
internal static CodeContractAssertion FromInvocationExpression(IInvocationExpression invocationExpression) { Contract.Requires(invocationExpression != null); var statement = invocationExpression.GetContainingStatement(); Contract.Assert(statement != null); ContractAssertionType?assertionType = GetContractAssertionType(invocationExpression); if (assertionType == null) { return(null); } Contract.Assert(invocationExpression.Arguments.Count != 0, "Invocation expression should have at least one argument!"); IExpression originalPredicateExpression = invocationExpression.Arguments[0].Expression; var predicateExpression = PredicateExpression.Create(originalPredicateExpression); var message = ExtractMessage(invocationExpression); // TODO: switch to dictionary of factory methods? switch (assertionType.Value) { case ContractAssertionType.Requires: return(new ContractRequires(statement, invocationExpression, predicateExpression, message)); case ContractAssertionType.Ensures: return(new ContractEnsures(statement, predicateExpression, message)); case ContractAssertionType.Invariant: return(new ContractInvariant(statement, predicateExpression, message)); case ContractAssertionType.Assert: return(new ContractAssert(statement, predicateExpression, message)); case ContractAssertionType.Assume: return(new ContractAssume(statement, predicateExpression, message)); default: Contract.Assert(false, "Unknown assertion type: " + assertionType.Value); return(null); } }
internal static IfThrowPrecondition TryCreate(ICSharpStatement statement) { Contract.Requires(statement != null); var ifStatement = statement as IIfStatement; if (ifStatement == null || ifStatement.Condition == null) { return(null); } var predicateExpression = PredicateExpression.Create(ifStatement.Condition); IThrowStatement throwStatement = ParseThrowStatement(ifStatement); if (throwStatement == null) { return(null); } var arguments = throwStatement.GetArguments().ToList(); var exceptionType = throwStatement.GetExceptionType(); if (exceptionType == null) { return(null); } // We can deal with any exception derived from the ArgumentException if (!IsDerivedOrEqualFor(exceptionType, typeof(ArgumentException)) || arguments.Count == 0) { return(null); } var message = arguments.Skip(1).FirstOrDefault() .Return(ExtractMessage, NoMessage.Instance); // message is optional and should be second argument return(new IfThrowPrecondition(ifStatement, predicateExpression, message, exceptionType)); }
internal ContractRequires(ICSharpStatement statement, IInvocationExpression invocationExpression, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) { GenericArgumentDeclaredType = GetGenericRequiresType(invocationExpression); }
internal ContractInvariant(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) { }
internal ContractInvariant(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) {}
public PreconditionValidator(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) {}
public PreconditionValidator(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) { }
protected CodeContractAssertion(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) {}
protected CodeContractAssertion(ICSharpStatement statement, PredicateExpression predicateExpression, Message message) : base(statement, predicateExpression, message) { }