private bool IsDocumentedExceptionOrSubtypeThrown(ExceptionDocCommentModel exceptionDocumentation)
 {
     return exceptionDocumentation
         .AnalyzeUnit
         .UncaughtThrownExceptions
         .Any(m => ThrowsExceptionOrSubtype(exceptionDocumentation, m));
 }
 private bool IsDocumentedExceptionThrown(ExceptionDocCommentModel exceptionDocumentation)
 {
     return exceptionDocumentation
         .AnalyzeUnit
         .UncaughtThrownExceptions
         .Any(m => m.IsException(exceptionDocumentation));
 }
        private Action<ITextControl> MarkInsertedDescription(ISolution solution, ExceptionDocCommentModel insertedExceptionModel)
        {
            var exceptionCommentRange = insertedExceptionModel.GetMarkerRange();
            if (exceptionCommentRange == DocumentRange.InvalidRange)
                return null;

            var copyExceptionDescription =
                string.IsNullOrEmpty(insertedExceptionModel.ExceptionDescription) ||
                insertedExceptionModel.ExceptionDescription.Contains("[MARKER]");

            var exceptionDescription = copyExceptionDescription ? "Condition" : insertedExceptionModel.ExceptionDescription;

            var nameSuggestionsExpression = new NameSuggestionsExpression(new[] {exceptionDescription});
            var field = new TemplateField("name", nameSuggestionsExpression, 0);
            var fieldInfo = new HotspotInfo(field, exceptionCommentRange);

            return textControl =>
            {
                var hotspotSession = Shell.Instance.GetComponent<LiveTemplatesManager>()
                    .CreateHotspotSessionAtopExistingText(
                        solution, TextRange.InvalidRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret,
                        new[] {fieldInfo});

                hotspotSession.Execute();
            };
        }
示例#4
0
        /// <summary>Checks whether the thrown exception is the same as <paramref name="exceptionDocumentation"/>.</summary>
        public bool IsException(ExceptionDocCommentModel exceptionDocumentation)
        {
            if (exceptionDocumentation.Accessor != null && exceptionDocumentation.Accessor != ExceptionAccessor)
            {
                return(false);
            }

            return(IsException(exceptionDocumentation.ExceptionType));
        }
 private bool IsAbstractOrInterfaceMethod(ExceptionDocCommentModel exceptionDocumentation)
 {
     if (exceptionDocumentation.AnalyzeUnit is MethodDeclarationModel)
     {
         var declaredElement = ((MethodDeclarationModel)exceptionDocumentation.AnalyzeUnit).Node.DeclaredElement;
         if (declaredElement != null && declaredElement.IsAbstract)
             return true;
     }
     return false;
 }
 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;
 }
示例#7
0
        public void RemoveExceptionDocumentation(ExceptionDocCommentModel exceptionDocumentation, IProgressIndicator progress)
        {
            if (exceptionDocumentation == null)
            {
                return;
            }

            var attributes = "cref=\"" + Regex.Escape(exceptionDocumentation.ExceptionTypeName) + "\"";

            if (exceptionDocumentation.Accessor != null)
            {
                attributes += " accessor=\"" + Regex.Escape(exceptionDocumentation.Accessor) + "\"";
            }

            var regex            = "<exception " + attributes + "((>((\r|\n|.)*?)</exception>)|((\r|\n|.)*?/>))";
            var newDocumentation = Regex.Replace(_documentationText, regex, string.Empty);

            ChangeDocumentation(newDocumentation);
        }
示例#8
0
        public bool IsExceptionOrSubtype(ExceptionDocCommentModel exceptionDocumentation)
        {
            if (exceptionDocumentation.Accessor != null && exceptionDocumentation.Accessor != ExceptionAccessor)
            {
                return(false);
            }

            if (ExceptionType == null)
            {
                return(false);
            }

            if (exceptionDocumentation.ExceptionType == null)
            {
                return(false);
            }

            return(ExceptionType.IsSubtypeOf(exceptionDocumentation.ExceptionType));
        }
        /// <summary>Performs analyze of <paramref name="exceptionDocumentation"/>.</summary>
        /// <param name="exceptionDocumentation">Exception documentation to analyze.</param>
        public override void Visit(ExceptionDocCommentModel exceptionDocumentation)
        {
            if (exceptionDocumentation == null)
                return;

            if (IsAbstractOrInterfaceMethod(exceptionDocumentation))
                return;

            if (!exceptionDocumentation.AnalyzeUnit.IsInspectionRequired)
                return;

            if (IsDocumentedExceptionThrown(exceptionDocumentation))
                return;

            var isOptional = IsDocumentedExceptionOrSubtypeThrown(exceptionDocumentation);

            var highlighting = isOptional
                ? new ExceptionNotThrownOptionalHighlighting(exceptionDocumentation)
                : new ExceptionNotThrownHighlighting(exceptionDocumentation);

            ServiceLocator.StageProcess.AddHighlighting(highlighting, exceptionDocumentation.DocumentRange);
        }
 /// <summary>Initializes a new instance of the <see cref="ExceptionNotThrownOptionalHighlighting"/> class. </summary>
 /// <param name="exceptionDocumentation">The exception documentation. </param>
 internal ExceptionNotThrownOptionalHighlighting(ExceptionDocCommentModel exceptionDocumentation)
 {
     ExceptionDocumentation = exceptionDocumentation;
 }
 /// <summary>Initializes a new instance of the <see cref="ExceptionNotThrownHighlighting"/> class. </summary>
 /// <param name="exceptionDocumentation">The exception documentation. </param>
 internal ExceptionNotThrownHighlighting(ExceptionDocCommentModel exceptionDocumentation)
     : base(exceptionDocumentation)
 {
 }
        public bool IsExceptionOrSubtype(ExceptionDocCommentModel exceptionDocumentation)
        {
            if (exceptionDocumentation.Accessor != null && exceptionDocumentation.Accessor != ExceptionAccessor)
                return false;

            if (ExceptionType == null)
                return false;

            if (exceptionDocumentation.ExceptionType == null)
                return false;

            return ExceptionType.IsSubtypeOf(exceptionDocumentation.ExceptionType);
        }
        /// <summary>Checks whether the thrown exception is the same as <paramref name="exceptionDocumentation"/>.</summary>
        public bool IsException(ExceptionDocCommentModel exceptionDocumentation)
        {
            if (exceptionDocumentation.Accessor != null && exceptionDocumentation.Accessor != ExceptionAccessor)
                return false;

            return IsException(exceptionDocumentation.ExceptionType);
        }
 /// <summary>Performs analyze of <paramref name="exceptionDocumentation"/>.</summary>
 /// <param name="exceptionDocumentation">Exception documentation to analyze.</param>
 public virtual void Visit(ExceptionDocCommentModel exceptionDocumentation)
 {
 }