Exemple #1
0
        public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
        {
            node.Pattern?.Accept(this);
            node.WhenClause?.Accept(this);

            base.VisitCasePatternSwitchLabel(node);
        }
Exemple #2
0
        public override Evaluation VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
        {
            node.Pattern?.Accept <Evaluation>(this);
            node.WhenClause?.Accept <Evaluation>(this);

            return(base.VisitCasePatternSwitchLabel(node));
        }
Exemple #3
0
 public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     if (currentMethod != null)
     {
         currentMethod.cyclomaticComplexity++;
     }
     base.VisitCasePatternSwitchLabel(node);
 }
Exemple #4
0
 internal override void BindPatternSwitchLabelForInference(
     CasePatternSwitchLabelSyntax node,
     BindingDiagnosticBag diagnostics
     )
 {
     // There's supposed to be a SwitchBinder (or other overrider of this method) in the chain.
     throw ExceptionUtilities.Unreachable;
 }
        public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
        {
            if (node.Parent is SwitchSectionSyntax switchSection &&
                switchSection.Parent is SwitchStatementSyntax switchStatement)
            {
                this.HandleAssignedValue(node.Pattern, switchStatement.Expression);
            }

            base.VisitCasePatternSwitchLabel(node);
        }
Exemple #6
0
        public static Doc Print(CasePatternSwitchLabelSyntax node)
        {
            var docs = new List <Doc>();

            docs.Add(Token.Print(node.Keyword, " "), Node.Print(node.Pattern));
            if (node.WhenClause != null)
            {
                docs.Add(" ", Node.Print(node.WhenClause));
            }
            docs.Add(Token.Print(node.ColonToken));
            return(Doc.Concat(docs));
        }
Exemple #7
0
        public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
        {
            if (!PreVisit(node))
            {
                return;
            }

            node.Pattern?.Accept(this);
            node.WhenClause?.Accept(this);

            base.VisitCasePatternSwitchLabel(node);

            PostVisit(node);
        }
Exemple #8
0
        private Doc PrintCasePatternSwitchLabelSyntax(
            CasePatternSwitchLabelSyntax node)
        {
            var parts = new Parts();

            parts.Push(
                this.PrintSyntaxToken(node.Keyword, " "),
                this.Print(node.Pattern)
                );
            if (node.WhenClause != null)
            {
                parts.Push(" ", this.Print(node.WhenClause));
            }
            parts.Push(this.PrintSyntaxToken(node.ColonToken));
            return(Concat(parts));
        }
        public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
        {
            var lastWhen    = new ApexWhenTypeClauseSyntax();
            var pattern     = node.Pattern as DeclarationPatternSyntax;
            var type        = pattern?.Type;
            var designation = pattern?.Designation as SingleVariableDesignationSyntax;

            if (pattern == null || type == null || designation == null)
            {
                throw new InvalidOperationException("Unsupported switch pattern format. " +
                                                    "Case type variable is expected.");
            }

            lastWhen.Type       = ConvertType(type);
            lastWhen.Identifier = designation.Identifier.ValueText;
            LastWhen            = lastWhen;
        }
        /// <summary>
        /// Bind a pattern switch label in order to force inference of the type of pattern variables.
        /// </summary>
        internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabelSyntax node, DiagnosticBag diagnostics)
        {
            // node should be a label of this switch statement.
            Debug.Assert(this.SwitchSyntax == node.Parent.Parent);

            // This simulates enough of the normal binding path of a switch statement to cause
            // the label's pattern variables to have their types inferred, if necessary.
            // It also binds the when clause, and therefore any pattern and out variables there.
            BoundPatternSwitchLabel defaultLabel = null;

            BindPatternSwitchSectionLabel(
                sectionBinder: GetBinder(node.Parent),
                node: node,
                label: LabelsByNode[node],
                defaultLabel: ref defaultLabel,
                diagnostics: diagnostics);
        }
        /// <summary>
        /// Bind a pattern switch label in order to force inference of the type of pattern variables.
        /// </summary>
        internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabelSyntax node, DiagnosticBag diagnostics)
        {
            // node should be a label of this switch statement.
            Debug.Assert(this.SwitchSyntax == node.Parent.Parent);

            // This simulates enough of the normal binding path of a switch statement to cause
            // the label's pattern variables to have their types inferred, if necessary.
            // It also binds the when clause, and therefore any pattern and out variables there.
            BoundPatternSwitchLabel defaultLabel = null;
            BindPatternSwitchSectionLabel(
                sectionBinder: GetBinder(node.Parent),
                boundSwitchExpression: SwitchGoverningExpression,
                node: node,
                label: LabelsByNode[node],
                defaultLabel: ref defaultLabel,
                diagnostics: diagnostics);
        }
