/// <summary>Determines whether the specified throw statement is caught.</summary> /// <param name="throwStatement">The throw statement.</param> /// <returns><c>true</c> if the specified throw statement is caught; otherwise, <c>false</c>.</returns> private static bool IsExceptionCaught(IThrowStatement throwStatement) { ITreeNode node = throwStatement.ToTreeNode(); if (node == null) { return true; } while (node != null) { var tryStatement = node as ITryStatement; if (tryStatement != null) { if (IsCatchStatement(throwStatement, tryStatement)) { return true; } } node = node.Parent; } return false; }
public override void VisitThrowStatement(IThrowStatement operation) { if (_finallyBlockNestingDepth > 0) { ThrowStatements.Add(operation); } base.VisitThrowStatement(operation); }
/// <summary> /// Analyzes the documented. /// </summary> /// <param name="throwStatement"> /// The statement. /// </param> /// <returns> /// Returns a list of suggestion bases. /// </returns> public IEnumerable<SuggestionBase> AnalyzeThrowStatement(IThrowStatement throwStatement) { var suggestions = new List<SuggestionBase>(); if (IsExceptionCaught(throwStatement)) { return suggestions; } if (IsThrowStatementDocumented(throwStatement)) { return suggestions; } suggestions.Add(new DocumentThrownExceptionWarning(throwStatement)); return suggestions; }
/// <summary> /// /// </summary> /// <param name="throwStatement"></param> public ThrowStatement(IThrowStatement throwStatement) : base(throwStatement) { this.exception = throwStatement.Exception; }
public virtual void VisitThrowStatement(IThrowStatement operation) { DefaultVisit(operation); }
public void Visit(IThrowStatement throwStatement) { throw new NotImplementedException(); }
/// <summary> /// Performs some computation with the throw statement. /// </summary> /// <param name="throwStatement"></param> public virtual void Visit(IThrowStatement throwStatement) { this.Visit((IStatement)throwStatement); }
/// <summary> /// Traverses the throw statement. /// </summary> public virtual void TraverseChildren(IThrowStatement throwStatement) { Contract.Requires(throwStatement != null); this.TraverseChildren((IStatement)throwStatement); if (this.StopTraversal) return; this.Traverse(throwStatement.Exception); }
/// <summary> /// Performs some computation with the throw statement. /// </summary> /// <param name="throwStatement"></param> public virtual void Visit(IThrowStatement throwStatement) { }
public override void TraverseChildren(IThrowStatement throwStatement) { MethodEnter(throwStatement); base.TraverseChildren(throwStatement); MethodExit(); }
/// <summary> /// Initializes a new instance of the <see cref="ArgumentNullExceptionDescription"/> class. /// </summary> /// <param name="statement">The thrown statement.</param> public ArgumentNullExceptionDescription(IThrowStatement statement) { this.statement = statement; arguments = GetArguments(); }
/// <summary> /// Determines whether [is catch statement] [the specified throw statement]. /// </summary> /// <param name="throwStatement"> /// The throw statement. /// </param> /// <param name="tryStatement"> /// The try statement. /// </param> /// <returns> /// <c>true</c> if [is catch statement] [the specified throw statement]; otherwise, <c>false</c>. /// </returns> private static bool IsCatchStatement(IThrowStatement throwStatement, ITryStatement tryStatement) { var catchClauses = tryStatement.Catches; foreach (var catchClause in catchClauses) { if (throwStatement.Exception == catchClause.ExceptionType) { return true; } } return false; }
/// <summary> /// Determines whether this instance is documented. /// </summary> /// <param name="throwStatement"> /// The throw statement. /// </param> /// <returns> /// <c>true</c> if this instance is documented; otherwise, <c>false</c>. /// </returns> private static bool IsThrowStatementDocumented(IThrowStatement throwStatement) { ITypeMemberDeclaration typeMemberDeclaration = throwStatement.GetContainingTypeMemberDeclaration(); if (typeMemberDeclaration == null) { return true; } IDeclaredElement declaredElement = typeMemberDeclaration.DeclaredElement; if (declaredElement == null) { return true; } var xmlNode = declaredElement.GetXMLDoc(false); if (xmlNode == null) { return false; } var exceptionList = xmlNode.SelectNodes("exception"); if (exceptionList == null || exceptionList.Count == 0) { return false; } var exception = throwStatement.Exception; if (exception == null) { return true; } var type = exception.Type(); var exceptionTypeName = type.GetLongPresentableName(throwStatement.Language); foreach (XmlNode node in exceptionList) { var attribute = node.Attributes["cref"]; if (attribute == null) { continue; } var cref = attribute.Value; if (string.IsNullOrEmpty(cref)) { continue; } if (cref.StartsWith("T:")) { cref = cref.Substring(2); } if (cref == exceptionTypeName) { return true; } } return false; }
public override void TraverseChildren(IThrowStatement throwStatement) { this.exceptionsThrown.Add(throwStatement.Exception.Type); }
public override void VisitThrowStatement(IThrowStatement operation) { base.VisitThrowStatement(operation); }
public override void TraverseChildren(IThrowStatement throwStatement) { this.PrintToken(CSharpToken.Indent); this.PrintToken(CSharpToken.Throw); if (throwStatement.Exception != null) { this.PrintToken(CSharpToken.Space); this.Traverse(throwStatement.Exception); } this.PrintToken(CSharpToken.Semicolon); }
/// <summary> /// Gets the exception. /// </summary> /// <param name="statement"> /// The statement. /// </param> /// <returns> /// The exception. /// </returns> private static IType GetExceptionType(IThrowStatement statement) { if (statement.Exception != null) { // TODO: may throw exception return statement.Exception.Type(); } ITreeNode node = statement.ToTreeNode(); while (node != null && !(node is ICatchClause)) { node = node.Parent; } var catchClause = node as ICatchClause; if (catchClause == null) { return null; } return catchClause.ExceptionType; }
/// <summary> /// Visits the specified throw statement. /// </summary> /// <param name="throwStatement">The throw statement.</param> public override void Visit(IThrowStatement throwStatement) { ThrowStatement mutableThrowStatement = new ThrowStatement(throwStatement); this.resultStatement = this.myCodeCopier.DeepCopy(mutableThrowStatement); }
//^ ensures this.path.Count == old(this.path.Count); /// <summary> /// Traverses the throw statement. /// </summary> /// <param name="throwStatement"></param> public virtual void Visit(IThrowStatement throwStatement) { if (this.stopTraversal) return; //^ int oldCount = this.path.Count; this.path.Push(throwStatement); if (throwStatement.Exception != null) this.Visit(throwStatement.Exception); //^ 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(); }
/// <summary> /// Returns a deep copy of the throw statement. /// </summary> /// <param name="throwStatement"></param> public ThrowStatement Copy(IThrowStatement throwStatement) { var mutableCopy = this.shallowCopier.Copy(throwStatement); mutableCopy.Exception = this.Copy(mutableCopy.Exception); return mutableCopy; }
/// <summary> /// Traverses the throw statement. /// </summary> public void Traverse(IThrowStatement throwStatement) { Contract.Requires(throwStatement != null); if (this.preorderVisitor != null) this.preorderVisitor.Visit(throwStatement); if (this.StopTraversal) return; this.TraverseChildren(throwStatement); if (this.StopTraversal) return; if (this.postorderVisitor != null) this.postorderVisitor.Visit(throwStatement); }
/// <summary> /// Returns a shallow copy of the throw statement. /// </summary> /// <param name="throwStatement"></param> public ThrowStatement Copy(IThrowStatement throwStatement) { return new ThrowStatement(throwStatement); }
public void Visit(IThrowStatement throwStatement) { this.traverser.Traverse(throwStatement); }
public void Visit(IThrowStatement throwStatement) { this.result = this.copier.Copy(throwStatement); }
public void Visit(IThrowStatement throwStatement) { Contract.Requires(throwStatement != null); throw new NotImplementedException(); }
/// <summary> /// Visits the throw statement. /// </summary> /// <param name="throwStatement">The throw statement.</param> /// <param name="consumer">The consumer.</param> /// <returns></returns> public override object VisitThrowStatement(IThrowStatement throwStatement, IHighlightingConsumer consumer) { AddHighlighting(consumer, this.documentThrownExceptionAnalyzer.AnalyzeThrowStatement(throwStatement)); return base.VisitThrowStatement(throwStatement, consumer); }
public override void VisitThrowStatement(IThrowStatement operation) { if (operation.ThrownObject == null && _seenEmptyThrowInCatchClauses.Count > 0 && !_seenEmptyThrowInCatchClauses.Peek()) { _seenEmptyThrowInCatchClauses.Pop(); _seenEmptyThrowInCatchClauses.Push(true); } base.VisitThrowStatement(operation); }
/// <summary> /// Gets the argument null text. /// </summary> /// <param name="throwStatement"> /// The statement. /// </param> /// <returns> /// The argument null text. /// </returns> private static string GetArgumentExceptionText(IThrowStatement throwStatement) { const string result = "Argument is null."; string name = null; var containingStatement = throwStatement.GetContainingStatement(); if (containingStatement is IBlock) { containingStatement = containingStatement.GetContainingStatement(); } var ifStatement = containingStatement as IIfStatement; if (ifStatement == null) { return result; } var condition = ifStatement.Condition as IEqualityExpression; if (condition == null) { return result; } var leftOperand = condition.LeftOperand; var rightOperand = condition.RightOperand; if (rightOperand == null || leftOperand == null) { return result; } var left = leftOperand.GetText(); var right = rightOperand.GetText(); if (left == "null") { name = right; } else if (right == "null") { name = left; } if (name == null) { return result; } return "<c>" + name + "</c> is null."; }
private IIfStatement GetContainingIfOperation( SemanticModel semanticModel, IThrowStatement throwOperation, CancellationToken cancellationToken) { var throwStatement = throwOperation.Syntax; var containingOperation = GetOperation( semanticModel, throwStatement.Parent, cancellationToken); if (containingOperation?.Kind == OperationKind.BlockStatement) { // C# may have an intermediary block between the throw-statement // and the if-statement. Walk up one operation higher in htat case. containingOperation = GetOperation( semanticModel, throwStatement.Parent.Parent, cancellationToken); } return containingOperation as IIfStatement; }
/// <summary> /// Gets the exception text. /// </summary> /// <param name="throwStatement"> /// The throw statement. /// </param> /// <param name="exceptionTypeName"> /// Name of the exception type. /// </param> /// <returns> /// The exception text. /// </returns> private static string GetExceptionText(IThrowStatement throwStatement, string exceptionTypeName) { if (exceptionTypeName == "ArgumentNullException") { return GetArgumentExceptionText(throwStatement); } var exceptionText = "<c>" + exceptionTypeName + "</c>."; var exception = throwStatement.Exception; if (exception == null) { return exceptionText; } var argumentsOwner = exception as IArgumentsOwner; if (argumentsOwner == null) { return exceptionText; } string result = null; foreach (var argument in argumentsOwner.Arguments) { var csharpArgument = argument as ICSharpArgument; if (csharpArgument == null) { continue; } if (csharpArgument.Kind != ParameterKind.VALUE) { continue; } var value = csharpArgument.Value.ConstantValue; if (!value.IsString()) { continue; } var stringValue = value.Value as string; if (string.IsNullOrEmpty(stringValue)) { continue; } result = stringValue; break; } if (exceptionTypeName == "ArgumentOutOfRangeException") { result = String.Format("<c>{0}</c> is out of range.", result); } if (result != null) { return result; } return exceptionText; }
public virtual void onASTElement(IThrowStatement throwStatement) { }