Browse Source

Merge remote-tracking branch 'upstream/master' into mansheng

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
e7a902baca
  1. 2
      ICSharpCode.NRefactory.CSharp/Formatter/AstFormattingVisitor.cs
  2. 14
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/ExtractMethodAction.cs
  3. 16
      ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs
  4. 2
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtractMethodTests.cs
  5. 14
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs

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

@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.CSharp
curIndent = new Indent(this.options); curIndent = new Indent(this.options);
} }
protected virtual void VisitChildren (AstNode node) protected override void VisitChildren (AstNode node)
{ {
if (!FormattingRegion.IsEmpty) { if (!FormattingRegion.IsEmpty) {
if (node.EndLocation < FormattingRegion.Begin || node.StartLocation > FormattingRegion.End) if (node.EndLocation < FormattingRegion.Begin || node.StartLocation > FormattingRegion.End)

14
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/ExtractMethodAction.cs

@ -31,6 +31,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.CSharp.Analysis; using ICSharpCode.NRefactory.CSharp.Analysis;
using System.Threading; using System.Threading;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using System.Threading.Tasks;
namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
{ {
@ -78,10 +79,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
}; };
if (!StaticVisitor.UsesNotStaticMember(context, expression)) if (!StaticVisitor.UsesNotStaticMember(context, expression))
method.Modifiers |= Modifiers.Static; method.Modifiers |= Modifiers.Static;
script.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method); var task = script.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method);
task.ContinueWith (delegate {
var target = new IdentifierExpression(methodName); var target = new IdentifierExpression(methodName);
script.Replace(expression, new InvocationExpression(target)); script.Replace(expression, new InvocationExpression(target));
// script.Link(target, method.NameToken); script.Link(target, method.NameToken);
}, TaskScheduler.FromCurrentSynchronizationContext ());
}); });
} }
@ -180,13 +183,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
new ParameterDeclaration(context.CreateShortType(status.Item1.Type), status.Item1.Name, mod)); new ParameterDeclaration(context.CreateShortType(status.Item1.Type), status.Item1.Name, mod));
invocation.Arguments.Add(argumentExpression); invocation.Arguments.Add(argumentExpression);
} }
var task = script.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method);
task.ContinueWith (delegate {
foreach (var node in statements.Skip (1)) { foreach (var node in statements.Skip (1)) {
script.Remove(node); script.Remove(node);
} }
script.Replace(statements [0], new ExpressionStatement(invocation)); script.Replace(statements [0], new ExpressionStatement(invocation));
script.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method); script.Link(target, method.NameToken);
//script.Link(target, method.NameToken); }, TaskScheduler.FromCurrentSynchronizationContext ());
}); });
} }
} }

16
ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs

@ -28,6 +28,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using System.Threading.Tasks;
namespace ICSharpCode.NRefactory.CSharp.Refactoring namespace ICSharpCode.NRefactory.CSharp.Refactoring
{ {
@ -161,10 +162,11 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
output.RegisterTrackedSegments(this, startOffset); output.RegisterTrackedSegments(this, startOffset);
} }
public virtual void Link (params AstNode[] nodes) public virtual Task Link (params AstNode[] nodes)
{ {
// Default implementation: do nothing // Default implementation: do nothing
// Derived classes are supposed to enter the text editor's linked state. // Derived classes are supposed to enter the text editor's linked state.
return null;
} }
public void Replace (AstNode node, AstNode replaceWith) public void Replace (AstNode node, AstNode replaceWith)
@ -198,24 +200,24 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
End End
} }
public virtual void InsertWithCursor(string operation, InsertPosition defaultPosition, IEnumerable<AstNode> node) public virtual Task InsertWithCursor(string operation, InsertPosition defaultPosition, IEnumerable<AstNode> node)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public virtual void InsertWithCursor(string operation, ITypeDefinition parentType, IEnumerable<AstNode> node) public virtual Task InsertWithCursor(string operation, ITypeDefinition parentType, IEnumerable<AstNode> node)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void InsertWithCursor(string operation, InsertPosition defaultPosition, params AstNode[] nodes) public Task InsertWithCursor(string operation, InsertPosition defaultPosition, params AstNode[] nodes)
{ {
InsertWithCursor(operation, defaultPosition, (IEnumerable<AstNode>)nodes); return InsertWithCursor(operation, defaultPosition, (IEnumerable<AstNode>)nodes);
} }
public void InsertWithCursor(string operation, ITypeDefinition parentType, params AstNode[] nodes) public Task InsertWithCursor(string operation, ITypeDefinition parentType, params AstNode[] nodes)
{ {
InsertWithCursor(operation, parentType, (IEnumerable<AstNode>)nodes); return InsertWithCursor(operation, parentType, (IEnumerable<AstNode>)nodes);
} }
protected virtual int GetIndentLevelAt (int offset) protected virtual int GetIndentLevelAt (int offset)

2
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtractMethodTests.cs

@ -28,11 +28,11 @@ using ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod;
namespace ICSharpCode.NRefactory.CSharp.CodeActions namespace ICSharpCode.NRefactory.CSharp.CodeActions
{ {
[Ignore("FIXME!!")]
[TestFixture] [TestFixture]
public class ExtractMethodTests : ContextActionTestBase public class ExtractMethodTests : ContextActionTestBase
{ {
[Ignore("FIXME!!")]
[Test()] [Test()]
public void ExtractMethodResultStatementTest() public void ExtractMethodResultStatementTest()
{ {

14
ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs

@ -36,6 +36,7 @@ using ICSharpCode.NRefactory.Semantics;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using NUnit.Framework; using NUnit.Framework;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace ICSharpCode.NRefactory.CSharp.CodeActions namespace ICSharpCode.NRefactory.CSharp.CodeActions
{ {
@ -89,23 +90,27 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
this.context = context; this.context = context;
} }
public override void Link (params AstNode[] nodes) public override Task Link (params AstNode[] nodes)
{ {
// check that all links are valid. // check that all links are valid.
foreach (var node in nodes) { foreach (var node in nodes) {
Assert.IsNotNull (GetSegment (node)); Assert.IsNotNull (GetSegment (node));
} }
return new Task (() => {});
} }
public override void InsertWithCursor(string operation, InsertPosition defaultPosition, IEnumerable<AstNode> nodes) public override Task InsertWithCursor(string operation, InsertPosition defaultPosition, IEnumerable<AstNode> nodes)
{ {
var entity = context.GetNode<EntityDeclaration>(); var entity = context.GetNode<EntityDeclaration>();
foreach (var node in nodes) { foreach (var node in nodes) {
InsertBefore(entity, node); InsertBefore(entity, node);
} }
var t = new Task (() => {});
t.RunSynchronously ();
return t;
} }
public override void InsertWithCursor (string operation, ITypeDefinition parentType, IEnumerable<AstNode> nodes) public override Task InsertWithCursor (string operation, ITypeDefinition parentType, IEnumerable<AstNode> nodes)
{ {
var unit = context.RootNode; var unit = context.RootNode;
var insertType = unit.GetNodeAt<TypeDeclaration> (parentType.Region.Begin); var insertType = unit.GetNodeAt<TypeDeclaration> (parentType.Region.Begin);
@ -116,6 +121,9 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
InsertText (startOffset, output.Text); InsertText (startOffset, output.Text);
output.RegisterTrackedSegments (this, startOffset); output.RegisterTrackedSegments (this, startOffset);
} }
var t = new Task (() => {});
t.RunSynchronously ();
return t;
} }
void Rename (AstNode node, string newName) void Rename (AstNode node, string newName)

Loading…
Cancel
Save