From 80c3b8dc6a5b2c32507abfca66dd25b11c7aeb5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Wed, 13 Jun 2012 10:10:19 +0200 Subject: [PATCH] [Formatter] The formatting visitor can now take a region to format. --- .../Formatter/AstFormattingVisitor.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs b/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs index 5d91a97ca5..ac58953794 100644 --- a/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs @@ -97,6 +97,11 @@ namespace ICSharpCode.NRefactory.CSharp get; set; } + + public DomRegion FormattingRegion { + get; + set; + } public AstFormattingVisitor(CSharpFormattingOptions policy, IDocument document, TextEditorOptions options = null) { @@ -111,6 +116,22 @@ namespace ICSharpCode.NRefactory.CSharp this.options = options ?? TextEditorOptions.Default; curIndent = new Indent(this.options); } + + protected virtual void VisitChildren (AstNode node) + { + if (!FormattingRegion.IsEmpty) { + if (node.EndLocation < FormattingRegion.Begin || node.StartLocation > FormattingRegion.End) + return; + } + + AstNode next; + for (var child = node.FirstChild; child != null; child = next) { + // Store next to allow the loop to continue + // if the visitor removes/replaces child. + next = child.NextSibling; + child.AcceptVisitor (this); + } + } /// /// Applies the changes to the input document.