Browse Source

Speeded up document script node formatting.

pull/32/merge
Mike Krüger 13 years ago
parent
commit
8639ca4d5b
  1. 7
      ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs
  2. 474
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  3. 26
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SortUsingsAction.cs
  4. 18
      ICSharpCode.NRefactory.CSharp/Refactoring/DocumentScript.cs
  5. 20
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs
  6. 1
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/SplitDeclarationAndAssignmentTests.cs

7
ICSharpCode.NRefactory.CSharp/Ast/AstNode.cs

@ -31,6 +31,7 @@ using System.Diagnostics; @@ -31,6 +31,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.TypeSystem;
namespace ICSharpCode.NRefactory.CSharp
{
@ -192,6 +193,12 @@ namespace ICSharpCode.NRefactory.CSharp @@ -192,6 +193,12 @@ namespace ICSharpCode.NRefactory.CSharp
return child.EndLocation;
}
}
public DomRegion Region {
get {
return new DomRegion (StartLocation, EndLocation);
}
}
/// <summary>
/// Gets the region from StartLocation to EndLocation for this node.

474
ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs

File diff suppressed because it is too large Load Diff

26
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/SortUsingsAction.cs

@ -1,3 +1,29 @@ @@ -1,3 +1,29 @@
//
// SortUsingsAction.cs
//
// Author:
// Lopatkin Ilja
//
// Copyright (c) 2012 Lopatkin Ilja
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;

18
ICSharpCode.NRefactory.CSharp/Refactoring/DocumentScript.cs

@ -40,8 +40,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -40,8 +40,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
get { return originalDocument; }
}
readonly IDisposable undoGroup;
public DocumentScript(IDocument document, CSharpFormattingOptions formattingOptions, TextEditorOptions options) : base(formattingOptions, options)
{
this.originalDocument = document.CreateDocumentSnapshot();
@ -101,15 +101,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -101,15 +101,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
public override void FormatText(IEnumerable<AstNode> nodes)
{
var syntaxTree = SyntaxTree.Parse(currentDocument, "dummy.cs");
var formatter = new AstFormattingVisitor(FormattingOptions, currentDocument, Options);
var segments = new List<ISegment>();
foreach (var node in nodes.OrderByDescending (n => n.StartLocation)) {
var segment = GetSegment(node);
var formatter = new AstFormattingVisitor(FormattingOptions, currentDocument, Options);
formatter.FormattingRegion = new ICSharpCode.NRefactory.TypeSystem.DomRegion (
formatter.AddFormattingRegion (new ICSharpCode.NRefactory.TypeSystem.DomRegion (
currentDocument.GetLocation (segment.Offset),
currentDocument.GetLocation (segment.EndOffset)
);
syntaxTree.AcceptVisitor(formatter);
));
segments.Add(segment);
}
syntaxTree.AcceptVisitor(formatter);
foreach (var segment in segments) {
formatter.ApplyChanges(segment.Offset, segment.Length);
}
}

20
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs

@ -58,8 +58,8 @@ class A @@ -58,8 +58,8 @@ class A
int $i = 2;
}
", @"
int i = 2;
while (true) {
int i = 2;
while (true) {
}
");
}
@ -86,8 +86,8 @@ class A @@ -86,8 +86,8 @@ class A
}
", @"
int i = 2;
while (true) {
int j = 3;
while (true) {
int j = 3;
}
");
}
@ -100,8 +100,8 @@ class A @@ -100,8 +100,8 @@ class A
i$nt i = 2, j = 3;
}
", @"
int i = 2, j = 3;
while (true) {
int i = 2, j = 3;
while (true) {
}
");
}
@ -115,11 +115,11 @@ class A @@ -115,11 +115,11 @@ class A
int j$ = i;
}
", @"
int j;
int j;
while (true) {
int i = 2;
j = i;
}
}
");
}
@ -131,8 +131,8 @@ class A @@ -131,8 +131,8 @@ class A
int j$ = 2;
});
", @"
int j = 2;
var action = new Action<int>(i => {
int j = 2;
var action = new Action<int>(i => {
});
");
}

1
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/SplitDeclarationAndAssignmentTests.cs

@ -101,7 +101,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions @@ -101,7 +101,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
" {" + Environment.NewLine +
" int i;" + Environment.NewLine +
" for (i = 1; i < 10; i++) {" + Environment.NewLine +
" " + Environment.NewLine +
" }" + Environment.NewLine +
" }" + Environment.NewLine +
"}", result);

Loading…
Cancel
Save