/// <summary> /// Traverses the thrown exception. /// </summary> public void Traverse(IThrownException thrownException) { Contract.Requires(thrownException != null); preorderVisitor.Visit(thrownException); if (StopTraversal) { return; } TraverseChildren(thrownException); }
/// <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); }
/// <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); }
public void Visit(IThrownException thrownException) { Contract.Assume(false); }
/// <summary> /// Makes a shallow copy of the given thrown exception. /// </summary> public virtual ThrownException Copy(IThrownException thrownException) { return new ThrownException(thrownException); }
//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; }
/// <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); }
/// <summary> /// Visits the given thrown exception. /// </summary> public virtual void Visit(IThrownException thrownException) { }
/// <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); }
/// <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); }
/// <summary> /// /// </summary> /// <param name="thrownException"></param> public ThrownException(IThrownException thrownException) { this.exceptionType = thrownException.ExceptionType; this.postcondition = thrownException.Postcondition; }
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); }
/// <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; }
//^ 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(); }
//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; }
/// <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); }
/// <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; }
public void Visit(IThrownException thrownException) { Contract.Requires(thrownException != null); throw new NotImplementedException(); }
/// <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)); }
/// <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; }