Browse Source

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

newNRvisualizers
Mansheng Yang 14 years ago
parent
commit
cbf1bdf40a
  1. 2
      ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs
  2. 5
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  3. 124
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/ExtractMethodAction.cs
  4. 23
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/VariableLookupVisitor.cs
  5. 146
      ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/VariableUsageAnalyzation.cs
  6. 2
      ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs
  7. 70
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/ExtractMethodTests.cs
  8. 12
      ICSharpCode.NRefactory.Tests/CSharp/CodeActions/TestRefactoringContext.cs
  9. 42
      ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

2
ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngineBase.cs

@ -801,6 +801,8 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
if (root == null) { if (root == null) {
return null; return null;
} }
if (root is Accessor)
root = root.Parent;
var csResolver = CompletionContextProvider.GetResolver (GetState(), root); var csResolver = CompletionContextProvider.GetResolver (GetState(), root);
var result = csResolver.Resolve(resolveNode); var result = csResolver.Resolve(resolveNode);
var state = csResolver.GetResolverStateBefore(resolveNode); var state = csResolver.GetResolverStateBefore(resolveNode);

5
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -14,7 +14,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ProductVersion>10.0.0</ProductVersion> <ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<SignAssembly>true</SignAssembly> <SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>..\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign> <DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode> <AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
@ -45,7 +45,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType> <DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>True</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
@ -417,6 +417,7 @@
<Compile Include="Refactoring\CodeActions\ImplementAbstractMembersAction.cs" /> <Compile Include="Refactoring\CodeActions\ImplementAbstractMembersAction.cs" />
<Compile Include="Refactoring\CodeActions\ExtractFieldAction.cs" /> <Compile Include="Refactoring\CodeActions\ExtractFieldAction.cs" />
<Compile Include="Completion\ICompletionContextProvider.cs" /> <Compile Include="Completion\ICompletionContextProvider.cs" />
<Compile Include="Refactoring\CodeActions\ExtractMethod\VariableUsageAnalyzation.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> <ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">

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

