public static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, IDeclaredElement declaredElement)
        {
            if (declaredElement == null)
                return new List<ThrownExceptionModel>();

            var xmlDoc = declaredElement.GetXMLDoc(true);
            if (xmlDoc == null)
                return new List<ThrownExceptionModel>();

            return Read(analyzeUnit, exceptionsOrigin, xmlDoc);
        }
        public ThrownExceptionModel(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin,
            IDeclaredType exceptionType, string exceptionDescription, bool isEventInvocationException, string exceptionAccessor)
            : base(analyzeUnit)
        {
            ExceptionType = exceptionType;
            ExceptionDescription = exceptionDescription;
            ExceptionsOrigin = exceptionsOrigin;
            ExceptionAccessor = exceptionAccessor;

            IsEventInvocationException = isEventInvocationException;

            CheckAccessorOverride(exceptionsOrigin, exceptionType);
        }
Пример #3
0
        public ThrownExceptionModel(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin,
                                    IDeclaredType exceptionType, string exceptionDescription, bool isEventInvocationException, string exceptionAccessor)
            : base(analyzeUnit)
        {
            ExceptionType        = exceptionType;
            ExceptionDescription = exceptionDescription;
            ExceptionsOrigin     = exceptionsOrigin;
            ExceptionAccessor    = exceptionAccessor;

            IsEventInvocationException = isEventInvocationException;

            CheckAccessorOverride(exceptionsOrigin, exceptionType);
        }
        /// <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;
        }
Пример #5
0
        private void CheckAccessorOverride(IExceptionsOriginModel exceptionsOrigin, IDeclaredType exceptionType)
        {
            var doc = GetXmlDocId(exceptionsOrigin.Node);

            if (doc != null)
            {
                var fullMethodName = Regex.Replace(doc.Substring(2), "(`[0-9]+)|(\\(.*?\\))", ""); // TODO: merge with other
                var overrides      = ServiceLocator.Settings.GetExceptionAccessorOverrides();
                var ov             =
                    overrides.SingleOrDefault(
                        o => o.FullMethodName == fullMethodName && o.GetExceptionType().Equals(exceptionType));
                if (ov != null)
                {
                    ExceptionAccessor = ov.ExceptionAccessor;
                }
            }
        }
        /// <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
                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);
        }
        private static IEnumerable <ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, XmlNode xmlDoc)
        {
            var result = new List <ThrownExceptionModel>();

            var exceptionNodes = xmlDoc.SelectNodes("exception");

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

            var psiModule = analyzeUnit.GetPsiModule();

            foreach (XmlNode exceptionNode in exceptionNodes)
            {
                if (exceptionNode.Attributes != null)
                {
                    var accessorNode = exceptionNode.Attributes["accessor"];
                    var accessor     = accessorNode != null ? accessorNode.Value : null;

                    var exceptionType = exceptionNode.Attributes["cref"].Value;
                    if (exceptionType.StartsWith("T:"))
                    {
                        exceptionType = exceptionType.Substring(2);
                    }

#if R10
                    var exceptionDeclaredType = TypeFactory.CreateTypeByCLRName(exceptionType, psiModule);
#else
                    var exceptionDeclaredType = TypeFactory.CreateTypeByCLRName(exceptionType, psiModule, psiModule.GetContextFromModule());
#endif

                    result.Add(new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, exceptionDeclaredType,
                                                        exceptionNode.InnerXml, false, accessor));
                }
            }

            return(result);
        }
        public static IEnumerable <ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, IDeclaredElement declaredElement)
        {
            if (declaredElement == null)
            {
                return(new List <ThrownExceptionModel>());
            }

            var xmlDoc = declaredElement.GetXMLDoc(true);

            if (xmlDoc == null)
            {
                return(new List <ThrownExceptionModel>());
            }

            return(Read(analyzeUnit, exceptionsOrigin, xmlDoc));
        }
 private void CheckAccessorOverride(IExceptionsOriginModel exceptionsOrigin, IDeclaredType exceptionType)
 {
     var doc = GetXmlDocId(exceptionsOrigin.Node);
     if (doc != null)
     {
         var fullMethodName = Regex.Replace(doc.Substring(2), "(`[0-9]+)|(\\(.*?\\))", ""); // TODO: merge with other
         var overrides = ServiceLocator.Settings.GetExceptionAccessorOverrides();
         var ov =
             overrides.SingleOrDefault(
                 o => o.FullMethodName == fullMethodName && o.GetExceptionType().Equals(exceptionType));
         if (ov != null)
             ExceptionAccessor = ov.ExceptionAccessor;
     }
 }
        /// <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);
        }
        private static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, XmlNode xmlDoc)
        {
            var result = new List<ThrownExceptionModel>();

            var exceptionNodes = xmlDoc.SelectNodes("exception");
            if (exceptionNodes == null)
                return result;

            var psiModule = analyzeUnit.GetPsiModule();
            foreach (XmlNode exceptionNode in exceptionNodes)
            {
                if (exceptionNode.Attributes != null)
                {
                    var accessorNode = exceptionNode.Attributes["accessor"];
                    var accessor = accessorNode != null ? accessorNode.Value : null;

                    var exceptionType = exceptionNode.Attributes["cref"].Value;
                    if (exceptionType.StartsWith("T:"))
                        exceptionType = exceptionType.Substring(2);

            #if R10
                    var exceptionDeclaredType = TypeFactory.CreateTypeByCLRName(exceptionType, psiModule);
            #else
                    var exceptionDeclaredType = TypeFactory.CreateTypeByCLRName(exceptionType, psiModule, psiModule.GetContextFromModule());
            #endif

                    result.Add(new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, exceptionDeclaredType,
                        exceptionNode.InnerXml, false, accessor));
                }
            }

            return result;
        }