public void Class()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
 public void SetUp()
 {
     var controller = new CSharpController();
     codeRoot = new CodeRoot(controller);
     var ns = new Namespace(controller, "Namespace1") { Index = 0 };
     codeRoot.AddChild(ns);
     ns.AddChild(new Class(controller, "Class1") { Index = 1 });
 }
Esempio n. 3
0
 public Namespace(Namespace nsToCopyFrom)
     : base(null)
 {
     PreceedingBlankLines = -1;
     nsToCopyFrom.CloneInto(this);
     //foreach(UsingStatement us in nsToCopyFrom.UsingStatements)
     //{
     //    UsingStatements.Add((UsingStatement)us.Clone());
     //}
 }
        public void They_Should_Not_Show_In_The_Object_Heirarchy()
        {
            Namespace ns = new Namespace(controller) { Index = 1};
            Region region = new Region(controller, "RegionStart") { Index = 2};
            Class clazz = new Class(controller, "Class1") { Index = 3};

            region.AddChild(clazz);
            ns.AddChild(region);

            Assert.That(clazz.Parent, Is.SameAs(ns), "The parent of the Class should be the Namespace, not the Region");
        }
        public void Class()
        {
            Class cl = new Class(controller, "Class1");
            Assert.That(cl.FullyQualifiedDisplayName, Is.EqualTo("Class1"));

            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(cl);

            Assert.That(cl.FullyQualifiedDisplayName, Is.EqualTo("ns1.Class1"));
        }
        protected CodeRoot CreateBasicRoot()
        {
            Class cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);

            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            return root;
        }
        public void They_Should_Not_Show_In_The_Fully_Qualified_Display_Name()
        {
            Namespace ns = new Namespace(controller);
            Region region = new Region(controller, "RegionStart");
            Class clazz = new Class(controller, "Class1");

            region.AddChild(clazz);
            ns.AddChild(region);

            Assert.That(clazz.FullyQualifiedDisplayName.IndexOf("RegionStart") < 0,
                "The fully qualified display name of the Class should not contain the region name");
        }
        public void InterfaceMethod()
        {
            Interface it = new Interface(controller, "Interface1");
            InterfaceMethod item = new InterfaceMethod(controller, "Function1", new DataType(controller, "int"));
            item.Parameters.Add(new Parameter(controller, "float", "f"));
            item.Parameters.Add(new Parameter(controller, "InputObject", "j"));
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Function1 (float, InputObject)"));

            it.AddChild(item);
            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(it);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Function1 (float, InputObject)"));
        }
        public void InterfaceProperty()
        {
            Interface it = new Interface(controller, "Interface1");
            InterfaceProperty item = new InterfaceProperty(controller, "Property1", new DataType(controller, "int"));
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Property1"));

            it.AddChild(item);
            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(it);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Property1"));
        }
 protected CodeRoot CreateNamespaceAndInterface(IBaseConstruct inter)
 {
     Interface interface1 = new Interface(controller, "Interface1");
     interface1.Modifiers.Add("public");
     interface1.AddChild(inter);
     AttributeSection attrs = new AttributeSection(controller);
     Attribute attr = new Attribute(controller);
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     interface1.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(interface1);
     CodeRoot root = new CodeRoot(controller);
     root.AddChild(ns);
     return root;
 }
Esempio n. 11
0
 private bool IsTheSame(Namespace comparisonNamespace)
 {
     return IsTheSame(comparisonNamespace, ComparisonDepth.Signature);
 }
        private CodeRoot GetPrevGenOrNewGenRoot()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);

            // Create another class to match to the user one.
            Class c3 = new Class(controller, "Class3");

            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c3);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            return root;
        }
        private CodeRootMap CreateBasicMap(out Class cl2)
        {
            CodeRootMap map = new CodeRootMap();

            Class cl = new Class(controller, "Class1");
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            cl2 = new Class(controller, "Class2");
            ns.AddChild(cl2);
            root = new CodeRoot(controller);
            root.AddChild(ns);
            map.AddCodeRoot(root, Version.NewGen);
            return map;
        }
        public void Interface()
        {
            Interface item = new Interface(controller, "Interface1");
            Assert.That(item.FullyQualifiedIdentifer, Is.EqualTo("Interface1"));

            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(item);

            Assert.That(item.FullyQualifiedIdentifer, Is.EqualTo("ns1|Interface1"));
        }
        public void Matching_Successful()
        {
            controller.Reorder = true;
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class c2 = new Class(controller, "Class2"); // Extra class in user
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.PrevGen);

            root = GetPrevGenOrNewGenRoot();
            map.AddCodeRoot(root, Version.NewGen);

            bool matchResult = map.MatchConstructs("ArchAngel.Tests|Class2", "ArchAngel.Tests|Class3", "ArchAngel.Tests|Class3");

            Assert.That(matchResult, Is.True);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "Class2");
            Assertions.StringContains(result, "Class3", 0);
            int count = 0;
            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(c2))
                    count++;
            }
            Assert.That(count, Is.EqualTo(1));
        }
 protected CodeRoot CreateClassAndNamespace(IEnumerable<IBaseConstruct> children)
 {
     Class cl = new Class(controller, "Class1");
     foreach(IBaseConstruct child in children)
         cl.AddChild(child);
     cl.Index = 10;
     AttributeSection attrs = new AttributeSection(controller);
     attrs.Index = 5;
     Attribute attr = new Attribute(controller);
     attr.Index = 6;
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     cl.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Index = 0;
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(cl);
     CodeRoot userRoot = new CodeRoot(controller);
     userRoot.AddChild(ns);
     return userRoot;
 }