@ -80,11 +80,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
if (!StaticVisitor.UsesNotStaticMember(context, expression)) if (!StaticVisitor.UsesNotStaticMember(context, expression))
method.Modifiers |= Modifiers.Static; method.Modifiers |= Modifiers.Static;
var task = 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 {
Action<Task> replaceStatements = 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 ()); };
if (task.IsCompleted) {
replaceStatements (null);
} else {
task.ContinueWith (replaceStatements, TaskScheduler.FromCurrentSynchronizationContext ());
}
}); });
} }
@ -113,84 +120,87 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
var usedVariables = VariableLookupVisitor.Analyze(context, statements); var usedVariables = VariableLookupVisitor.Analyze(context, statements);
var extractedCodeAnalysis = new DefiniteAssignmentAnalysis( var inExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
(Statement)statements [0].Parent,
context.Resolver,
context.CancellationToken);
var lastStatement = statements [statements.Count - 1]; var lastStatement = statements [statements.Count - 1];
extractedCodeAnalysis.SetAnalyzedRange(statements [0], lastStatement);
var statusAfterMethod = new List<Tuple<IVariable, DefiniteAssignmentStatus>>();
foreach (var variable in usedVariables) {
extractedCodeAnalysis.Analyze(
variable.Name,
DefiniteAssignmentStatus.PotentiallyAssigned,
context.CancellationToken);
statusAfterMethod.Add(Tuple.Create(variable, extractedCodeAnalysis.GetStatusAfter(lastStatement)));
}
var stmt = statements [0].GetParent<BlockStatement>(); var stmt = statements [0].GetParent<BlockStatement>();
while (stmt.GetParent<BlockStatement> () != null) { while (stmt.GetParent<BlockStatement> () != null) {
stmt = stmt.GetParent<BlockStatement>(); stmt = stmt.GetParent<BlockStatement>();
} }
var wholeCodeAnalysis = new DefiniteAssignmentAnalysis(stmt, context.Resolver, context.CancellationToken); inExtractedRegion.SetAnalyzedRange(statements [0], lastStatement);
var statusBeforeMethod = new Dictionary<IVariable, DefiniteAssignmentStatus>(); stmt.AcceptVisitor (inExtractedRegion);
foreach (var variable in usedVariables) {
wholeCodeAnalysis.Analyze(variable.Name, DefiniteAssignmentStatus.PotentiallyAssigned, context.CancellationToken);
statusBeforeMethod [variable] = extractedCodeAnalysis.GetStatusBefore(statements [0]);
}
var afterCodeAnalysis = new DefiniteAssignmentAnalysis(stmt, context.Resolver, context.CancellationToken); var beforeExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
var statusAtEnd = new Dictionary<IVariable, DefiniteAssignmentStatus>(); beforeExtractedRegion.SetAnalyzedRange(statements [0].Parent, statements [0], true, false);
afterCodeAnalysis.SetAnalyzedRange(lastStatement, stmt.Statements.Last(), false, true); stmt.AcceptVisitor (beforeExtractedRegion);
var afterExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
afterExtractedRegion.SetAnalyzedRange(lastStatement, stmt.Statements.Last(), false, true);
stmt.AcceptVisitor (afterExtractedRegion);
usedVariables.Sort ((l, r) => l.Region.Begin.CompareTo (r.Region.Begin));
IVariable generatedReturnVariable = null;
foreach (var variable in usedVariables) { foreach (var variable in usedVariables) {
afterCodeAnalysis.Analyze(variable.Name, DefiniteAssignmentStatus.PotentiallyAssigned, context.CancellationToken); if ((variable is IParameter) || beforeExtractedRegion.Has (variable) || !afterExtractedRegion.Has (variable))
statusBeforeMethod [variable] = extractedCodeAnalysis.GetStatusBefore(statements [0]); continue;
generatedReturnVariable = variable;
method.ReturnType = context.CreateShortType (variable.Type);
method.Body.Add (new ReturnStatement (new IdentifierExpression (variable.Name)));
break;
} }
var beforeVisitor = new VariableLookupVisitor(context);
beforeVisitor.SetAnalyzedRange(stmt, statements [0], true, false); foreach (var variable in usedVariables) {
stmt.AcceptVisitor(beforeVisitor); if (!(variable is IParameter) && !beforeExtractedRegion.Has (variable) && !afterExtractedRegion.Has (variable))
var afterVisitor = new VariableLookupVisitor(context); continue;
afterVisitor.SetAnalyzedRange(lastStatement, stmt, false, true); if (variable == generatedReturnVariable)
stmt.AcceptVisitor(afterVisitor);
foreach (var status in statusAfterMethod) {
if (!beforeVisitor.UsedVariables.Contains(status.Item1) && !afterVisitor.UsedVariables.Contains(status.Item1))
continue; continue;
Expression argumentExpression = new IdentifierExpression(status.Item1.Name); Expression argumentExpression = new IdentifierExpression(variable.Name);
ParameterModifier mod; ParameterModifier mod = ParameterModifier.None;
switch (status.Item2) { if (inExtractedRegion.GetStatus (variable) == VariableState.Changed) {
case DefiniteAssignmentStatus.AssignedAfterTrueExpression: if (beforeExtractedRegion.GetStatus (variable) == VariableState.None) {
case DefiniteAssignmentStatus.AssignedAfterFalseExpression:
case DefiniteAssignmentStatus.PotentiallyAssigned:
mod = ParameterModifier.Ref;
argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
break;
case DefiniteAssignmentStatus.DefinitelyAssigned:
if (statusBeforeMethod [status.Item1] != DefiniteAssignmentStatus.PotentiallyAssigned)
goto case DefiniteAssignmentStatus.PotentiallyAssigned;
mod = ParameterModifier.Out; mod = ParameterModifier.Out;
argumentExpression = new DirectionExpression(FieldDirection.Out, argumentExpression); argumentExpression = new DirectionExpression(FieldDirection.Out, argumentExpression);
break; } else {
// case DefiniteAssignmentStatus.Unassigned: mod = ParameterModifier.Ref;
default: argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
mod = ParameterModifier.None; }
break;
} }
method.Parameters.Add(
new ParameterDeclaration(context.CreateShortType(status.Item1.Type), status.Item1.Name, mod)); method.Parameters.Add(new ParameterDeclaration(context.CreateShortType(variable.Type), variable.Name, mod));
invocation.Arguments.Add(argumentExpression); invocation.Arguments.Add(argumentExpression);
} }
var task = 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 { Action<Task> replaceStatements = 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)); foreach (var variable in usedVariables) {
if ((variable is IParameter) || beforeExtractedRegion.Has (variable) || !afterExtractedRegion.Has (variable))
continue;
if (variable == generatedReturnVariable)
continue;
script.InsertBefore (statements [0], new VariableDeclarationStatement (context.CreateShortType(variable.Type), variable.Name));
}
AstNode invocationStatement;
if (generatedReturnVariable != null) {
invocationStatement = new VariableDeclarationStatement (new SimpleType ("var"), generatedReturnVariable.Name, invocation);
} else {
invocationStatement = new ExpressionStatement(invocation);
}
script.Replace(statements [0], invocationStatement);
script.Link(target, method.NameToken); script.Link(target, method.NameToken);
}, TaskScheduler.FromCurrentSynchronizationContext ()); };
if (task.IsCompleted) {
replaceStatements (null);
} else {
task.ContinueWith (replaceStatements, TaskScheduler.FromCurrentSynchronizationContext ());
}
}); });
} }
} }

