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();
            });
        }
 private bool IsDocumentedExceptionOrSubtypeThrown(ExceptionDocCommentModel exceptionDocumentation)
 {
     return(exceptionDocumentation
            .AnalyzeUnit
            .UncaughtThrownExceptions
            .Any(m => ThrowsExceptionOrSubtype(exceptionDocumentation, m)));
 }
        /// <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);
        }
 private bool IsDocumentedExceptionThrown(ExceptionDocCommentModel exceptionDocumentation)
 {
     return(exceptionDocumentation
            .AnalyzeUnit
            .UncaughtThrownExceptions
            .Any(m => m.IsException(exceptionDocumentation)));
 }
Example #5
0
        public bool IsExceptionValid(ExceptionDocCommentModel comment)
        {
            if (comment.Accessor.IsNullOrWhitespace())
            {
                return(true);
            }

            if (this.IsInvocation == false)
            {
                return(false);
            }

            if (_assignment != null)
            {
                var exceptionOrigin       = comment.AssociatedExceptionModel.ExceptionsOrigin.Node.GetText().TrimFromStart("this.");
                var assignmentDestination = _assignment.Dest.LastChild.GetText();
                if (assignmentDestination.Contains(exceptionOrigin) && comment.Accessor == "get")
                {
                    return(false);
                }

                if (assignmentDestination.Contains(exceptionOrigin) == false && comment.Accessor == "set")
                {
                    return(false);
                }
            }

            return(true);
        }
 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);
 }
 /// <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)
 {
 }
Example #10
0
 /// <summary>Performs analyze of <paramref name="exceptionDocumentation"/>.</summary>
 /// <param name="exceptionDocumentation">Exception documentation to analyze.</param>
 public virtual void Visit(ExceptionDocCommentModel exceptionDocumentation)
 {
 }