private void AddDeclaration(string name, AstNode node)
 {
     if (currentDeclarationSpace != null)
     {
         currentDeclarationSpace.AddDeclaration(name, node);
     }
 }
Exemple #2
0
        public void IsNameTakenMultipleChildSpaces()
        {
            parent.AddChildSpace(child);
            var child2 = new LocalDeclarationSpace();

            parent.AddChildSpace(child2);

            var input   = @"
class Foo
{
	void Bar()
	{
		{
			int $i;
		}
	}
}";
            var context = TestRefactoringContext.Create(input);

            child2.AddDeclaration("i", context.GetNode <VariableInitializer>());

            Assert.That(parent.IsNameUsed("i"), "The declaration was not added to parent correctly.");
            Assert.That(!child.IsNameUsed("i"), "child contained the declaration, event though it shouldn't.");
            Assert.That(child2.IsNameUsed("i"), "child2 did not contain the declaration, event though it should have.");

            Assert.That(!parent.IsNameUsed("j"), "parent contained a non-existent declaration.");
            Assert.That(!child.IsNameUsed("j"), "parent contained a non-existent declaration.");
            Assert.That(!child2.IsNameUsed("j"), "parent contained a non-existent declaration.");
        }
Exemple #3
0
        public void ContainsNameSimpleVariableDeclaration()
        {
            parent.AddChildSpace(child);

            var input   = @"
class Foo
{
	void Bar()
	{
		int $i;
	}
}";
            var context = TestRefactoringContext.Create(input);

            child.AddDeclaration("i", context.GetNode <VariableInitializer>());

            Assert.That(child.ContainsName("i", false), "The declaration was not added to child correctly.");
            Assert.That(!parent.ContainsName("i", false), "parent incorrectly contained the declaration.");
            Assert.That(parent.ContainsName("i", true), "parent did not contain the declaration, event though it should have.");
        }
		public void IsNameTakenMultipleChildSpaces()
		{
			parent.AddChildSpace(child);
			var child2 = new LocalDeclarationSpace();
			parent.AddChildSpace(child2);

			var input = @"
class Foo
{
	void Bar()
	{
		{
			int $i;
		}
	}
}";
			var context = TestRefactoringContext.Create(input);
			child2.AddDeclaration("i", context.GetNode<VariableInitializer>());

			Assert.That(parent.IsNameUsed("i"), "The declaration was not added to parent correctly.");
			Assert.That(!child.IsNameUsed("i"), "child contained the declaration, event though it shouldn't.");
			Assert.That(child2.IsNameUsed("i"), "child2 did not contain the declaration, event though it should have.");

			Assert.That(!parent.IsNameUsed("j"), "parent contained a non-existent declaration.");
			Assert.That(!child.IsNameUsed("j"), "parent contained a non-existent declaration.");
			Assert.That(!child2.IsNameUsed("j"), "parent contained a non-existent declaration.");
		}