public void ApplyTo(Actions actions)
        {
            foreach (var attr in attributes)
            {
                var attribute = attr.Build(_class.Controller);

                if (attribute == null)
                {
                    continue;
                }

                if (_class.HasAttributeNamed(attribute.Name) || attributesToDelete.Contains(attribute.Name))
                {
                    continue;
                }

                actions.AddAction(new AddAttributeToClassAction(_class, attribute));
            }
            foreach (var attr in attributesToDelete)
            {
                if (_class.HasAttributeNamed(attr))
                {
                    ArchAngel.Providers.CodeProvider.DotNet.Attribute att = _class.Attributes.Find(a => a.Name == attr);
                    actions.AddAction(new RemoveAttributeFromClassAction(att));
                }
            }
        }
예제 #2
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");
        }
예제 #3
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 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");
        }
예제 #5
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);
        }
        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)]");
        }
        public void Attribute_Added_Positional_Attribute()
        {
            const string positionalAttrName = "MyPositionalAttrName1";
            const string attrName = "MyAttributeName1";
            string expectedResult = String.Format("{0}({1})", attrName, positionalAttrName);
            Attribute merged1 = new Attribute(controller);
            Attribute merged2 = new Attribute(controller);
            Attribute merged3 = new Attribute(controller);

            Attribute changing = new Attribute(controller);
            changing.Name = attrName;
            changing.PositionalArguments.Add(positionalAttrName);

            Attribute unchanging = new Attribute(controller);
            unchanging.Name = attrName;

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
예제 #8
0
 private int Compare(Attribute attributeX, Attribute attributeY)
 {
     if (attributeX == null && attributeY == null)
     {
         return(0);
     }
     else if (attributeX == null && attributeY != null)
     {
         return((this._direction == SortDirection.Ascending) ? -1 : 1);
     }
     else if (attributeX != null && attributeY == null)
     {
         return((this._direction == SortDirection.Ascending) ? 1 : -1);
     }
     else
     {
         return((this._direction == SortDirection.Ascending) ? attributeX.Name.CompareTo(attributeY.Name) : attributeY.Name.CompareTo(attributeX.Name));
     }
 }
        public void Attribute_Added_Named_Attribute()
        {
            const string attributeName = "MyNamedAttribute1";
            const string attributeValue = "MyNamedAttributeValue1";
            const string attrName = "MyAttributeName1";
            string expectedResult = String.Format("{0}({1} = {2})",attrName,attributeName,attributeValue);
            Attribute merged1 = new Attribute(controller);
            Attribute merged2 = new Attribute(controller);
            Attribute merged3 = new Attribute(controller);

            Attribute changing = new Attribute(controller);
            changing.Name = attrName;
            changing.NamedArguments.Add(new Attribute.NamedArgument(attributeName, attributeValue));

            Attribute unchanging = new Attribute(controller);
            unchanging.Name = attrName;

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
예제 #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");
        }
예제 #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);
        }
예제 #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)]");
        }
예제 #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);
        }
예제 #14
0
        private Attribute GetAttributeFromNode(IAstNode node)
        {
            Attribute attr = new Attribute(controller);

            //DotNet.Ast.Attribute
            ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.Attribute attrNode = node as ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.Attribute;
            if (attrNode == null)
                throw new ArgumentException("node is not an Attribute");

            string attrName = "";
            if (string.IsNullOrEmpty(attrNode.Target) == false)
            {
                // Add the target onto the attribute name.
                attrName = attrNode.Target + ":";
            }
            attrName += FormatterUtility.GetDataTypeFromTypeReference(attrNode.AttributeType, document, controller).ToString();
            attr.Name = attrName;

            foreach (IAstNode child in attrNode.Arguments)
            {
                //DotNet.Ast.AttributeArgument
                AttributeArgument argument = (AttributeArgument)child;
                string argumentValue = document.GetSubstring(argument.Expression.TextRange);
                if (string.IsNullOrEmpty(argument.Name))
                {
                    attr.PositionalArguments.Add(argumentValue);
                }
                else
                {
                    attr.NamedArguments.Add(new Attribute.NamedArgument(argument.Name, argumentValue));
                }
            }
            // Subtract 1 from start and add 1 to end to account for '[]'
            attr.TextRange = new TextRange(node.StartOffset - 1, node.EndOffset + 1);
            return attr;
        }
 public AddAttributeToClassAction(Class classToAddTo, Attribute attributeToAdd)
 {
     ClassToAddTo = classToAddTo;
     AttributeToAdd = attributeToAdd;
 }
 public AddAttributeToMethodAction(Function methodToAddTo, Attribute attributeToAdd)
 {
     MethodToAddTo = methodToAddTo;
     AttributeToAdd = attributeToAdd;
 }
 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;
 }
예제 #18
0
 public VBAttributePrinter(Attribute obj)
 {
     this.obj = obj;
 }
        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 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");
        }
 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 AddAttributeToMethodAction(Function methodToAddTo, Attribute attributeToAdd)
 {
     MethodToAddTo  = methodToAddTo;
     AttributeToAdd = attributeToAdd;
 }
 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 VBAttributePrinter(Attribute obj)
 {
     this.obj = obj;
 }
예제 #25
0
 public AddAttributeToFieldAction(Field fieldToAddTo, Attribute attributeToAdd)
 {
     FieldToAddTo   = fieldToAddTo;
     AttributeToAdd = attributeToAdd;
 }
예제 #26
0
 public void AddAttribute(Attribute attr)
 {
     singleAttributes.Add(attr);
     attr.ParentObject = this;
 }
 public AddAttributeToFieldAction(Field fieldToAddTo, Attribute attributeToAdd)
 {
     FieldToAddTo = fieldToAddTo;
     AttributeToAdd = attributeToAdd;
 }
예제 #28
0
 public AddAttributeToPropertyAction(Property propertyToAddTo, Attribute attributeToAdd)
 {
     PropertyToAddTo = propertyToAddTo;
     AttributeToAdd  = attributeToAdd;
 }
예제 #29
0
 public AddAttributeToClassAction(Class classToAddTo, Attribute attributeToAdd)
 {
     ClassToAddTo   = classToAddTo;
     AttributeToAdd = attributeToAdd;
 }
예제 #30
0
 public void AddAttribute(Attribute attr)
 {
     singleAttributes.Add(attr);
     attr.ParentObject = this;
 }
 public AddAttributeToPropertyAction(Property propertyToAddTo, Attribute attributeToAdd)
 {
     PropertyToAddTo = propertyToAddTo;
     AttributeToAdd = attributeToAdd;
 }