Exemplo n.º 1
0
 public static Task <Document> RefactorAsync(
     Document document,
     ThrowExpressionSyntax throwExpression,
     CancellationToken cancellationToken)
 {
     return(RefactorAsync(document, throwExpression, throwExpression.Expression, cancellationToken));
 }
Exemplo n.º 2
0
 private Doc PrintThrowExpressionSyntax(ThrowExpressionSyntax node)
 {
     return(Concat(
                this.PrintSyntaxToken(node.ThrowKeyword, " "),
                this.Print(node.Expression)
                ));
 }
Exemplo n.º 3
0
 public static Doc Print(ThrowExpressionSyntax node)
 {
     return(Doc.Concat(
                Token.PrintWithSuffix(node.ThrowKeyword, " "),
                Node.Print(node.Expression)
                ));
 }
            public override void VisitThrowExpression(ThrowExpressionSyntax throwExpression)
            {
                bool isReported = CheckThrowExpression(throwExpression.Expression, throwExpression);

                if (!isReported)
                {
                    base.VisitThrowExpression(throwExpression);
                }
            }
        public static async Task ComputeRefactoringAsync(RefactoringContext context, ThrowExpressionSyntax throwExpression)
        {
            ExpressionSyntax expression = throwExpression.Expression;

            if (expression?.IsMissing == false &&
                context.Span.IsContainedInSpanOrBetweenSpans(throwExpression))
            {
                await ComputeRefactoringAsync(context, throwExpression, expression).ConfigureAwait(false);
            }
        }
Exemplo n.º 6
0
        public override void VisitThrowExpression(ThrowExpressionSyntax node)
        {
            if (!PreVisit(node))
            {
                return;
            }

            node.Expression?.Accept(this);

            base.VisitThrowExpression(node);

            PostVisit(node);
        }
        public override void VisitThrowExpression(ThrowExpressionSyntax throwExpression)
        {
            ThrowIfCancellationRequested();

            if (IsPXSetupNotEnteredException(throwExpression.Expression))
            {
                ReportDiagnostic(_context.ReportDiagnostic, _descriptor, throwExpression);
            }
            else
            {
                base.VisitThrowExpression(throwExpression);
            }
        }
        public static AddExceptionToDocumentationCommentAnalysis Analyze(
            ThrowExpressionSyntax throwExpression,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            ExpressionSyntax expression = throwExpression.Expression;

            if (expression?.IsMissing == false)
            {
                return(Analyze(throwExpression, expression, semanticModel, cancellationToken));
            }
            else
            {
                return(AddExceptionToDocumentationCommentAnalysis.NoSuccess);
            }
        }
Exemplo n.º 9
0
        public static AddExceptionToDocumentationCommentAnalysisResult Analyze(
            ThrowExpressionSyntax throwExpression,
            INamedTypeSymbol exceptionSymbol,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            ExpressionSyntax expression = throwExpression.Expression;

            if (expression?.IsMissing == false)
            {
                return(Analyze(throwExpression, expression, exceptionSymbol, semanticModel, cancellationToken));
            }
            else
            {
                return(Fail);
            }
        }
            public bool IsArgumentException(SyntaxNodeAnalysisContext context, SyntaxNode syntaxNode)
            {
                var exceptionExpression = syntaxNode switch
                {
                    ThrowStatementSyntax throwStatement => throwStatement.Expression,
                    ThrowExpressionSyntax throwExpression => throwExpression.Expression,
                    _ => null,
                };

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

                var type = context.SemanticModel.GetTypeInfo(exceptionExpression, context.CancellationToken).Type;

                return(type != null && type.IsOrInheritFrom(_argumentSymbol));
            }
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     base.VisitThrowExpression(node);
     ReportDiagnostic(AddDiagnostic, DiagnosticDescriptor, node);
 }
 internal static void Analyze(SyntaxNodeAnalysisContext context, ThrowExpressionSyntax throwExpression)
 {
     Analyze(context, throwExpression.Expression);
 }
Exemplo n.º 13
0
        public override Evaluation VisitThrowExpression(ThrowExpressionSyntax node)
        {
            node.Expression?.Accept <Evaluation>(this);

            return(base.VisitThrowExpression(node));
        }
