Browse Source

Fix NullReferenceException in MoveToOuterScopeAction.FindCurrentScopeEntryNode

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
0cf742a339
  1. 9
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs
  2. 13
      src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs

9
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Refactoring/CodeActions/MoveToOuterScopeAction.cs

@ -129,11 +129,6 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -129,11 +129,6 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
return newVariableDeclarationStatement;
}
List<Type> scopeContainers = new List<Type>() {
typeof (MethodDeclaration),
typeof (Accessor)
};
AstNode FindCurrentScopeEntryNode(Statement startNode)
{
// Start one node up in the tree, otherwise we may stop at the BlockStatement
@ -143,9 +138,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring @@ -143,9 +138,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
do {
lastNode = currentNode;
currentNode = currentNode.Parent;
if (scopeContainers.Contains(currentNode.GetType()))
if (currentNode == null)
return null;
} while (currentNode.GetType() != typeof(BlockStatement));
} while (!(currentNode is BlockStatement));
return lastNode;
}
#endregion

13
src/Libraries/NRefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeActions/MoveToOuterScopeTests.cs

@ -136,6 +136,19 @@ class A @@ -136,6 +136,19 @@ class A
});
");
}
[Test]
public void IgnoresDeclarationDirectlyInConstructorBody()
{
TestWrongContext<MoveToOuterScopeAction>(@"
class A
{
public A()
{
int $i = 2;
}
}");
}
}
}

Loading…
Cancel
Save