Example #1
0
 /// <summary>
 ///     Traverses the thrown exception.
 /// </summary>
 public void Traverse(IThrownException thrownException)
 {
     Contract.Requires(thrownException != null);
     preorderVisitor.Visit(thrownException);
     if (StopTraversal)
     {
         return;
     }
     TraverseChildren(thrownException);
 }
Example #2
0
 /// <summary>
 ///     Traverses the children of the thrown exception.
 /// </summary>
 public virtual void TraverseChildren(IThrownException thrownException)
 {
     Contract.Requires(thrownException != null);
     Traverse(thrownException.ExceptionType);
     if (StopTraversal)
     {
         return;
     }
     Traverse(thrownException.Postcondition);
 }
Example #3
0
        /// <summary>
        /// Creates a new package for an IThrownException contract.
        /// </summary>
        public XThrownException(IMetadataHost host, IThrownException thrownException, string inheritedFrom, string inheritedFromTypeName, DocTracker docTracker)
            : base(host, inheritedFrom, inheritedFromTypeName, docTracker)
        {
            Contract.Requires(docTracker != null);
            Contract.Requires(thrownException != null);
            Contract.Requires(thrownException.Postcondition != null);
            Contract.Requires(thrownException.ExceptionType != null);
            var post = thrownException.Postcondition;

            this.thrownException = thrownException;
            Contract.Assert(this.thrownException.Postcondition != null);
            var unspecializedExceptionType = MethodHelper.Unspecialize(thrownException.ExceptionType);

            Contract.Assert(this.thrownException.Postcondition != null);
            this.exception = TypeHelper.GetTypeName(unspecializedExceptionType, NameFormattingOptions.DocumentationId);
            Contract.Assert(this.thrownException == thrownException);
            Contract.Assert(thrownException.Postcondition == post);
            Contract.Assert(this.thrownException.Postcondition != null);
        }
Example #4
0
 public void Visit(IThrownException thrownException)
 {
     Contract.Assume(false);
 }
Example #5
0
 /// <summary>
 /// Makes a shallow copy of the given thrown exception.
 /// </summary>
 public virtual ThrownException Copy(IThrownException thrownException)
 {
     return new ThrownException(thrownException);
 }
Example #6
0
 //TODO: copy statement contract
 /// <summary>
 /// Makes a deep copy of the given thrown exception.
 /// </summary>
 public ThrownException Copy(IThrownException thrownException)
 {
     var mutableCopy = this.shallowCopier.Copy(thrownException);
       mutableCopy.ExceptionType = this.Copy(mutableCopy.ExceptionType);
       mutableCopy.Postcondition = this.Copy(mutableCopy.Postcondition);
       return mutableCopy;
 }
Example #7
0
 /// <summary>
 /// Visits the specified thrown exception.
 /// </summary>
 /// <param name="thrownException">The thrown exception.</param>
 public virtual IThrownException Visit(IThrownException thrownException)
 {
     ThrownException mutableThrownException = thrownException as ThrownException;
       if (!this.copyOnlyIfNotAlreadyMutable || mutableThrownException == null)
     mutableThrownException = new ThrownException(thrownException);
       return this.Visit(mutableThrownException);
 }
Example #8
0
 /// <summary>
 /// Visits the given thrown exception.
 /// </summary>
 public virtual void Visit(IThrownException thrownException)
 {
 }
Example #9
0
 /// <summary>
 /// Traverses the children of the thrown exception.
 /// </summary>
 public virtual void TraverseChildren(IThrownException thrownException)
 {
     Contract.Requires(thrownException != null);
       this.Traverse(thrownException.ExceptionType);
       if (this.StopTraversal) return;
       this.Traverse(thrownException.Postcondition);
 }
Example #10
0
    /// <summary>
    /// Makes a shallow copy of the given thrown exception.
    /// </summary>
    public virtual ThrownException Copy(IThrownException thrownException) {
      Contract.Requires(thrownException != null);
      Contract.Ensures(Contract.Result<ThrownException>() != null);

      return new ThrownException(thrownException);
    }
Example #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="thrownException"></param>
 public ThrownException(IThrownException thrownException)
 {
     this.exceptionType = thrownException.ExceptionType;
     this.postcondition = thrownException.Postcondition;
 }
Example #12
0
 private static List<IThrownException> FilterUserMessage(IContractAwareHost host, IEnumerable<IThrownException> thrownExceptions, ITypeDefinition typeDefinition) {
   int n = (int)IteratorHelper.EnumerableCount(thrownExceptions);
   var filteredThrownExceptions = new IThrownException[n];
   var i = 0;
   foreach (var te in thrownExceptions) {
     if (CanAccess(te.Postcondition.Description, typeDefinition)) {
       filteredThrownExceptions[i] = te;
     } else {
       var newP = new Postcondition(te.Postcondition);
       newP.Description = null;
       filteredThrownExceptions[i] = new ThrownException() {
         ExceptionType = te.ExceptionType,
         Postcondition = newP,
       };
     }
     i++;
   }
   return new List<IThrownException>(filteredThrownExceptions);
 }