23
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/VariableLookupVisitor.cs

@ -33,18 +33,22 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
class VariableLookupVisitor : DepthFirstAstVisitor class VariableLookupVisitor : DepthFirstAstVisitor
{ {
readonly RefactoringContext context; readonly RefactoringContext context;
public List<IVariable> UsedVariables = new List<IVariable> (); public List<IVariable> UsedVariables = new List<IVariable> ();
TextLocation startLocation = TextLocation.Empty; TextLocation startLocation = TextLocation.Empty;
TextLocation endLocation = TextLocation.Empty; TextLocation endLocation = TextLocation.Empty;
public VariableLookupVisitor (RefactoringContext context) public VariableLookupVisitor (RefactoringContext context)
{ {
this.context = context; this.context = context;
} }
public bool Has (IVariable item1)
{
return UsedVariables.Contains (item1);
}
public void SetAnalyzedRange(AstNode start, AstNode end, bool startInclusive = true, bool endInclusive = true) public void SetAnalyzedRange(AstNode start, AstNode end, bool startInclusive = true, bool endInclusive = true)
{ {
if (start == null) if (start == null)
@ -54,17 +58,18 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
startLocation = startInclusive ? start.StartLocation : start.EndLocation; startLocation = startInclusive ? start.StartLocation : start.EndLocation;
endLocation = endInclusive ? end.EndLocation : end.StartLocation; endLocation = endInclusive ? end.EndLocation : end.StartLocation;
} }
public override void VisitIdentifierExpression(IdentifierExpression identifierExpression) public override void VisitIdentifierExpression(IdentifierExpression identifierExpression)
{ {
if (startLocation.IsEmpty || startLocation <= identifierExpression.StartLocation && identifierExpression.EndLocation <= endLocation) { if (startLocation.IsEmpty || startLocation <= identifierExpression.StartLocation && identifierExpression.EndLocation <= endLocation) {
var result = context.Resolve(identifierExpression); var result = context.Resolve(identifierExpression);
var local = result as LocalResolveResult; var local = result as LocalResolveResult;
if (local != null && !UsedVariables.Contains(local.Variable)) if (local != null && !UsedVariables.Contains(local.Variable)) {
UsedVariables.Add(local.Variable); UsedVariables.Add(local.Variable);
}
} }
} }
public override void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement) public override void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement)
{ {
base.VisitVariableDeclarationStatement(variableDeclarationStatement); base.VisitVariableDeclarationStatement(variableDeclarationStatement);
@ -78,14 +83,14 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
} }
} }
public static List<IVariable> Analyze(RefactoringContext context, Expression expression) public static List<IVariable> Analyze(RefactoringContext context, Expression expression)
{ {
var visitor = new VariableLookupVisitor(context); var visitor = new VariableLookupVisitor(context);
expression.AcceptVisitor(visitor); expression.AcceptVisitor(visitor);
return visitor.UsedVariables; return visitor.UsedVariables;
} }
public static List<IVariable> Analyze(RefactoringContext context, List<Statement> statements) public static List<IVariable> Analyze(RefactoringContext context, List<Statement> statements)
{ {
var visitor = new VariableLookupVisitor(context); var visitor = new VariableLookupVisitor(context);

146
ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/ExtractMethod/VariableUsageAnalyzation.cs

@ -0,0 +1,146 @@
//
// VariableUsageAnalyzation.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// 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 ICSharpCode.NRefactory.TypeSystem;
using System.Linq;
namespace ICSharpCode.NRefactory.CSharp.Refactoring.ExtractMethod
{
public enum VariableState {
None,
Used,
Changed
}
public class VariableUsageAnalyzation : DepthFirstAstVisitor
{
readonly RefactoringContext context;
readonly List<IVariable> usedVariables;
Dictionary<IVariable, VariableState> states = new Dictionary<IVariable, VariableState> ();
TextLocation startLocation = TextLocation.Empty;
TextLocation endLocation = TextLocation.Empty;
public VariableUsageAnalyzation (RefactoringContext context, List<IVariable> usedVariables)
{
this.context = context;
this.usedVariables = usedVariables;
}
public bool Has(IVariable variable)
{
return states.ContainsKey (variable);
}
public void SetAnalyzedRange(AstNode start, AstNode end, bool startInclusive = true, bool endInclusive = true)
{
if (start == null)
throw new ArgumentNullException("start");
if (end == null)
throw new ArgumentNullException("end");
startLocation = startInclusive ? start.StartLocation : start.EndLocation;
endLocation = endInclusive ? end.EndLocation : end.StartLocation;
states.Clear ();
}
public VariableState GetStatus (IVariable variable)
{
VariableState state;
if (!states.TryGetValue (variable, out state))
return VariableState.None;
return state;
}
void SetState (string identifier, VariableState state)
{
var variable = usedVariables.FirstOrDefault (v => v.Name == identifier);
if (variable == null)
return;
VariableState oldState;
if (states.TryGetValue (variable, out oldState)) {
if (oldState < state)
states [variable] = state;
} else {
states [variable] = state;
}
}
public override void VisitIdentifierExpression(IdentifierExpression identifierExpression)
{
if (startLocation.IsEmpty || startLocation <= identifierExpression.StartLocation && identifierExpression.EndLocation <= endLocation) {
SetState (identifierExpression.Identifier, VariableState.Used);
}
}
public override void VisitAssignmentExpression(AssignmentExpression assignmentExpression)
{
if (startLocation.IsEmpty || startLocation <= assignmentExpression.StartLocation && assignmentExpression.EndLocation <= endLocation) {
var left = assignmentExpression.Left as IdentifierExpression;
if (left != null)
SetState(left.Identifier, VariableState.Changed);
}
base.VisitAssignmentExpression (assignmentExpression);
}
public override void VisitDirectionExpression(DirectionExpression directionExpression)
{
if (startLocation.IsEmpty || startLocation <= directionExpression.StartLocation && directionExpression.EndLocation <= endLocation) {
var expr = directionExpression.Expression as IdentifierExpression;
if (expr != null)
SetState(expr.Identifier, VariableState.Changed);
}
base.VisitDirectionExpression (directionExpression);
}
public override void VisitVariableInitializer(VariableInitializer variableInitializer)
{
if (startLocation.IsEmpty || startLocation <= variableInitializer.StartLocation && variableInitializer.EndLocation <= endLocation) {
SetState(variableInitializer.Name, variableInitializer.Initializer.IsNull ? VariableState.None : VariableState.Changed);
}
base.VisitVariableInitializer(variableInitializer);
}
public override void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression)
{
if (startLocation.IsEmpty || startLocation <= unaryOperatorExpression.StartLocation && unaryOperatorExpression.EndLocation <= endLocation) {
if (unaryOperatorExpression.Operator == UnaryOperatorType.Increment || unaryOperatorExpression.Operator == UnaryOperatorType.Decrement ||
unaryOperatorExpression.Operator == UnaryOperatorType.PostIncrement || unaryOperatorExpression.Operator == UnaryOperatorType.PostDecrement) {
var expr = unaryOperatorExpression.Expression as IdentifierExpression;
if (expr != null)
SetState(expr.Identifier, VariableState.Changed);
}
}
base.VisitUnaryOperatorExpression (unaryOperatorExpression);
}
}
}

2
ICSharpCode.NRefactory.CSharp/Resolver/CSharpConversions.cs

@ -84,6 +84,8 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
public bool Equals(TypePair other) public bool Equals(TypePair other)
{ {
if (this.FromType == null || this.ToType == null || other.FromType == null || other.ToType == null)
return false;
return this.FromType.Equals(other.FromType) && this.ToType.Equals(other.ToType); return this.FromType.Equals(other.FromType) && this.ToType.Equals(other.ToType);
} }

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

@ -28,10 +28,59 @@ 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
{ {
[Test()]
public void SimpleArgument()
{
Test<ExtractMethodAction>(@"class TestClass
{
void TestMethod ()
{
int i = 5;
<-Console.WriteLine (i);->
}
}
", @"class TestClass
{
static void NewMethod (int i)
{
Console.WriteLine (i);
}
void TestMethod ()
{
int i = 5;
NewMethod (i);
}
}
");
}
[Test()]
public void NoArgument()
{
Test<ExtractMethodAction>(@"class TestClass
{
void TestMethod ()
{
int i = 5;
<-Console.WriteLine (""Hello World"");->
}
}
", @"class TestClass
{
static void NewMethod ()
{
Console.WriteLine (""Hello World"");
}
void TestMethod ()
{
int i = 5;
NewMethod ();
}
}
");
}
[Test()] [Test()]
public void ExtractMethodResultStatementTest() public void ExtractMethodResultStatementTest()
@ -91,7 +140,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
"); ");
} }
[Ignore("FIXME!!")]
[Test()] [Test()]
public void ExtractMethodStaticResultStatementTest() public void ExtractMethodStaticResultStatementTest()
{ {
@ -146,7 +194,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
"); ");
} }
[Ignore("FIXME!!")]
[Test()] [Test()]
public void ExtractMethodMultiVariableTest() public void ExtractMethodMultiVariableTest()
{ {
@ -164,7 +211,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
", @"class TestClass ", @"class TestClass
{ {
int member; int member;
void NewMethod (ref int j, int i, out int k) void NewMethod (int i, ref int j, out int k)
{ {
j = i + j; j = i + j;
k = j + member; k = j + member;
@ -185,7 +232,8 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
[Test()] [Test()]
public void TestBug607990() public void TestBug607990()
{ {
Test<ExtractMethodAction>(@"class TestClass Test<ExtractMethodAction>(@"using System;
class TestClass
{ {
void TestMethod () void TestMethod ()
{ {
@ -193,7 +241,8 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
obj1.ToString();-> obj1.ToString();->
} }
} }
", @"class TestClass ", @"using System;
class TestClass
{ {
static void NewMethod () static void NewMethod ()
{ {
@ -212,7 +261,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
/// <summary> /// <summary>
/// Bug 616193 - Extract method passes param with does not exists any more in main method /// Bug 616193 - Extract method passes param with does not exists any more in main method
/// </summary> /// </summary>
[Ignore("FIXME!!")]
[Test()] [Test()]
public void TestBug616193() public void TestBug616193()
{ {
@ -248,7 +296,6 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
/// <summary> /// <summary>
/// Bug 616199 - Extract method forgets to return a local var which is used in main method /// Bug 616199 - Extract method forgets to return a local var which is used in main method
/// </summary> /// </summary>
[Ignore("FIXME!!")]
[Test()] [Test()]
public void TestBug616199() public void TestBug616199()
{ {
@ -269,7 +316,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
} }
void TestMethod () void TestMethod ()
{ {
string z = NewMethod (); var z = NewMethod ();
string ret = ""test1"" + z; string ret = ""test1"" + z;
} }
} }
@ -331,8 +378,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
"); ");
} }
[Ignore("Fix me!")]
[Ignore("FIXME!!")]
[Test()] [Test()]
public void ExtractMethodMultiVariableWithLocalReturnVariableTest() public void ExtractMethodMultiVariableWithLocalReturnVariableTest()
{ {
@ -352,7 +398,7 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
", @"class TestClass ", @"class TestClass
{ {
int member; int member;
void NewMethod (ref int j, int i, out int k, out int test) void NewMethod (int i, ref int j, out int k, out int test)
{ {
j = i + j; j = i + j;
k = j + member; k = j + member;

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

@ -105,9 +105,9 @@ namespace ICSharpCode.NRefactory.CSharp.CodeActions
foreach (var node in nodes) { foreach (var node in nodes) {
InsertBefore(entity, node); InsertBefore(entity, node);
} }
var t = new Task (() => {}); var tcs = new TaskCompletionSource<object> ();
t.RunSynchronously (); tcs.SetResult (null);
return t; return tcs.Task;
} }
public override Task InsertWithCursor (string operation, ITypeDefinition parentType, IEnumerable<AstNode> nodes) public override Task InsertWithCursor (string operation, ITypeDefinition parentType, IEnumerable<AstNode> nodes)
@ -121,9 +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 (() => {}); var tcs = new TaskCompletionSource<object> ();
t.RunSynchronously (); tcs.SetResult (null);
return t; return tcs.Task;
} }
void Rename (AstNode node, string newName) void Rename (AstNode node, string newName)

42
ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionBugTests.cs

@ -5241,7 +5241,7 @@ public class TestFoo
public void TestBug4961() public void TestBug4961()
{ {
CombinedProviderTest( CombinedProviderTest(
@"using System; @"using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace EnumerationProblem namespace EnumerationProblem
@ -5323,7 +5323,47 @@ $mc->$
}); });
} }
/// <summary>
/// Bug 6146 - No intellisense on value keyword in property set method
/// </summary>
[Test()]
public void TestBug6146()
{
CombinedProviderTest(
@"using System;
public class FooBar
{
public FooBar Foo {
set {
$value.$
}
}
}
", provider => {
Assert.IsNotNull(provider.Find("Foo"));
});
}
[Test()]
public void TestBug6146Case2()
{
CombinedProviderTest(
@"using System;
public class FooBar
{
public FooBar Foo {
set {
$value.Foo.F$
}
}
}
", provider => {
Assert.IsNotNull(provider.Find("Foo"));
});
}
} }

Loading…
Cancel
Save