示例#1
0
        public static HashSet <Assertion> CollectAssertions(
            [NotNull] AssertionMethodAnnotationProvider assertionMethodAnnotationProvider,
            [NotNull] AssertionConditionAnnotationProvider assertionConditionAnnotationProvider,
            [NotNull] ICSharpTreeNode rootNode)
        {
            var forTypeLevelInitializersOnly = rootNode is IClassLikeDeclaration;

            var assertions = new HashSet <Assertion>();

            foreach (var expression in rootNode.Descendants <ICSharpExpression>())
            {
                Debug.Assert(expression != null);

                var isInTypeLevelInitializer = expression.PathToRoot()
                                               .Any(node => node is IExpressionInitializer && (node.Parent is IFieldDeclaration || node.Parent is IPropertyDeclaration));

                if (forTypeLevelInitializersOnly != isInTypeLevelInitializer)
                {
                    continue;
                }

                switch (expression)
                {
                case IInvocationExpression invocationExpression:
                    var assertionStatement = AssertionStatement.TryFromInvocationExpression(
                        invocationExpression,
                        assertionMethodAnnotationProvider,
                        assertionConditionAnnotationProvider);
                    if (assertionStatement != null)
                    {
                        assertions.Add(assertionStatement);
                    }

                    var inlineAssertion = InlineAssertion.TryFromInvocationExpression(invocationExpression);
                    if (inlineAssertion != null)
                    {
                        assertions.Add(inlineAssertion);
                    }
                    break;

                case ISuppressNullableWarningExpression suppressNullableWarningExpression:
                    assertions.Add(new NullForgivingOperation(suppressNullableWarningExpression));
                    break;
                }
            }

            return(assertions);
        }
示例#2
0
 internal RedundantInlineAssertionHighlighting([NotNull] string message, [NotNull] InlineAssertion assertion) : base(message)
     => this.assertion = assertion;
 internal RedundantInlineAssertionSuggestion([NotNull] string message, [NotNull] InlineAssertion assertion) : base(message)
     => this.assertion = assertion;