Ejemplo n.º 1
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.");
        }
		void VisitNewDeclarationSpace(AstNode node)
		{
			var oldDeclarationSpace = currentDeclarationSpace;
			currentDeclarationSpace = new LocalDeclarationSpace();
			if (oldDeclarationSpace != null)
				oldDeclarationSpace.AddChildSpace(currentDeclarationSpace);

			VisitChildren(node);

			nodeDeclarationSpaces.Add(node, currentDeclarationSpace);
			currentDeclarationSpace = oldDeclarationSpace;
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a child declaration space.
        /// </summary>
        /// <param name="child">The <see cref="LocalDeclarationSpace"/> to add.</param>
        public void AddChildSpace(LocalDeclarationSpace child)
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }
            if (Children.Contains(child))
            {
                throw new InvalidOperationException("the child was already added");
            }

            Children.Add(child);
            child.Parent = this;
        }
        private void VisitNewDeclarationSpace(AstNode node)
        {
            var oldDeclarationSpace = currentDeclarationSpace;

            currentDeclarationSpace = new LocalDeclarationSpace();
            if (oldDeclarationSpace != null)
            {
                oldDeclarationSpace.AddChildSpace(currentDeclarationSpace);
            }

            VisitChildren(node);

            nodeDeclarationSpaces.Add(node, currentDeclarationSpace);
            currentDeclarationSpace = oldDeclarationSpace;
        }
Ejemplo n.º 5
0
        public void GetNameDeclarationsInChildSpace()
        {
            var child2 = new LocalDeclarationSpace();

            parent.AddChildSpace(child);
            parent.AddChildSpace(child2);

            var node1 = new IdentifierExpression();

            child.AddDeclaration("blah", node1);

            var node2 = new IdentifierExpression();

            child.AddDeclaration("blah", node2);

            var declarations = parent.GetNameDeclarations("blah").ToList();

            Assert.NotNull(declarations, "declarations");
            Assert.AreEqual(2, declarations.Count, "Wrong declaration count");
            Assert.That(declarations.Contains(node1), "node1 was not one of the declarations");
            Assert.That(declarations.Contains(node2), "node2 was not one of the declarations");
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Adds a child declaration space.
		/// </summary>
		/// <param name="child">The <see cref="LocalDeclarationSpace"/> to add.</param>
		public void AddChildSpace(LocalDeclarationSpace child)
		{
			if (child == null)
				throw new ArgumentNullException("child");
			if (Children.Contains(child))
				throw new InvalidOperationException("the child was already added");

			Children.Add(child);
			child.Parent = this;
		}
Ejemplo n.º 7
0
 public void SetUp()
 {
     parent = new LocalDeclarationSpace();
     child  = new LocalDeclarationSpace();
 }
		public void SetUp()
		{
			parent = new LocalDeclarationSpace();
			child = new LocalDeclarationSpace();
		}
		public void GetNameDeclarationsInChildSpace()
		{
			var child2 = new LocalDeclarationSpace();
			parent.AddChildSpace(child);
			parent.AddChildSpace(child2);

			var node1 = new IdentifierExpression();
			child.AddDeclaration("blah", node1);

			var node2 = new IdentifierExpression();
			child.AddDeclaration("blah", node2);

			var declarations = parent.GetNameDeclarations("blah").ToList();
			Assert.NotNull(declarations, "declarations");
			Assert.AreEqual(2, declarations.Count, "Wrong declaration count");
			Assert.That(declarations.Contains(node1), "node1 was not one of the declarations");
			Assert.That(declarations.Contains(node2), "node2 was not one of the declarations");
		}
		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.");
		}