Browse Source

Fixed bug in RemoveBackingStore context action.

newNRvisualizers
Mike Krüger 14 years ago
parent
commit
d88c793032
  1. 3
      ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs
  2. 8
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ContextActionTestBase.cs
  3. 43
      ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBackingStoreTests.cs

3
ICSharpCode.NRefactory.CSharp/Refactoring/ContextAction/RemoveBackingStore.cs

@ -99,7 +99,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -99,7 +99,8 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
if (propertyDeclaration.Getter.Body.Statements.Count != 1)
return null;
var returnStatement = propertyDeclaration.Getter.Body.Statements.First () as ReturnStatement;
if (returnStatement == null)
return null;
var result = context.Resolve (returnStatement.Expression);
if (result == null || !(result is MemberResolveResult))
return null;

8
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/ContextActionTestBase.cs

@ -44,5 +44,13 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -44,5 +44,13 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
return context.doc.Text;
}
protected static void TestWrongContext (IContextAction action, string input)
{
var context = new TestRefactoringContext (input);
if (!action.IsValid (context))
Console.WriteLine ("invalid node is:" + context.GetNode ());
Assert.IsTrue (!action.IsValid (context), action.GetType () + " shouldn't be valid there.");
}
}
}

43
ICSharpCode.NRefactory.Tests/CSharp/ContextAction/RemoveBackingStoreTests.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -33,7 +33,7 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
public class RemoveBackingStoreTests : ContextActionTestBase
{
[Test()]
public void Test ()
public void TestSimpleStore ()
{
string result = RunContextAction (
new RemoveBackingStore (),
@ -57,6 +57,47 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions @@ -57,6 +57,47 @@ namespace ICSharpCode.NRefactory.CSharp.ContextActions
" }" + Environment.NewLine +
"}", result);
}
/// <summary>
/// Bug 3292 -Error in analysis service
/// </summary>
[Test()]
public void TestBug3292 ()
{
TestWrongContext (
new RemoveBackingStore (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int $Field {" + Environment.NewLine +
" get { " +
" Console.WriteLine(field);" +
" }" + Environment.NewLine +
" set { field = value; }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
}
[Test()]
public void TestBug3292Case2 ()
{
TestWrongContext (
new RemoveBackingStore (),
"class TestClass" + Environment.NewLine +
"{" + Environment.NewLine +
" int field;" + Environment.NewLine +
" public int $Field {" + Environment.NewLine +
" get { " +
" return field;" +
" }" + Environment.NewLine +
" set { Console.WriteLine(field); }" + Environment.NewLine +
" }" + Environment.NewLine +
"}"
);
}
}
}

Loading…
Cancel
Save