Example #13
0
 /// <summary>
 /// Rewrites the given thrown exception.
 /// </summary>
 public virtual IThrownException Rewrite(IThrownException thrownException)
 {
     var mutableThrownException = thrownException as ThrownException;
       if (mutableThrownException == null) return thrownException;
       this.RewriteChildren(mutableThrownException);
       return mutableThrownException;
 }
Example #14
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given thrown exception.
 /// </summary>
 public virtual void Visit(IThrownException thrownException)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(thrownException);
       this.Visit(thrownException.ExceptionType);
       this.Visit(thrownException.Postcondition);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
Example #15
0
    //TODO: copy statement contract

    /// <summary>
    /// Makes a deep copy of the given thrown exception.
    /// </summary>
    public ThrownException Copy(IThrownException thrownException) {
      Contract.Requires(thrownException != null);
      Contract.Ensures(Contract.Result<ThrownException>() != null);

      var mutableCopy = this.shallowCopier.Copy(thrownException);
      mutableCopy.ExceptionType = this.Copy(mutableCopy.ExceptionType);
      mutableCopy.Postcondition = this.Copy(mutableCopy.Postcondition);
      return mutableCopy;
    }
Example #16
0
 /// <summary>
 /// Traverses the thrown exception.
 /// </summary>
 public void Traverse(IThrownException thrownException)
 {
     Contract.Requires(thrownException != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(thrownException);
       if (this.StopTraversal) return;
       this.TraverseChildren(thrownException);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(thrownException);
 }
Example #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="thrownException"></param>
 public ThrownException(IThrownException thrownException) {
   this.exceptionType = thrownException.ExceptionType;
   this.postcondition = thrownException.Postcondition;
 }
Example #18
0
 public void Visit(IThrownException thrownException)
 {
     Contract.Assume(false);
 }
Example #19
0
 /// <summary>
 /// Get the mutable copy of a thrown exception.
 /// </summary>
 /// <param name="thrownException"></param>
 /// <returns></returns>
 public virtual ThrownException GetMutableCopy(IThrownException thrownException)
 {
     object cachedValue;
       if (this.cache.TryGetValue(thrownException, out cachedValue))
     return (ThrownException)cachedValue;
       var result = new ThrownException(thrownException);
       // Probably not necessary, no two thrown exceptions are shared.
       this.cache.Add(thrownException, result);
       this.cache.Add(result, result);
       return result;
 }
Example #20
0
 public void Visit(IThrownException thrownException)
 {
     Contract.Requires(thrownException != null);
       throw new NotImplementedException();
 }
Example #21
0
 /// <summary>
 /// Returns a deep copy of the <param name="thrownException"/>.
 /// </summary>
 public virtual IThrownException Substitute(IThrownException thrownException)
 {
     this.coneAlreadyFixed = true;
       return this.DeepCopy(new ThrownException(thrownException));
 }
Example #22
0
 /// <summary>
 /// Creates a new package for an IThrownException contract.
 /// </summary>
 public XThrownException(IMetadataHost host, IThrownException thrownException, string inheritedFrom, string inheritedFromTypeName, DocTracker docTracker)
   : base(host, inheritedFrom, inheritedFromTypeName, docTracker) {
   Contract.Requires(docTracker != null);
   Contract.Requires(thrownException != null);
   Contract.Requires(thrownException.Postcondition != null);
   Contract.Requires(thrownException.ExceptionType != null);
   var post = thrownException.Postcondition;
   this.thrownException = thrownException;
   Contract.Assert(this.thrownException.Postcondition != null);
   var unspecializedExceptionType = MethodHelper.Unspecialize(thrownException.ExceptionType);
   Contract.Assert(this.thrownException.Postcondition != null);
   this.exception = TypeHelper.GetTypeName(unspecializedExceptionType, NameFormattingOptions.DocumentationId);
   Contract.Assert(this.thrownException == thrownException);
   Contract.Assert(thrownException.Postcondition == post);
   Contract.Assert(this.thrownException.Postcondition != null);
   }
Example #23
0
 /// <summary>
 /// Visits the specified thrown exception.
 /// </summary>
 /// <param name="thrownException">The thrown exception.</param>
 public virtual IThrownException Visit(IThrownException thrownException)
 {
     if (this.stopTraversal) return thrownException;
       ThrownException mutableThrownException = thrownException as ThrownException;
       if (mutableThrownException == null) return thrownException;
       mutableThrownException.ExceptionType = this.Visit(mutableThrownException.ExceptionType);
       mutableThrownException.Postcondition = this.Visit(mutableThrownException.Postcondition);
       return mutableThrownException;
 }