Example #1
0
 public DocCommentBlockModel(IAnalyzeUnit analyzeUnit, IDocCommentBlock docCommentNode)
     : base(analyzeUnit, docCommentNode)
 {
     References           = new List <IReference>();
     DocumentedExceptions = new List <ExceptionDocCommentModel>();
     Update();
 }
Example #2
0
        public void StartProcess(IAnalyzeUnit analyzeUnit)
        {
            AnalyzeUnit = analyzeUnit;
            Model       = (T)analyzeUnit;

            BlockModelsStack.Push(AnalyzeUnit);
        }
Example #3
0
        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);

                    var exceptionDeclaredType = TypeFactory.CreateTypeByCLRName(exceptionType, psiModule);

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

            return result;
        }
Example #4
0
 public ConstructorInitializerModel(IAnalyzeUnit analyzeUnit, IConstructorInitializer node, IBlockModel containingBlock)
     : base(analyzeUnit, node)
 {
     ContainingBlock  = containingBlock;
     ThrownExceptions = node.Reference != null?
                        ThrownExceptionsReader.Read(analyzeUnit, this, node.Reference.Resolve().DeclaredElement) :
                            new List <ThrownExceptionModel>();
 }
Example #5
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;
        }
        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);
        }
Example #7
0
        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 static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, ObjectCreationExpressionModel objectCreationExpression)
        {
            var declaredElement = objectCreationExpression.Node.ConstructorReference.Resolve().DeclaredElement;
            if (declaredElement == null)
                return Enumerable.Empty<ThrownExceptionModel>();

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

            return Read(analyzeUnit, objectCreationExpression, xmlDoc);
        }
Example #9
0
        public static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, ObjectCreationExpressionModel objectCreationExpression)
        {
            var declaredElement = objectCreationExpression.Node.ConstructorReference.Resolve().DeclaredElement;
            if (declaredElement == null)
                return Enumerable.Empty<ThrownExceptionModel>();

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

            return Read(analyzeUnit, objectCreationExpression, 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);
        }
Example #11
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;
        }
        /// <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);
        }
 public CatchClauseModel(ICatchClause catchClauseNode, TryStatementModel tryStatementModel, IAnalyzeUnit analyzeUnit)
     : base(analyzeUnit, catchClauseNode)
 {
     ParentBlock = tryStatementModel;
     IsCatchAll  = GetIsCatchAll();
 }
Example #15
0
 public ObjectCreationExpressionModel(IAnalyzeUnit analyzeUnit, IObjectCreationExpression objectCreationExpression, IBlockModel containingBlock)
     : base(analyzeUnit, objectCreationExpression, containingBlock)
 {
 }
 protected ModelBase(IAnalyzeUnit analyzeUnit)
 {
     AnalyzeUnit = analyzeUnit;
 }
 public DocCommentBlockModel(IAnalyzeUnit analyzeUnit, IDocCommentBlockNode docCommentNode)
 protected BlockModelBase(IAnalyzeUnit analyzeUnit, T node)
     : base(analyzeUnit, node)
 {
     TryStatements    = new List <TryStatementModel>();
     ThrownExceptions = new List <IExceptionsOriginModel>();
 }
Example #19
0
 public CatchVariableModel(IAnalyzeUnit analyzeUnit, ICatchVariableDeclaration catchVariableDeclaration)
     : base(analyzeUnit, catchVariableDeclaration)
 {
 }
Example #20
0
 protected TreeElementModelBase(IAnalyzeUnit analyzeUnit, T node)
     : base(analyzeUnit)
 {
     Node = node;
 }
        /// <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);
        }
Example #22
0
 public ReferenceExpressionModel(IAnalyzeUnit analyzeUnit, IReferenceExpression invocationExpression, IBlockModel containingBlock)
     : base(analyzeUnit, invocationExpression, containingBlock)
 {
 }
        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;
        }
Example #24
0
 protected ModelBase(IAnalyzeUnit analyzeUnit)
 {
     AnalyzeUnit = analyzeUnit;
 }
Example #25
0
 public void StartProcess(IAnalyzeUnit analyzeUnit)
 {
 }
Example #26
0
 protected ExpressionExceptionsOriginModelBase(IAnalyzeUnit analyzeUnit, T node, IBlockModel containingBlock)
     : base(analyzeUnit, node)
 {
     ContainingBlock = containingBlock;
 }
Example #27
0
 protected AnalyzeUnitModelBase(IAnalyzeUnit analyzeUnit, T node)
     : base(analyzeUnit, node)
 {
     DocumentationBlock = new DocCommentBlockModel(this, null);
 }
 public AccessorDeclarationModel(IAnalyzeUnit analyzeUnit, IAccessorDeclaration node, IBlockModel parentBlock)
     : base(analyzeUnit, node)
 {
     ParentBlock = parentBlock;
 }
 public TryStatementModel(IAnalyzeUnit analyzeUnit, ITryStatement tryStatement)
     : base(analyzeUnit, tryStatement)
 {
     CatchClauses = GetCatchClauses();
 }