Esempio n. 17
0
        private void Process_Namespace_Declaration(NamespaceDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");
            Namespace ns = new Namespace(controller);
            ns.Name = node.Name.Text;

            SetupBaseConstruct(node.StartOffset, node.EndOffset, "", ns, null);
        }
 protected CodeRoot ConstructRootWithClass(IBaseConstruct childOfClass)
 {
     Class cl = new Class(controller, "Class1");
     cl.AddChild(childOfClass);
     AttributeSection attrs = new AttributeSection(controller);
     Attribute attr = new Attribute(controller);
     attr.PositionalArguments.Add("true");
     attr.Name = "Serializable";
     attrs.AddAttribute(attr);
     cl.AddAttributeSection(attrs);
     Namespace ns = new Namespace(controller);
     ns.Name = "ArchAngel.Tests";
     ns.AddChild(cl);
     CodeRoot root = new CodeRoot(controller);
     root.AddChild(ns);
     return root;
 }
        public void User_Is_Missing_Others_Are_Exact_Copy()
        {
            Function func = new Function(controller);
            func.Name = "Method1";
            func.Modifiers.Add("public");
            func.ReturnType = new DataType(controller, "void");
            func.BodyText = "{ }";

            Class cl = new Class(controller, "Class1");
            cl.AddChild(func);
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);
            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.PrevGen);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "public void Method1()");
            Assertions.StringContains(result, "{ }");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }
        public void PrevGen_Is_Skipped_Where_No_Template_Or_User_Exist()
        {
            Class cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            Class c2 = new Class(controller, "Class2"); // Extra class in prevgen
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            Namespace ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            ns.AddChild(c2);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            cl.IsPartial = true;
            cl.GenericTypes.Add("T");
            attrs = new AttributeSection(controller);
            attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            cl.AddAttributeSection(attrs);
            ns = new Namespace(controller);
            ns.Name = "ArchAngel.Tests";
            ns.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns);

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            // make sure that the deleted class Class2 was not included int he merged code root.
            Assertions.StringContains(result, "Class2", 0);
        }
        public void Namespace()
        {
            Namespace item = new Namespace(controller, "Namespace1");
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Namespace1"));

            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(item);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("ns1.Namespace1"));
        }
