Exemple #1
0
        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");
        }
Exemple #2
0
        public override ActionResult ApplyActionTo(StringBuilder sb)
        {
            int    startSearch = PropertyToAddTo.TextRange.StartOffset;
            string text        = sb.ToString();

            // Put the new Attribute just in front of the property declaration.
            int insertionPoint = text.LastIndexOf("\n", startSearch) + 1;

            AttributeSection section = new AttributeSection(AttributeToAdd.Controller);

            section.AddAttribute(AttributeToAdd);
            section.PreceedingBlankLines = -1;
            var indentLevel = InsertionHelpers.GetIndentationInFrontOf(text, startSearch);

            section.Controller.IndentLevel = indentLevel;

            string newText = Helper.StandardizeLineBreaks(section.ToString(), "\n") + "\n";

            // Calculate the Attribute's Text Range
            // The start index is the insertion point + the number of tabs in front of the attribute, +1 for the \n
            AttributeToAdd.TextRange.StartOffset = insertionPoint + indentLevel + 1;
            AttributeToAdd.TextRange.EndOffset   = AttributeToAdd.TextRange.StartOffset + (newText.Trim()).Length;

            sb.Insert(insertionPoint, newText);

            PropertyToAddTo.AttributeSections.Add(section);

            //return new ActionResult(insertionPoint, newText.Length, new[] { AttributeToAdd });
            return(new ActionResult(AttributeToAdd.TextRange.StartOffset, newText.Length, new[] { AttributeToAdd }));
        }
        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);
        }
Exemple #4
0
        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);
        }
        public override ActionResult ApplyActionTo(StringBuilder sb)
        {
            int startSearch = FieldToAddTo.TextRange.StartOffset;
            string text = sb.ToString();

            // Put the new Attribute just in front of the property declaration.
            int insertionPoint = text.LastIndexOf("\n", startSearch) + 1;

            AttributeSection section = new AttributeSection(AttributeToAdd.Controller);
            section.AddAttribute(AttributeToAdd);
            section.PreceedingBlankLines = -1;
            var indentLevel = InsertionHelpers.GetIndentationInFrontOf(text, startSearch);
            section.Controller.IndentLevel = indentLevel;

            string newText = Helper.StandardizeLineBreaks(section.ToString(), "\n") + "\n";

            // Calculate the Attribute's Text Range
            // The start index is the insertion point + the number of tabs in front of the attribute, +1 for the \n
            AttributeToAdd.TextRange.StartOffset = insertionPoint + indentLevel + 1;
            AttributeToAdd.TextRange.EndOffset = AttributeToAdd.TextRange.StartOffset + (newText.Trim()).Length;

            sb.Insert(insertionPoint, newText);

            FieldToAddTo.AttributeSections.Add(section);

            //return new ActionResult(insertionPoint, newText.Length, new[] { AttributeToAdd });
            return new ActionResult(AttributeToAdd.TextRange.StartOffset, newText.Length, new[] { AttributeToAdd });
        }
        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));
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        private bool MergeAttributes(BaseConstruct userBC, BaseConstruct newgenBC, BaseConstruct prevgenBC)
        {
            bool userChange = false, templateChange = false;

            if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(userBC._Attributes.ToArray(), prevgenBC._Attributes.ToArray()))
            {
                userChange = true;
            }
            if (!ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(newgenBC._Attributes.ToArray(), prevgenBC._Attributes.ToArray()))
            {
                templateChange = true;
            }

            if (ArchAngel.Providers.CodeProvider.CSharp.Utility.BaseContructCollectionsAreTheSame(newgenBC._Attributes.ToArray(), userBC._Attributes.ToArray()))
            {
                userChange     = true;
                templateChange = false;
            }

            if (templateChange && userChange)
            {
                return(false);
            }

            _Attributes.Clear();
            _AttributeSections.Clear();
            if (userChange)
            {
                foreach (Attribute attr in userBC._Attributes)
                {
                    Attribute clone = (Attribute)attr.Clone();

                    AttributeSection parentSec = new AttributeSection(controller);
                    parentSec.Target = ((AttributeSection)attr.ParentObject).Target;
                    parentSec.AddAttribute(clone);
                    AddAttributeSection(parentSec);
                }
            }
            else if (templateChange)
            {
                foreach (Attribute attr in newgenBC._Attributes)
                {
                    Attribute clone = (Attribute)attr.Clone();

                    AttributeSection parentSec = new AttributeSection(controller);
                    parentSec.Target = ((AttributeSection)attr.ParentObject).Target;
                    parentSec.AddAttribute(clone);
                    AddAttributeSection(parentSec);
                }
            }
            return(true);
        }
Exemple #9
0
        protected void CloneInto(BaseConstruct newBaseConstruct)
        {
            newBaseConstruct.Name     = Name;
            newBaseConstruct.Omit     = Omit;
            newBaseConstruct.Comments = Comments.Clone();

            //newBaseConstruct.Attributes.Clear();
            //foreach(AttributeSection att in Attributes)
            //{
            //    AttributeSection att1 = (AttributeSection)att.Clone();
            //    att1.ParentObject = newBaseConstruct;
            //    newBaseConstruct.Attributes.Add(att1);
            //}

            newBaseConstruct.emptyPlaceholders.Clear();
            foreach (EmptyPlaceholder eph in emptyPlaceholders)
            {
                EmptyPlaceholder clone = (EmptyPlaceholder)eph.Clone();
                clone.ParentObject = newBaseConstruct;
                newBaseConstruct.emptyPlaceholders.Add(clone);
            }
            newBaseConstruct._Attributes.Clear();
            foreach (Attribute attr in _Attributes)
            {
                Attribute clone = (Attribute)attr.Clone();

                AttributeSection parentSec = new AttributeSection(null);
                parentSec.Target = ((AttributeSection)attr.ParentObject).Target;
                parentSec.AddAttribute(clone);
                newBaseConstruct.AddAttributeSection(parentSec);
            }

            newBaseConstruct.Index                = Index;
            newBaseConstruct.InputLength          = InputLength;
            newBaseConstruct.InputStartPos        = InputStartPos;
            newBaseConstruct.Language             = Language;
            newBaseConstruct.NumberOfLines        = NumberOfLines;
            newBaseConstruct.OutputOffset         = OutputOffset;
            newBaseConstruct.PreceedingBlankLines = PreceedingBlankLines;
            newBaseConstruct.XmlComments.Clear();
            foreach (string xml in XmlComments)
            {
                newBaseConstruct.XmlComments.Add(xml);
            }
        }
Exemple #10
0
        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");
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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)]");
        }
Exemple #13
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);
        }