Ejemplo n.º 1
0
 public abstract TDeclaration ReplaceBodyWithExpressionClause(TDeclaration declaration, ArrowExpressionClauseSyntax arrow);
 protected abstract TDeclaration WithExpressionBody(TDeclaration declaration, ArrowExpressionClauseSyntax expressionBody);
Ejemplo n.º 3
0
 protected override ConversionOperatorDeclarationSyntax WithExpressionBody(ConversionOperatorDeclarationSyntax declaration, ArrowExpressionClauseSyntax expressionBody)
 => declaration.WithExpressionBody(expressionBody);
Ejemplo n.º 4
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
 }
Ejemplo n.º 5
0
        private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context, INamedTypeSymbol taskOfTSymbol)
        {
            var methodDeclaration = (MethodDeclarationSyntax)context.Node;

            if (methodDeclaration.Modifiers.Contains(SyntaxKind.AsyncKeyword))
            {
                return;
            }

            if ((methodDeclaration.ReturnType as GenericNameSyntax)?.TypeArgumentList?.Arguments.Count != 1)
            {
                return;
            }

            ArrowExpressionClauseSyntax expressionBody = methodDeclaration.ExpressionBody;

            if (expressionBody != null)
            {
                ExpressionSyntax expression = expressionBody.Expression?.WalkDownParentheses();

                if (expression?.IsKind(
                        SyntaxKind.NullLiteralExpression,
                        SyntaxKind.DefaultExpression,
                        SyntaxKind.DefaultLiteralExpression,
                        SyntaxKind.ConditionalAccessExpression) != true)
                {
                    return;
                }

                if (!IsReturnTypeConstructedFromTaskOfT())
                {
                    return;
                }

                ReportDiagnostic(context, expression);
            }
            else
            {
                BlockSyntax body = methodDeclaration.Body;

                if (body == null)
                {
                    return;
                }

                if (!IsReturnTypeConstructedFromTaskOfT())
                {
                    return;
                }

                AnalyzeBlock(context, body);
            }

            bool IsReturnTypeConstructedFromTaskOfT()
            {
                return(context.SemanticModel
                       .GetDeclaredSymbol(methodDeclaration, context.CancellationToken)?
                       .ReturnType
                       .OriginalDefinition
                       .Equals(taskOfTSymbol) == true);
            }
        }
Ejemplo n.º 6
0
 private static ExpressionSyntax GetExpressionToCheck(BlockSyntax blockSyntax, ArrowExpressionClauseSyntax expressionBodySyntax,
                                                      bool hasReturnValue)
 {
     return(hasReturnValue
         ? GetExpressionFromBodyOptions(blockSyntax, expressionBodySyntax)
         : (GetSingleStatement(blockSyntax) as ExpressionStatementSyntax)?.Expression);
 }
 protected override IndexerDeclarationSyntax WithExpressionBody(IndexerDeclarationSyntax declaration, ArrowExpressionClauseSyntax expressionBody)
 => declaration.WithExpressionBody(expressionBody);
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ArrowExpressionClauseSyntax expressionBody, out SemanticModel speculativeModel)
 {
     speculativeModel = null;
     return(false);
 }
        private static void HandleArrowExpressionClause(SyntaxNodeAnalysisContext context)
        {
            ArrowExpressionClauseSyntax arrowExpressionClause = (ArrowExpressionClauseSyntax)context.Node;

            CheckToken(context, arrowExpressionClause.ArrowToken, true, true, true);
        }
Ejemplo n.º 10
0
 private void VisitAccessorListOrExpressionBody(AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody)
 {
     Visit(accessorList);
     Visit(expressionBody);
 }
Ejemplo n.º 11
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 12
0
 private void VisitBodyOrExpressionBody(BlockSyntax body, ArrowExpressionClauseSyntax expressionBody)
 {
     Visit(body);
     Visit(expressionBody);
 }
Ejemplo n.º 13
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
     this.AddReturnValue(node.Expression);
 }
Ejemplo n.º 14
0
 private static ExpressionSyntax GetExpressionFromBodyOptions(BlockSyntax blockSyntax, ArrowExpressionClauseSyntax expressionBodySyntax)
 {
     return(blockSyntax == null
         ? expressionBodySyntax?.Expression
         : (GetSingleStatement(blockSyntax) as ReturnStatementSyntax)?.Expression);
 }
 protected override PropertyDeclarationSyntax WithExpressionBody(PropertyDeclarationSyntax declaration, ArrowExpressionClauseSyntax expressionBody)
 => declaration.WithExpressionBody(expressionBody);
Ejemplo n.º 16
0
 internal override bool TryGetSpeculativeSemanticModelCore(SyntaxTreeSemanticModel parentModel, int position, ArrowExpressionClauseSyntax expressionBody, out SemanticModel speculativeModel)
 {
     throw ExceptionUtilities.Unreachable;
 }
Ejemplo n.º 17
0
 public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
 {
     VisitNodeToBind(node.Expression);
 }
 private static LiteralExpressionSyntax GetNullLiteralOrDefault(ArrowExpressionClauseSyntax expressionBody)
 {
     return(expressionBody.Expression.IsKind(SyntaxKind.NullLiteralExpression)
         ? (LiteralExpressionSyntax)expressionBody.Expression
         : null);
 }