Exemplo n.º 14
0
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     throw new NotImplementedException();
 }
    /// <inheritdoc/>
    public override SyntaxNode?VisitThrowExpression(ThrowExpressionSyntax node)
    {
        Diagnostics.Add(ThrowExpressionOrStatement, node);

        return(base.VisitThrowExpression(node));
    }
Exemplo n.º 16
0
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     Log(node, "Unsupported Syntax !");
 }
Exemplo n.º 17
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ThrowExpressionSyntax throwExpression)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.AddExceptionToDocumentationComment) &&
                context.Span.IsContainedInSpanOrBetweenSpans(throwExpression))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                INamedTypeSymbol exceptionSymbol = semanticModel.GetTypeByMetadataName(MetadataNames.System_Exception);

                AddExceptionToDocumentationCommentAnalysisResult analysis = AddExceptionToDocumentationCommentAnalysis.Analyze(throwExpression, exceptionSymbol, semanticModel, context.CancellationToken);

                if (analysis.Success)
                {
                    context.RegisterRefactoring(
                        "Add exception to documentation comment",
                        cancellationToken => AddExceptionToDocumentationCommentRefactoring.RefactorAsync(context.Document, analysis, cancellationToken));
                }
            }
        }
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     this.throws.Add(node.ThrowKeyword);
     base.VisitThrowExpression(node);
 }
Exemplo n.º 19
0
        public override void VisitThrowExpression(ThrowExpressionSyntax node)
        {
            node.Expression?.Accept(this);

            base.VisitThrowExpression(node);
        }
Exemplo n.º 20
0
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     this.VisitExpression(node);
 }
Exemplo n.º 21
0
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
 }
        public override SyntaxNode VisitThrowExpression(ThrowExpressionSyntax node)
        {
            if (node.Parent is ExpressionStatementSyntax es && es.Expression == node || node.Parent is ThrowStatementSyntax)
            {
                return(base.VisitThrowExpression(node));
            }

            var typeInfo = semanticModel.GetTypeInfo(node);

            node = (ThrowExpressionSyntax)base.VisitThrowExpression(node);

            if ((typeInfo.ConvertedType ?? typeInfo.Type) != null)
            {
                var type = typeInfo.ConvertedType ?? typeInfo.Type;

                var invocation = SyntaxFactory.InvocationExpression(
                    SyntaxFactory.ParenthesizedExpression(
                        SyntaxFactory.CastExpression(
                            SyntaxFactory.QualifiedName(
                                SyntaxFactory.IdentifierName(SYSTEM_IDENTIFIER),
                                SyntaxFactory.GenericName(
                                    SyntaxFactory.Identifier(FUNC_IDENTIFIER))
                                .WithTypeArgumentList(
                                    SyntaxFactory.TypeArgumentList(
                                        SyntaxFactory.SingletonSeparatedList <TypeSyntax>(
                                            SyntaxFactory.ParseTypeName(type.ToMinimalDisplayString(semanticModel, node.GetLocation().SourceSpan.Start))
                                            ))
                                    .WithLessThanToken(
                                        SyntaxFactory.Token(SyntaxKind.LessThanToken))
                                    .WithGreaterThanToken(
                                        SyntaxFactory.Token(SyntaxKind.GreaterThanToken))))
                            .WithDotToken(
                                SyntaxFactory.Token(SyntaxKind.DotToken)),
                            SyntaxFactory.ParenthesizedExpression(
                                SyntaxFactory.ParenthesizedLambdaExpression(
                                    SyntaxFactory.Block(
                                        SyntaxFactory.SingletonList <StatementSyntax>(
                                            SyntaxFactory.ThrowStatement(node.Expression)
                                            .WithThrowKeyword(
                                                SyntaxFactory.Token(SyntaxKind.ThrowKeyword))
                                            .WithSemicolonToken(
                                                SyntaxFactory.Token(SyntaxKind.SemicolonToken))
                                            .NormalizeWhitespace()))
                                    .WithOpenBraceToken(
                                        SyntaxFactory.Token(SyntaxKind.OpenBraceToken))
                                    .WithCloseBraceToken(
                                        SyntaxFactory.Token(SyntaxKind.CloseBraceToken)))
                                .WithParameterList(
                                    SyntaxFactory.ParameterList()
                                    .WithOpenParenToken(
                                        SyntaxFactory.Token(SyntaxKind.OpenParenToken))
                                    .WithCloseParenToken(
                                        SyntaxFactory.Token(SyntaxKind.CloseParenToken)))
                                .WithArrowToken(
                                    SyntaxFactory.Token(SyntaxKind.EqualsGreaterThanToken)))
                            .WithOpenParenToken(
                                SyntaxFactory.Token(SyntaxKind.OpenParenToken))
                            .WithCloseParenToken(
                                SyntaxFactory.Token(SyntaxKind.CloseParenToken)))
                        .WithOpenParenToken(
                            SyntaxFactory.Token(SyntaxKind.OpenParenToken))
                        .WithCloseParenToken(
                            SyntaxFactory.Token(SyntaxKind.CloseParenToken)))
                    .WithOpenParenToken(
                        SyntaxFactory.Token(SyntaxKind.OpenParenToken))
                    .WithCloseParenToken(
                        SyntaxFactory.Token(SyntaxKind.CloseParenToken)))
                                 .WithArgumentList(
                    SyntaxFactory.ArgumentList()
                    .WithOpenParenToken(
                        SyntaxFactory.Token(SyntaxKind.OpenParenToken))
                    .WithCloseParenToken(
                        SyntaxFactory.Token(SyntaxKind.CloseParenToken)));

                return(invocation);
            }

            return(node);
        }
