/// <summary>Performs analyze of <paramref name="thrownException"/>.</summary> /// <param name="thrownException">Thrown exception to analyze.</param> public override void Visit(ThrownExceptionModel thrownException) { if (thrownException == null) { return; } if (!thrownException.AnalyzeUnit.IsInspectionRequired || thrownException.IsCaught || thrownException.IsExceptionDocumented) { return; } var isOptional = IsSubtypeDocumented(thrownException) || IsThrownExceptionSubclassOfOptionalException(thrownException) || IsThrownExceptionThrownFromExcludedMethod(thrownException) || thrownException.IsThrownFromAnonymousMethod; if (thrownException.IsEventInvocationException) { if (ServiceLocator.Settings.DelegateInvocationsMayThrowExceptions) { var highlighting = new EventExceptionNotDocumentedHighlighting(thrownException); ServiceLocator.StageProcess.AddHighlighting(highlighting, thrownException.DocumentRange); } } else { var highlighting = isOptional ? new ExceptionNotDocumentedOptionalHighlighting(thrownException) : new ExceptionNotDocumentedHighlighting(thrownException); ServiceLocator.StageProcess.AddHighlighting(highlighting, thrownException.DocumentRange); } }
internal bool IsSupertypeOf(ThrownExceptionModel thrownException) { var exceptionType = GetExceptionType(); if (exceptionType == null) { return(false); } return(thrownException.ExceptionType.IsSubtypeOf(exceptionType)); }
/// <summary> /// Performs analyze of <paramref name="thrownException"/>. /// </summary> /// <param name="thrownException"> /// Thrown exception to analyze. /// </param> public override void Visit(ThrownExceptionModel thrownException) { // add a squiggle if the throwing a Exception (new Exception()) // throw; statements are ignored if (thrownException.IsThrownFromThrowStatement && thrownException.FullName == "System.Exception" && !thrownException.IsRethrow) { var highlight = new ThrowingSystemExceptionHighlighting(); var range = thrownException.DocumentRange; ServiceLocator.StageProcess.AddHighlighting(highlight, range); } }
private bool IsThrownExceptionSubclassOfOptionalException(ThrownExceptionModel thrownExceptionModel) { var optionalExceptions = ServiceLocator.Settings.GetOptionalExceptions(); if (thrownExceptionModel.IsThrownFromThrowStatement) { return(optionalExceptions.Any(e => e.ReplacementType != OptionalExceptionReplacementType.InvocationOnly && thrownExceptionModel.ExceptionType.IsSubtypeOf(e.ExceptionType))); } else { return(optionalExceptions.Any(e => e.ReplacementType != OptionalExceptionReplacementType.ThrowOnly && thrownExceptionModel.ExceptionType.IsSubtypeOf(e.ExceptionType))); } }
/// <summary>Initializes a new instance of the <see cref="ThrowStatementModel"/> class. </summary> /// <param name="analyzeUnit">The analyze unit.</param> /// <param name="throwStatement">The throw statement.</param> /// <param name="containingBlock">The containing block.</param> public ThrowStatementModel(IAnalyzeUnit analyzeUnit, IThrowStatement throwStatement, IBlockModel containingBlock) : base(analyzeUnit, throwStatement) { ContainingBlock = containingBlock; var exceptionType = GetExceptionType(); var exceptionDescription = GetThrownExceptionMessage(throwStatement); string accessor = null; if (containingBlock is AccessorDeclarationModel) { accessor = ((AccessorDeclarationModel)containingBlock).Node.NameIdentifier.Name; } _thrownException = new ThrownExceptionModel(analyzeUnit, this, exceptionType, exceptionDescription, false, accessor); }
private ThrownExceptionModel CreateThrownSystemException() { var psiModule = Node.GetPsiModule(); var systemExceptionType = TypeFactory.CreateTypeByCLRName("System.Exception", psiModule); string accessor = null; if (ContainingBlock is AccessorDeclarationModel) { accessor = ((AccessorDeclarationModel)ContainingBlock).Node.NameIdentifier.Name; } var thrownException = new ThrownExceptionModel(AnalyzeUnit, this, systemExceptionType, "A delegate callback throws an exception.", true, accessor); return(thrownException); }
private bool IsSubtypeDocumented(ThrownExceptionModel thrownException) { if (thrownException.IsThrownFromThrowStatement) { if (ServiceLocator.Settings.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements && thrownException.IsExceptionOrSubtypeDocumented) { return(true); } } else { if (ServiceLocator.Settings.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions && thrownException.IsExceptionOrSubtypeDocumented) { return(true); } } return(false); }
private bool IsThrownExceptionThrownFromExcludedMethod(ThrownExceptionModel thrownException) { var parent = thrownException.ExceptionsOrigin as ReferenceExpressionModel; if (parent != null) { var node = parent.Node; var resolveResult = node.Reference.Resolve(); if (resolveResult != null) { var element = resolveResult.DeclaredElement as IXmlDocIdOwner; if (element != null && (resolveResult.DeclaredElement is IMethod || resolveResult.DeclaredElement is IProperty)) { // remove generic placeholders ("`1") and method signature ("(...)") var fullMethodName = Regex.Replace(element.XMLDocId.Substring(2), "(`+[0-9]+)|(\\(.*?\\))", ""); // TODO: merge with other var excludedMethods = ServiceLocator.Settings.GetOptionalMethodExceptions(); return(excludedMethods.Any(t => t.FullMethodName == fullMethodName && t.IsSupertypeOf(thrownException))); } } } return(false); }
/// <summary>Initializes a new instance of the <see cref="ExceptionNotDocumentedOptionalHighlighting"/> class. </summary> /// <param name="thrownException">The thrown exception. </param> internal ExceptionNotDocumentedOptionalHighlighting(ThrownExceptionModel thrownException) { ThrownException = thrownException; }
private bool ThrowsExceptionOrSubtype(ExceptionDocCommentModel exceptionDocumentation, ThrownExceptionModel thrownException) { if (thrownException.IsThrownFromThrowStatement) { if (ServiceLocator.Settings.IsDocumentationOfExceptionSubtypeSufficientForThrowStatements) { return(thrownException.IsExceptionOrSubtype(exceptionDocumentation)); } } else { if (ServiceLocator.Settings.IsDocumentationOfExceptionSubtypeSufficientForReferenceExpressions) { return(thrownException.IsExceptionOrSubtype(exceptionDocumentation)); } } return(false); }
/// <summary>Initializes a new instance of the <see cref="ExceptionNotDocumentedHighlighting"/> class. </summary> /// <param name="thrownException">The thrown exception. </param> internal ExceptionNotDocumentedHighlighting(ThrownExceptionModel thrownException) : base(thrownException) { }
/// <summary>Performs analyze of <paramref name="thrownException"/>.</summary> /// <param name="thrownException">Thrown exception to analyze.</param> public virtual void Visit(ThrownExceptionModel thrownException) { }