/// <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()
 {
     AttributeSection att = new AttributeSection(null);
     CloneInto(att);
     att.Target = Target;
     return att;
 }
        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 AttributeSection()
        {
            AttributeSection inter = new AttributeSection(controller);
            inter.Target = "";

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
        public void Attributes()
        {
            AttributeSection attrs = new AttributeSection(controller);
            Attribute attr = new Attribute(controller);
            attr.PositionalArguments.Add("true");
            attr.Name = "Serializable";
            attrs.AddAttribute(attr);
            CodeRoot root = new CodeRoot(controller);
            root.AddChild(attrs);
            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, "[Serializable(true)]");
        }
        private bool IsTheSame(AttributeSection comparisonAttribute, ComparisonDepth depth)
        {
            if (comparisonAttribute == null)
                return false;

            if (Name == comparisonAttribute.Name && singleAttributes.Count == comparisonAttribute.singleAttributes.Count)
            {
                Comparers.BaseConstructComparer comparer = new Comparers.BaseConstructComparer();
                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(singleAttributes.ToArray(), comparisonAttribute.singleAttributes.ToArray(), comparer, depth))
                {
                    ComparisonDifference += GetType().Name + ".SingleAttributes";
                    return false;
                }

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

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

                if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(Attributes.ToArray(), comparisonAttribute.Attributes.ToArray()))
                {
                    ComparisonDifference += GetType().Name + ".Attributes";
                    return false;
                }

                return true;
            }
            return false;
        }
 private bool IsTheSame(AttributeSection comparisonAttribute)
 {
     return IsTheSame(comparisonAttribute, 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;
        }
        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));
        }
Example #9
0
 private AttributeSection GetAttributeSectionFromNode(ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.AttributeSection sec)
 {
     AttributeSection attrSec = new AttributeSection(controller);
     foreach (IAstNode node in sec.Attributes)
     {
         attrSec.AddAttribute(GetAttributeFromNode(node));
     }
     // Subtract 1 from start and add 1 to end to account for '[]'
     attrSec.TextRange = new TextRange(sec.StartOffset - 1, sec.EndOffset + 1);
     return attrSec;
 }
 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;
 }
 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);
        }
 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;
 }