Esempio n. 22
0
        private bool IsTheSame(Namespace comparisonNamespace, ComparisonDepth depth)
        {
            if (comparisonNamespace == null)
                return false;

            if (Name == comparisonNamespace.Name)
            {
                if (depth == ComparisonDepth.Signature)
                {
                    return true;
                }

                if (!base.IsTheSame(comparisonNamespace, depth))
                {
                    return false;
                }

                if (depth == ComparisonDepth.Outer)
                {
                    return true;
                }

                if (!Utility.CollectionsAreTheSame(UsingStatements, comparisonNamespace.UsingStatements, new Comparers.UsingStatementComparer()))
                {
                    ComparisonDifference += GetType().Name + ".UsingStatements";
                    return false;
                }

                Comparers.BaseConstructComparer comparer = new Comparers.BaseConstructComparer();

                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Classes.ToArray(), comparisonNamespace.Classes.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Classes";
                    return false;
                }
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Structs.ToArray(), comparisonNamespace.Structs.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Structs";
                    return false;
                }
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Interfaces.ToArray(), comparisonNamespace.Interfaces.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Interfaces";
                    return false;
                }
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Enums.ToArray(), comparisonNamespace.Enums.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Enums";
                    return false;
                }
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Delegates.ToArray(), comparisonNamespace.Delegates.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Delegates";
                    return false;
                }
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(InnerNamespaces.ToArray(), comparisonNamespace.InnerNamespaces.ToArray(), comparer))
                {
                    ComparisonDifference += GetType().Name + ".Namespaces";
                    return false;
                }
                return true;
            }
            return false;
        }
        public void Struct()
        {
            Struct cl = new Struct(controller, "Struct1");
            Assert.That(cl.FullyQualifiedDisplayName, Is.EqualTo("Struct1"));

            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(cl);

            Assert.That(cl.FullyQualifiedDisplayName, Is.EqualTo("ns1.Struct1"));
        }
        public void InterfaceAccessor()
        {
            InterfaceProperty itp = new InterfaceProperty(controller, "Property1", new DataType(controller, "int"));
            InterfaceAccessor item1 = new InterfaceAccessor(controller, ArchAngel.Providers.CodeProvider.DotNet.InterfaceAccessor.AccessorTypes.Get, "");
            InterfaceAccessor item2 = new InterfaceAccessor(controller, ArchAngel.Providers.CodeProvider.DotNet.InterfaceAccessor.AccessorTypes.Set, "");

            itp.AddChild(item1);
            itp.AddChild(item2);

            Assert.That(item1.FullyQualifiedDisplayName, Is.EqualTo("Property1.Get Accessor"));
            Assert.That(item2.FullyQualifiedDisplayName, Is.EqualTo("Property1.Set Accessor"));

            Interface it = new Interface(controller, "Interface1");
            it.AddChild(itp);
            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(it);

            Assert.That(item1.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Property1.Get Accessor"));
            Assert.That(item2.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Property1.Set Accessor"));
        }
Esempio n. 25
0
 /// <summary>
 /// Returns a shallow copy of the construct. Does not copy children.
 /// </summary>
 /// <returns>A shallow copy of the construct. Does not copy children.</returns>
 public override IBaseConstruct Clone()
 {
     Namespace ns = new Namespace(this);
     foreach (UsingStatement us in UsingStatements)
     {
         ns.AddChild(us.Clone());
     }
     return ns;
 }
        public void InterfaceEvent()
        {
            Interface it = new Interface(controller, "Interface1");
            InterfaceEvent item = new InterfaceEvent(controller, "Event1", new DataType(controller, "Delegate1"), false);
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Event1"));

            it.AddChild(item);
            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(it);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Event1"));
        }
        public void Matching_Successful()
        {
            CodeRootMap map = new CodeRootMap();

            Class cl = new Class(controller, "Class1");
            Namespace ns1 = new Namespace(controller);
            ns1.Name = "ArchAngel.Tests";
            ns1.AddChild(cl);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(ns1);
            map.AddCodeRoot(root, Version.User);

            cl = new Class(controller, "Class1");
            Namespace ns2 = new Namespace(controller);
            ns2.Name = "Slyce.Tests";
            ns2.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns2);
            map.AddCodeRoot(root, Version.PrevGen);

            cl = new Class(controller, "Class1");
            Namespace ns3 = new Namespace(controller);
            ns3.Name = "Slyce.Tests";
            ns3.AddChild(cl);
            root = new CodeRoot(controller);
            root.AddChild(ns3);
            map.AddCodeRoot(root, Version.NewGen);

            map.MatchConstructs(map, ns1, ns3, ns2);

            foreach (CodeRootMapNode child in map.AllNodes)
            {
                Assert.That(child.PrevGenObj, Is.Not.Null,
                            string.Format("PrevGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.NewGenObj, Is.Not.Null,
                            string.Format("NewGen in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
                Assert.That(child.UserObj, Is.Not.Null,
                            string.Format("User in {0} is null", child.GetFirstValidBaseConstruct().ShortName));
            }

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(map.Diff(), Is.EqualTo(TypeOfDiff.UserChangeOnly));
            Assertions.StringContains(result, "class Class1", 1);
            Assertions.StringContains(result, "namespace ArchAngel.Tests", 1);
            Assertions.StringContains(result, "namespace Slyce.Tests", 0);

            int count = 0;
            foreach (CodeRootMapNode node in map.AllNodes)
            {
                if (node.IsTheSameReference(ns1))
                    count++;
            }
            Assert.That(count, Is.EqualTo(1));
        }
        public void InterfaceIndexer()
        {
            Interface it = new Interface(controller, "Interface1");
            InterfaceIndexer item = new InterfaceIndexer(controller, new DataType(controller, "int"), false);
            item.Parameters.Add(new Parameter(controller, "float", "f"));
            item.Parameters.Add(new Parameter(controller, "InputObject", "j"));
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Indexer [float, InputObject]"));

            it.AddChild(item);
            Namespace ns = new Namespace(controller);
            ns.Name = "ns1";
            ns.AddChild(it);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("ns1.Interface1.Indexer [float, InputObject]"));
        }
        public void Namespace()
        {
            Namespace inter = new Namespace(controller);
            inter.Name = "File";
            inter.AddChild(new Class(controller, "Class1"));

            Namespace clone = (Namespace)inter.Clone();
            clone.Controller = new CSharpController();

            Assert.That(inter.IsTheSame(clone, ComparisonDepth.Outer), Is.True);
            Assert.That(clone.WalkChildren(), Has.Count(0));
            Assert.That(inter.IsTheSame(clone, ComparisonDepth.Complete), Is.False);
        }
        public void Namespace()
        {
            Namespace inter = new Namespace(controller);
            inter.Name = "ArchAngel.Tests";
            inter.AddChild(new UsingStatement(controller, "", "System"));
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(inter);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "using System");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
        }