Пример #1
0
        public static ExpressionSyntax ConvertToExpression(IThrowOperation throwOperation)
        {
            var throwStatement = (ThrowStatementSyntax)throwOperation.Syntax;

            RoslynDebug.Assert(throwStatement.Expression != null);
            return(SyntaxFactory.ThrowExpression(throwStatement.ThrowKeyword, throwStatement.Expression));
        }
            public override void VisitThrow(IThrowOperation operation)
            {
                if (_finallyBlockNestingDepth > 0)
                {
                    ThrowExpressions.Add(operation);
                }

                base.VisitThrow(operation);
            }
            public override void VisitThrow(IThrowOperation operation)
            {
                if (operation.Exception == null && _seenEmptyThrowInCatchClauses.Count > 0 && !_seenEmptyThrowInCatchClauses.Peek())
                {
                    _seenEmptyThrowInCatchClauses.Pop();
                    _seenEmptyThrowInCatchClauses.Push(true);
                }

                base.VisitThrow(operation);
            }
            public override Location VisitThrow([NotNull] IThrowOperation operation, [CanBeNull] object argument)
            {
                if (operation.IsStatement())
                {
                    var syntax = (ThrowStatementSyntax)operation.Syntax;
                    return(syntax.ThrowKeyword.GetLocation());
                }

                return(base.VisitThrow(operation, argument));
            }
            public override void VisitThrow(IThrowOperation operation)
            {
                if (_seenRethrowInCatchClauses.Count > 0 && !_seenRethrowInCatchClauses.Peek())
                {
                    _seenRethrowInCatchClauses.Pop();
                    _seenRethrowInCatchClauses.Push(true);
                }

                base.VisitThrow(operation);
            }
Пример #6
0
        public static ITypeSymbol GetExceptionType(this IThrowOperation throwOperation)
        {
            if (throwOperation.Exception != null)
            {
                return(throwOperation.Exception.Type);
            }

            var catchOperation = throwOperation.GetAncestor <ICatchClauseOperation>(OperationKind.CatchClause);

            return(catchOperation?.ExceptionType);
        }
Пример #7
0
 public override void VisitThrow(IThrowOperation operation)
 {
     Assert.Equal(OperationKind.Throw, operation.Kind);
     if (operation.Exception == null)
     {
         Assert.Empty(operation.Children);
     }
     else
     {
         Assert.Same(operation.Exception, operation.Children.Single());
     }
 }
Пример #8
0
 internal static Location GetExceptionalLocation(this IThrowOperation @this)
 {
     if (@this.Syntax is ThrowExpressionSyntax expressionSyntax)
     {
         return(expressionSyntax.ThrowKeyword.GetLocation());
     }
     else if (@this.Syntax is ThrowStatementSyntax statementSyntax)
     {
         return(statementSyntax.ThrowKeyword.GetLocation());
     }
     else
     {
         return(@this.Syntax.GetLocation());
     }
 }
Пример #9
0
            private void AnalyzeThrowOperation(OperationAnalysisContext context, IThrowOperation operation)
            {
                if (operation.Exception.Type != _platformNotSupportedException)
                {
                    return;
                }

                var rejectedPlatforms = GetRejectedPlatforms(operation);

                // If we couldn't find any rejected platforms then the throw operation wasn't
                // inside an if that checked for the absence of specific platforms.

                if (!rejectedPlatforms.Any)
                {
                    return;
                }

                // To check wether we didn't annoate them, we'll subtract the declared platforms
                // from the rejected ones.

                var declaredPlatforms = GetDeclaredPlatforms(context.ContainingSymbol);

                rejectedPlatforms.RemoveAll(declaredPlatforms);

                // If there aren't any left, that means we annoated them all.

                if (!rejectedPlatforms.Any)
                {
                    return;
                }

                // Alright, we missed some. Report them.

                var symbol             = context.ContainingSymbol;
                var formattedSymbol    = symbol.ToDisplayString(_symbolDisplayFormat);
                var formattedPlatforms = rejectedPlatforms.ToString();
                var location           = operation.Syntax.GetLocation();
                var diagnostic         = Diagnostic.Create(_pc0003, location, formattedSymbol, formattedPlatforms);

                context.ReportDiagnostic(diagnostic);
            }
 protected override ExpressionSyntax ConvertToExpression(IThrowOperation throwOperation)
 => CSharpUseConditionalExpressionHelpers.ConvertToExpression(throwOperation);
Пример #11
0
            public override PointsToAbstractValue VisitThrow(IThrowOperation operation, object argument)
            {
                var _ = base.VisitThrow(operation, argument);

                return(PointsToAbstractValue.NoLocation);
            }
Пример #12
0
 public ExceptionalOperation(IThrowOperation operation)
 {
     Location = operation.GetExceptionalLocation();
     Method   = null;
     Type     = operation.Exception.GetUnconvertedType();
 }
Пример #13
0
 public bool IsArgumentException(IThrowOperation operation)
 {
     return(operation.Exception != null && operation.Exception.Type.IsOrInheritFrom(_argumentSymbol));
 }
Пример #14
0
 protected abstract TExpressionSyntax ConvertToExpression(IThrowOperation throwOperation);
Пример #15
0
 public override IOperation VisitThrow(IThrowOperation operation, object argument)
 {
     return(new ThrowExpression(Visit(operation.Exception), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit));
 }
            public override NullAbstractValue VisitThrow(IThrowOperation operation, object argument)
            {
                var _ = base.VisitThrow(operation, argument);

                return(NullAbstractValue.NotNull);
            }
 public override void VisitThrow([NotNull] IThrowOperation operation)
 {
     Result.SetImmediate();
 }
 public override void VisitThrow([NotNull] IThrowOperation operation)
 {
     IncrementStatementCount(operation);
     base.VisitThrow(operation);
 }
Пример #19
0
 public override bool VisitThrow([NotNull] IThrowOperation operation1, [CanBeNull] IOperation argument)
 {
     return(argument is IThrowOperation operation2 && AreBaseOperationsEqual(operation1, operation2));
 }
Пример #20
0
 public virtual void VisitThrow(IThrowOperation operation)
 {
     DefaultVisit(operation);
 }
Пример #21
0
 public override void VisitThrow([NotNull] IThrowOperation operation)
 {
     base.VisitThrow(operation);
 }