void ExportStatement(SwitchStatementSyntax ss) { var node = new ULStatementSwitch(); node.Parent = currentBlock; node.Condition = ExportExp(ss.Expression).GetOutputName(0); node.Sections = new List <ULStatementSwitch.Section>(); foreach (var s in ss.Sections) { var section = new ULStatementSwitch.Section(); section.Labels = new List <string>(); section.Statements = new List <ULNodeBlock>(); node.Sections.Add(section); foreach (var l in s.Labels) { if (l is CaseSwitchLabelSyntax) { CaseSwitchLabelSyntax csls = l as CaseSwitchLabelSyntax; section.Labels.Add(ExportExp(csls.Value).GetOutputName(0)); } } foreach (var statement in s.Statements) { section.Statements.Add(ExportStatement(statement as BlockSyntax)); } } currentBlock.statements.Add(node); }
public override string VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { StringBuilder sb = new StringBuilder(); sb.AppendLine("case " + Visit(node.Value) + ":"); return(sb.ToString()); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document .GetSyntaxRootAsync(context.CancellationToken) .ConfigureAwait(false); CaseSwitchLabelSyntax label = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <CaseSwitchLabelSyntax>(); if (label == null) { return; } CodeAction codeAction = CodeAction.Create( "Remove unnecessary case label", cancellationToken => { return(RemoveUnnecessaryCaseLabelRefactoring.RefactorAsync( context.Document, label, cancellationToken)); }, DiagnosticIdentifiers.RemoveUnnecessaryCaseLabel + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public static Doc Print(CaseSwitchLabelSyntax node) { return(Doc.Concat( Token.PrintWithSuffix(node.Keyword, " "), Doc.Group(Node.Print(node.Value)), Token.Print(node.ColonToken) )); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { if (currentMethod != null) { currentMethod.cyclomaticComplexity++; } base.VisitCaseSwitchLabel(node); }
private Doc PrintCaseSwitchLabelSyntax(CaseSwitchLabelSyntax node) { return(Concat( this.PrintSyntaxToken(node.Keyword, " "), this.Print(node.Value), this.PrintSyntaxToken(node.ColonToken) )); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { var lastWhen = LastWhen as ApexWhenExpressionsClauseSyntax ?? new ApexWhenExpressionsClauseSyntax(); var expression = ConvertExpression(node.Value); lastWhen.Expressions.Add(expression); LastWhen = lastWhen; }
public static void Go(OutputWriter writer, CaseSwitchLabelSyntax method, bool isStringSwitch = false) { writer.Write("case "); //writer.WriteLine("case " + method.Value.ToString() +":"); Core.Write(writer, method.Value); writer.Write(isStringSwitch ? ".Text" : ""); writer.Write(":\r\n"); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } nobcounter++; base.VisitCaseSwitchLabel(node); }
private static Task <Document> ConvertSwitchExpressionToSwitchStatement( Document document, SwitchExpressionSyntax switchExpression, CancellationToken cancellationToken) { IEnumerable <SwitchSectionSyntax> sections = switchExpression.Arms.Select((arm, i) => { SyntaxToken separator = switchExpression.Arms.GetSeparator(i); SyntaxToken semicolon = Token(SyntaxKind.SemicolonToken); if (!separator.IsMissing) { semicolon = semicolon.WithTriviaFrom(separator); } PatternSyntax pattern = arm.Pattern; switch (pattern.Kind()) { case SyntaxKind.ConstantPattern: { CaseSwitchLabelSyntax label = CaseSwitchLabel( Token(SyntaxKind.CaseKeyword).WithLeadingTrivia(pattern.GetLeadingTrivia()), ((ConstantPatternSyntax)pattern).Expression.WithoutLeadingTrivia(), Token(SyntaxKind.ColonToken).WithTriviaFrom(arm.EqualsGreaterThanToken)); return(SwitchSection(label, CreateStatement(arm.Expression, semicolon))); } case SyntaxKind.DiscardPattern: { DefaultSwitchLabelSyntax label = DefaultSwitchLabel(Token(SyntaxKind.DefaultKeyword), Token(SyntaxKind.ColonToken)); return(SwitchSection(label, CreateStatement(arm.Expression, semicolon))); } default: { throw new InvalidOperationException(); } } }); var returnStatement = (ReturnStatementSyntax)switchExpression.Parent; SwitchStatementSyntax switchStatement = SwitchStatement( switchExpression.SwitchKeyword.WithTriviaFrom(returnStatement.ReturnKeyword), OpenParenToken(), switchExpression.GoverningExpression, CloseParenToken().WithTrailingTrivia(switchExpression.SwitchKeyword.TrailingTrivia), switchExpression.OpenBraceToken, sections.ToSyntaxList(), switchExpression.CloseBraceToken); switchStatement = switchStatement.WithFormatterAnnotation(); return(document.ReplaceNodeAsync(returnStatement, switchStatement, cancellationToken));
public static void ReportCasePatternNotSupported( this SyntaxNodeAnalysisContext context, CaseSwitchLabelSyntax switchLabel) { var diagnostic = Diagnostic.Create( ExhaustiveMatchAnalyzer.CasePatternNotSupported, switchLabel.Value.GetLocation(), switchLabel.Value.ToString()); context.ReportDiagnostic(diagnostic); }
// This is you want to override a node for the AST, go look at the Documentation // folder to see which methods you can overrride public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { // This will be executed for every CaseSwitchLabel // When you detect an issue, you can report it by doing this : // var issue = new Issue(IssueType.TheIssueYouCareAbout, node); // IssueReporter.Instance.AddIssue(issue); base.VisitCaseSwitchLabel(node); }
private static SyntaxRemoveOptions GetRemoveOptions(CaseSwitchLabelSyntax label) { if (label.GetLeadingTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia()) && label.GetTrailingTrivia().All(f => f.IsWhitespaceOrEndOfLineTrivia())) { return(SyntaxRemoveOptions.KeepNoTrivia); } return(SyntaxRemoveOptions.KeepExteriorTrivia); }
private static SyntaxRemoveOptions GetRemoveOptions(CaseSwitchLabelSyntax label) { if (label.GetLeadingTrivia().IsEmptyOrWhitespace() && label.GetTrailingTrivia().IsEmptyOrWhitespace()) { return(SyntaxRemoveOptions.KeepNoTrivia); } return(SyntaxRemoveOptions.KeepExteriorTrivia); }
public static Task <Document> RefactorAsync( Document document, CaseSwitchLabelSyntax label, CancellationToken cancellationToken) { var switchSection = (SwitchSectionSyntax)label.Parent; SwitchSectionSyntax newNode = switchSection.RemoveNode(label, GetRemoveOptions(label)) .WithFormatterAnnotation(); return(document.ReplaceNodeAsync(switchSection, newNode, cancellationToken)); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } embeddednessNode = node; embeddednessHasBeenIncreased = false; embeddednessHasBeenDecreased = false; base.VisitCaseSwitchLabel(node); embeddednessNode = null; }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { if (!PreVisit(node)) { return; } node.Value?.Accept(this); base.VisitCaseSwitchLabel(node); PostVisit(node); }
private static async Task <Document> RemoveCaseSwitchLabelAsync( Document document, CaseSwitchLabelSyntax label, CancellationToken cancellationToken) { SyntaxNode oldRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var switchSection = (SwitchSectionSyntax)label.Parent; SwitchSectionSyntax newNode = switchSection.RemoveNode(label, GetRemoveOptions(label)) .WithFormatterAnnotation(); SyntaxNode newRoot = oldRoot.ReplaceNode(switchSection, newNode); return(document.WithSyntaxRoot(newRoot)); }
private SwitchSectionSyntax ParseSwitchSection() { // First, parse case label(s) var labels = new List <SwitchLabelSyntax>(); var statements = new List <StatementSyntax>(); do { SyntaxToken specifier; SwitchLabelSyntax label; SyntaxToken colon; if (Current.Kind == SyntaxKind.CaseKeyword) { ExpressionSyntax expression; specifier = NextToken(); if (Current.Kind == SyntaxKind.ColonToken) { expression = CreateMissingIdentifierName(); expression = WithDiagnostic(expression, DiagnosticId.ConstantExpected); } else { expression = ParseExpression(); } colon = Match(SyntaxKind.ColonToken); label = new CaseSwitchLabelSyntax(specifier, expression, colon); } else { Debug.Assert(Current.Kind == SyntaxKind.DefaultKeyword); specifier = Match(SyntaxKind.DefaultKeyword); colon = Match(SyntaxKind.ColonToken); label = new DefaultSwitchLabelSyntax(specifier, colon); } labels.Add(label); }while (IsPossibleSwitchSection()); // Next, parse statement list stopping for new sections ParseStatements(statements, true); return(new SwitchSectionSyntax(labels, statements)); }
public static void Go(OutputWriter writer, CaseSwitchLabelSyntax method, bool isStringSwitch = false) { writer.Write("case "); if (isStringSwitch)// && method.Value.ToString ().Trim () == "null") { var value = Core.WriteString (method.Value, true, writer.Indent); if (value.Trim () == "null") writer.Write ("-1"); else { Core.Write (writer, method.Value); writer.Write (isStringSwitch ? ".Hash" : ""); } } else { //writer.WriteLine("case " + method.Value.ToString() +":"); Core.Write (writer, method.Value); } writer.Write(":\r\n"); }
public static void Go(OutputWriter writer, CaseSwitchLabelSyntax method, bool isStringSwitch = false) { writer.Write("case "); if (isStringSwitch) // && method.Value.ToString ().Trim () == "null") { var value = Core.WriteString(method.Value, true, writer.Indent); if (value.Trim() == "null") { writer.Write("-1"); } else { Core.Write(writer, method.Value); writer.Write(isStringSwitch ? ".Hash" : ""); } } else { //writer.WriteLine("case " + method.Value.ToString() +":"); Core.Write(writer, method.Value); } writer.Write(":\r\n"); }
public override void VisitSwitchSection(SwitchSectionSyntax node) { for (int i = 0; i < node.Labels.Count; i++) { if (node.Labels[i] is CaseSwitchLabelSyntax) { CaseSwitchLabelSyntax switchLabelSyntax = node.Labels[i] as CaseSwitchLabelSyntax; Emit(string.Format("{0} {1}:", switchLabelSyntax.Keyword.Text, switchLabelSyntax.Value)); } else { DefaultSwitchLabelSyntax switchLabelSyntax = node.Labels[i] as DefaultSwitchLabelSyntax; Emit(string.Format("{0}:", switchLabelSyntax.Keyword.Text)); } } using (IndentedBracketScope()) { base.VisitSwitchSection(node); } Emit("break;"); }
public override UstNode VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { var result = (Expression)base.Visit(node.Value); return(result); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { }
override public void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { Complexity++; base.VisitCaseSwitchLabel(node); }
public CaseSwitchLabelTranslation(CaseSwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { Value = syntax.Value.Get<ExpressionTranslation>(this); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { AddLocation(node.Keyword); base.VisitCaseSwitchLabel(node); }
public virtual void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { DefaultVisit(node); }
public static async Task ComputeRefactoringsAsync(RefactoringContext context, CaseSwitchLabelSyntax caseLabel) { if (context.IsAnyRefactoringEnabled(RefactoringIdentifiers.AddCastExpression, RefactoringIdentifiers.CallToMethod)) { ExpressionSyntax value = caseLabel.Value; if (value?.Span.Contains(context.Span) == true) { var switchStatement = caseLabel.Parent?.Parent as SwitchStatementSyntax; if (switchStatement != null) { ExpressionSyntax expression = switchStatement.Expression; if (expression?.IsMissing == false) { SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false); ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(expression, context.CancellationToken); if (typeSymbol?.IsErrorType() == false) { ModifyExpressionRefactoring.ComputeRefactoring(context, value, typeSymbol, semanticModel); } } } } } }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitCaseSwitchLabel(node); }
public override void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitCaseSwitchLabel(CaseSwitchLabelSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitCaseSwitchLabel(node); }
public static void Write(this CaseSwitchLabelSyntax syntax, IIndentedTextWriterWrapper textWriter, IContext context) { textWriter.Write("switchValue == "); syntax.Value.Write(textWriter, context); }
public CaseSwitchLabelTranslation(CaseSwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { Value = syntax.Value.Get <ExpressionTranslation>(this); }
private SwitchSectionSyntax ParseSwitchSection() { // First, parse case label(s) var labels = new List<SwitchLabelSyntax>(); var statements = new List<StatementSyntax>(); do { SyntaxToken specifier; SwitchLabelSyntax label; SyntaxToken colon; if (Current.Kind == SyntaxKind.CaseKeyword) { ExpressionSyntax expression; specifier = NextToken(); if (Current.Kind == SyntaxKind.ColonToken) { expression = CreateMissingIdentifierName(); expression = WithDiagnostic(expression, DiagnosticId.ConstantExpected); } else { expression = ParseExpression(); } colon = Match(SyntaxKind.ColonToken); label = new CaseSwitchLabelSyntax(specifier, expression, colon); } else { Debug.Assert(Current.Kind == SyntaxKind.DefaultKeyword); specifier = Match(SyntaxKind.DefaultKeyword); colon = Match(SyntaxKind.ColonToken); label = new DefaultSwitchLabelSyntax(specifier, colon); } labels.Add(label); } while (IsPossibleSwitchSection()); // Next, parse statement list stopping for new sections ParseStatements(statements, true); return new SwitchSectionSyntax(labels, statements); }