示例#1
0
        /// <summary>Reads the specified reference expression. </summary>
        /// <param name="analyzeUnit">The analyze unit. </param>
        /// <param name="exceptionsOrigin">The exceptions origin. </param>
        /// <param name="referenceExpression">The reference expression.</param>
        /// <returns>The list of thrown exceptions. </returns>
        public static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, IReferenceExpression referenceExpression)
        {
            var result = new List<ThrownExceptionModel>();

            var resolveResult = referenceExpression.Parent is IElementAccessExpression ? 
                ((IElementAccessExpression)referenceExpression.Parent).Reference.Resolve() : 
                referenceExpression.Reference.Resolve();

            var declaredElement = resolveResult.DeclaredElement;
            if (declaredElement == null)
                return result;

            var declarations = declaredElement.GetDeclarations();
            if (declarations.Count == 0)
                return Read(analyzeUnit, exceptionsOrigin, declaredElement);

            foreach (var declaration in declarations)
            {
                var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwner;
                if (docCommentBlockOwnerNode == null)
                    return result;

                var docCommentBlockNode = docCommentBlockOwnerNode.DocCommentBlock;
                if (docCommentBlockNode == null)
                    return result;
                string accessor = null;
                if (exceptionsOrigin is ReferenceExpressionModel &&
                    exceptionsOrigin.ContainingBlock is AccessorDeclarationModel)
                    accessor = ((AccessorDeclarationModel)exceptionsOrigin.ContainingBlock).Node.NameIdentifier.Name;

                var docCommentBlockModel = new DocCommentBlockModel(exceptionsOrigin.ContainingBlock as IAnalyzeUnit, docCommentBlockNode);
                foreach (var comment in docCommentBlockModel.DocumentedExceptions)
                {
                    if (exceptionsOrigin is ReferenceExpressionModel &&
                        exceptionsOrigin.ContainingBlock is AccessorDeclarationModel)
                    {
                        comment.AssociatedExceptionModel = new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, comment.ExceptionType,
                            comment.ExceptionDescription, false, accessor);
                    }
                    else
                    {
                        comment.AssociatedExceptionModel = new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, comment.ExceptionType,
                            comment.ExceptionDescription, false, comment.Accessor);
                    }

                    if (exceptionsOrigin is ReferenceExpressionModel)
                    {
                        if (((ReferenceExpressionModel)exceptionsOrigin).IsExceptionValid(comment) == false)
                        {
                            continue;
                        }
                    }

                    result.Add(comment.AssociatedExceptionModel);
                }
            }
            return result;
        }
示例#2
0
        public ExceptionDocCommentModel(DocCommentBlockModel documentationBlock, string exceptionType, string exceptionDescription, string accessor)
            : base(documentationBlock.AnalyzeUnit)
        {
            DocumentationBlock = documentationBlock;
            Accessor           = accessor;

            ExceptionTypeName    = exceptionType;
            ExceptionType        = GetExceptionType(exceptionType);
            ExceptionDescription = exceptionDescription;
        }
示例#3
0
 protected AnalyzeUnitModelBase(IAnalyzeUnit analyzeUnit, T node)
     : base(analyzeUnit, node)
 {
     DocumentationBlock = new DocCommentBlockModel(this, null);
 }
        /// <summary>Reads the specified reference expression. </summary>
        /// <param name="analyzeUnit">The analyze unit. </param>
        /// <param name="exceptionsOrigin">The exceptions origin. </param>
        /// <param name="referenceExpression">The reference expression.</param>
        /// <returns>The list of thrown exceptions. </returns>
        public static IEnumerable <ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, IReferenceExpression referenceExpression)
        {
            var result = new List <ThrownExceptionModel>();

            var resolveResult = referenceExpression.Parent is IElementAccessExpression ?
                                ((IElementAccessExpression)referenceExpression.Parent).Reference.Resolve() :
                                referenceExpression.Reference.Resolve();

            var declaredElement = resolveResult.DeclaredElement;

            if (declaredElement == null)
            {
                return(result);
            }

            var declarations = declaredElement.GetDeclarations();

            if (declarations.Count == 0)
            {
                return(Read(analyzeUnit, exceptionsOrigin, declaredElement));
            }

            foreach (var declaration in declarations)
            {
#if R8
                var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwnerNode;
                if (docCommentBlockOwnerNode == null)
                {
                    return(result);
                }

                var docCommentBlockNode = docCommentBlockOwnerNode.GetDocCommentBlockNode();
                if (docCommentBlockNode == null)
                {
                    return(result);
                }
#endif
#if R9 || R10
                var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwner;
                if (docCommentBlockOwnerNode == null)
                {
                    return(result);
                }

                var docCommentBlockNode = docCommentBlockOwnerNode.DocCommentBlock;
                if (docCommentBlockNode == null)
                {
                    return(result);
                }
#endif

                var docCommentBlockModel = new DocCommentBlockModel(null, docCommentBlockNode);
                foreach (var comment in docCommentBlockModel.DocumentedExceptions)
                {
                    result.Add(new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, comment.ExceptionType,
                                                        comment.ExceptionDescription, false, comment.Accessor));
                }
            }

            return(result);
        }