Exemple #12
0
            public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
            {
                base.VisitCasePatternSwitchLabel(node);

                var declaration = node.Pattern as DeclarationPatternSyntax;

                if (declaration == null)
                {
                    return;
                }

                if (declaration.Designation is SingleVariableDesignationSyntax variableDesignation)
                {
                    var symbol = model.GetDeclaredSymbol(variableDesignation);
                    if (symbol != null)
                    {
                        // variables declared in patterns are never null
                        var item = new Assignment(symbol, node, ValueType.NotNull);
                        Assignments.Add(item);
                    }
                }
            }
 BinaryExpressionSyntax(LogicalAndExpression) logicalAnd => CombineLogicalAndOperands(logicalAnd, model),
 CasePatternSwitchLabelSyntax {
     WhenClause : { } whenClause
 internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabelSyntax node, DiagnosticBag diagnostics)
 {
     // There's supposed to be a SwitchBinder (or other overrider of this method) in the chain.
     throw ExceptionUtilities.Unreachable;
 }
 override public void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     Complexity++;
     base.VisitCasePatternSwitchLabel(node);
 }
 public TameCasePatternSwitchLabelSyntax(CasePatternSwitchLabelSyntax node)
 {
     Node = node;
     AddChildren();
 }
Exemple #17
0
 internal virtual void BindPatternSwitchLabelForInference(CasePatternSwitchLabelSyntax node, DiagnosticBag diagnostics)
 {
     this.Next.BindPatternSwitchLabelForInference(node, diagnostics);
 }
Exemple #18
0
 public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     throw new NotImplementedException();
 }
 public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     this.caseLabels.Add(node);
     base.VisitCasePatternSwitchLabel(node);
 }
 public override SyntaxNode VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     //不支持的语法
     return(ReportAndAttachError(base.VisitCasePatternSwitchLabel(node), "[Cs2LuaRewriter] Unsupported 'case pattern' Syntax !"));
 }
Exemple #21
0
 public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node) => base.VisitCasePatternSwitchLabel(node);
Exemple #22
0
 internal override void BindPatternSwitchLabelForInference(CasePatternSwitchLabelSyntax node, DiagnosticBag diagnostics)
 {
     // A pattern should be handled by a pattern switch binder.
     throw ExceptionUtilities.Unreachable;
 }
 public override void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node)
 {
     Log(node, "Unsupported Syntax !");
 }
        private static Task <Document> UsePatternMatchingAsync(
            Document document,
            SwitchStatementSyntax switchStatement,
            CancellationToken cancellationToken)
        {
            SyntaxList <SwitchSectionSyntax> newSections = switchStatement.Sections.Select(section =>
            {
                if (!(section.Labels.Single() is CaseSwitchLabelSyntax label))
                {
                    return(section);
                }

                SyntaxList <StatementSyntax> statements = section.Statements;

                StatementSyntax statement = statements[0];

                if (statement is BlockSyntax block)
                {
                    statement = block.Statements.FirstOrDefault();
                }

                SingleLocalDeclarationStatementInfo localInfo = SyntaxInfo.SingleLocalDeclarationStatementInfo((LocalDeclarationStatementSyntax)statement);

                var castExpression = (CastExpressionSyntax)localInfo.Value;

                CasePatternSwitchLabelSyntax newLabel = CasePatternSwitchLabel(
                    DeclarationPattern(
                        castExpression.Type,
                        SingleVariableDesignation(localInfo.Identifier)),
                    label.ColonToken);

                SwitchSectionSyntax newSection = section.RemoveStatement(localInfo.Statement);

                newSection = newSection.WithLabels(newSection.Labels.ReplaceAt(0, newLabel));

                return(newSection.WithFormatterAnnotation());
            })
                                                           .ToSyntaxList();

            ExpressionSyntax expression = switchStatement.Expression;

            ExpressionSyntax newExpression = expression;

            LocalDeclarationStatementSyntax localDeclaration = null;

            if (expression.IsKind(SyntaxKind.InvocationExpression))
            {
                SimpleMemberInvocationExpressionInfo invocationInfo = SyntaxInfo.SimpleMemberInvocationExpressionInfo(expression);

                newExpression = invocationInfo.Expression;
            }
            else
            {
                localDeclaration = (LocalDeclarationStatementSyntax)switchStatement.PreviousStatement();

                SingleLocalDeclarationStatementInfo localInfo = SyntaxInfo.SingleLocalDeclarationStatementInfo(localDeclaration);

                SimpleMemberInvocationExpressionInfo invocationInfo = SyntaxInfo.SimpleMemberInvocationExpressionInfo(localInfo.Value);

                newExpression = invocationInfo.Expression;
            }

            SwitchStatementSyntax newSwitchStatement = switchStatement
                                                       .WithExpression(newExpression.WithTriviaFrom(expression))
                                                       .WithSections(newSections);

            if (localDeclaration != null)
            {
                StatementListInfo statementsInfo = SyntaxInfo.StatementListInfo(switchStatement);

                newSwitchStatement = newSwitchStatement.WithLeadingTrivia(localDeclaration.GetLeadingTrivia());

                SyntaxList <StatementSyntax> newStatements = statementsInfo.Statements
                                                             .Replace(switchStatement, newSwitchStatement)
                                                             .RemoveAt(statementsInfo.IndexOf(localDeclaration));

                return(document.ReplaceStatementsAsync(statementsInfo, newStatements, cancellationToken));
            }
            else
            {
                return(document.ReplaceNodeAsync(switchStatement, newSwitchStatement, cancellationToken));
            }
        }
 //
 // Summary:
 //     Called when the visitor visits a CasePatternSwitchLabelSyntax node.
 public virtual void VisitCasePatternSwitchLabel(CasePatternSwitchLabelSyntax node);