public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block() { // Arrange var factory = SpanFactory.CreateCsHtml(); Block start = new MarkupBlock( factory.Markup("test"), new ExpressionBlock( factory.Code(" ").AsExpression(), factory.CodeTransition(SyntaxConstants.TransitionString), factory.Code("foo").AsExpression() ), factory.Markup("test") ); WhiteSpaceRewriter rewriter = new WhiteSpaceRewriter(new HtmlMarkupParser().BuildSpan); // Act Block actual = rewriter.Rewrite(start); factory.Reset(); // Assert ParserTestBase.EvaluateParseTree(actual, new MarkupBlock( factory.Markup("test"), factory.Markup(" "), new ExpressionBlock( factory.CodeTransition(SyntaxConstants.TransitionString), factory.Code("foo").AsExpression() ), factory.Markup("test") )); }
public async Task <SyntaxNode> NormalizeWhiteSpaceHelperAsync(SyntaxNode initialSourceNode, Options options) { var modifiedSourceNode = initialSourceNode; if (TidyCSharpPackage.Instance != null) { modifiedSourceNode = Formatter.Format(modifiedSourceNode, TidyCSharpPackage.Instance.CleanupWorkingSolution.Workspace); } var blockRewriter = new BlockRewriter(modifiedSourceNode, IsReportOnlyMode, options); modifiedSourceNode = blockRewriter.Visit(modifiedSourceNode); if (IsReportOnlyMode) { CollectMessages(blockRewriter.GetReport()); } modifiedSourceNode = await RefreshResultAsync(modifiedSourceNode); if (CheckOption((int)CleanupTypes.Use_Slash_Instead_Of_Slash_Slash)) { var endoflineRewriter = new EndOFLineRewriter(modifiedSourceNode, IsReportOnlyMode, options); modifiedSourceNode = endoflineRewriter.Visit(modifiedSourceNode); modifiedSourceNode = await RefreshResultAsync(modifiedSourceNode); if (IsReportOnlyMode) { CollectMessages(endoflineRewriter.GetReport()); } } var whitespaceRewriter = new WhiteSpaceRewriter(modifiedSourceNode, IsReportOnlyMode, options); modifiedSourceNode = whitespaceRewriter.Apply(); if (IsReportOnlyMode) { CollectMessages(whitespaceRewriter.GetReport()); } if (CheckOption((int)CleanupTypes.Add_Blank_Line_Between_Statements_More_Than_One_Line)) { modifiedSourceNode = await RefreshResultAsync(modifiedSourceNode); var blRewriter = new BlankLineRewriter(modifiedSourceNode, IsReportOnlyMode, ProjectItemDetails.SemanticModel); modifiedSourceNode = blRewriter.Visit(modifiedSourceNode); if (IsReportOnlyMode) { CollectMessages(blRewriter.GetReport()); } } if (IsReportOnlyMode) { return(initialSourceNode); } return(modifiedSourceNode); }
public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree) { if (codeDocument == null) { throw new ArgumentNullException(nameof(codeDocument)); } if (syntaxTree == null) { throw new ArgumentNullException(nameof(syntaxTree)); } var conditionalAttributeCollapser = new ConditionalAttributeCollapser(); var rewritten = conditionalAttributeCollapser.Rewrite(syntaxTree.Root); var whitespaceRewriter = new WhiteSpaceRewriter(); rewritten = whitespaceRewriter.Rewrite(rewritten); var rewrittenSyntaxTree = RazorSyntaxTree.Create(rewritten, syntaxTree.Source, syntaxTree.Diagnostics, syntaxTree.Options); return(rewrittenSyntaxTree); }