Exemplo n.º 23
0
 public override BoundNode VisitThrowExpression(ThrowExpressionSyntax node)
 {
     throw new System.NotSupportedException("UdonSharp does not support throwing exceptions since Udon does not have support for exception throwing at the moment");
 }
Exemplo n.º 24
0
 public static void GoExpression(HaxeWriter writer, ThrowExpressionSyntax expr)
 {
     writer.Write("throw ");
     Core.Write(writer, expr.Expression);
 }
Exemplo n.º 25
0
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     CanUseExceptionFilter = false;
 }
Exemplo n.º 26
0
 /// <inheritdoc/>
 public override void VisitThrowExpression(ThrowExpressionSyntax node)
 {
     this.throwStatementsAndExpressions.Add(node);
     base.VisitThrowExpression(node);
 }
Exemplo n.º 27
0
 /// <inheritdoc />
 public override Expression VisitThrowExpression(ThrowExpressionSyntax node)
 {
     return(Expression.Throw(node.Expression.Accept(this)));
 }
Exemplo n.º 28
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ThrowExpressionSyntax throwExpression)
        {
            if (context.IsRefactoringEnabled(RefactoringDescriptors.AddExceptionElementToDocumentationComment) &&
                context.Span.IsContainedInSpanOrBetweenSpans(throwExpression))
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                AddExceptionToDocumentationCommentAnalysisResult analysis = AddExceptionToDocumentationCommentAnalysis.Analyze(
                    throwExpression,
                    semanticModel.GetTypeByMetadataName("System.Exception"),
                    semanticModel,
                    context.CancellationToken);

                if (analysis.Success)
                {
                    context.RegisterRefactoring(
                        "Add 'exception' element to documentation comment",
                        ct => AddExceptionElementToDocumentationCommentRefactoring.RefactorAsync(context.Document, analysis, ct),
                        RefactoringDescriptors.AddExceptionElementToDocumentationComment);
                }
            }
        }
Exemplo n.º 29
0
 internal ThrowExpressionInfo(ThrowExpressionSyntax node, ExpressionSyntax expression, ITypeSymbol exceptionSymbol)
     : base(node, expression, exceptionSymbol)
 {
 }
Exemplo n.º 30
0
 public static void WriteThrowExpression(ScalaWriter writer, ThrowExpressionSyntax syntax)
 {
     writer.Write("throw ");
     Core.Write(writer, syntax.Expression);
 }