Exemplo n.º 1
0
        public void GetAttributeModifierTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name            = "TestField";
            fieldElement.Access          = CodeAccess.Protected;
            fieldElement.Type            = "int";
            fieldElement.MemberModifiers = MemberModifiers.Static;

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, fieldElement);

            Assert.AreEqual("Static", attribute, "Unexpected attribute.");

            TypeElement typeElement = new TypeElement();

            typeElement.TypeModifiers = TypeModifiers.Sealed;

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, typeElement);
            Assert.AreEqual("Sealed", attribute, "Unexpected attribute.");

            UsingElement usingElement = new UsingElement();

            usingElement.Name = "System";

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Modifier, usingElement);
            Assert.AreEqual(string.Empty, attribute, "Unexpected attribute.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the expression value.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <param name="element">The element.</param>
        /// <returns>The expression value as text.</returns>
        private static string GetExpressionValue(IConditionExpression expression, ICodeElement element)
        {
            string value = string.Empty;

            if (expression != null && element != null)
            {
                StringExpression stringExpression = expression as StringExpression;
                if (stringExpression != null)
                {
                    value = stringExpression.Text;
                }
                else
                {
                    ElementAttributeExpression attributeExpression = expression as ElementAttributeExpression;

                    if (attributeExpression.Scope == ElementAttributeScope.Parent)
                    {
                        element = element.Parent;
                    }

                    if (attributeExpression != null)
                    {
                        value = ElementUtilities.GetAttribute(attributeExpression.ElementAttribute, element);
                    }
                }
            }

            return(value);
        }
Exemplo n.º 3
0
        public void GetAttributeNoneTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name = "TestField";

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.None, fieldElement);

            Assert.AreEqual(string.Empty, attribute, "Unexpected attribute.");
        }
Exemplo n.º 4
0
        public void GetAttributeAccessTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name   = "TestField";
            fieldElement.Access = CodeAccess.Protected;

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Access, fieldElement);

            Assert.AreEqual("Protected", attribute, "Unexpected attribute.");
        }
Exemplo n.º 5
0
        public void GetAttributeAttributesTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name = "TestField";

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);

            Assert.AreEqual(string.Empty, attribute, "Unexpected attribute.");

            //
            // Add some attributes to the element.
            //
            AttributeElement attribute1 = new AttributeElement();

            attribute1.Name     = "Attribute1";
            attribute1.BodyText = "false";

            AttributeElement attribute2 = new AttributeElement();

            attribute2.Name     = "Attribute2";
            attribute2.BodyText = "false";

            fieldElement.AddAttribute(attribute1);
            fieldElement.AddAttribute(attribute2);

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);
            Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute.");

            //
            // Add nested attributes to the element.
            //
            fieldElement.ClearAttributes();
            attribute1          = new AttributeElement();
            attribute1.Name     = "Attribute1";
            attribute1.BodyText = "false";

            attribute2          = new AttributeElement();
            attribute2.Name     = "Attribute2";
            attribute2.BodyText = "false";
            attribute1.AddChild(attribute2);

            fieldElement.AddAttribute(attribute1);

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Attributes, fieldElement);
            Assert.AreEqual("Attribute1, Attribute2", attribute, "Unexpected attribute.");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the name of the group the element falls into.
        /// </summary>
        /// <param name="elementFilterType">Type of the element filter.</param>
        /// <param name="codeElement">The code element.</param>
        /// <returns>The group name.</returns>
        private string GetGroupName(ElementAttributeType elementFilterType, ICodeElement codeElement)
        {
            string groupName = string.Empty;

            string attribute = ElementUtilities.GetAttribute(elementFilterType, codeElement);

            if (_captureRegex != null)
            {
                Match match = _captureRegex.Match(attribute);
                if (match != null && match.Groups.Count > 1)
                {
                    groupName = match.Groups[1].Value;
                }
            }
            else
            {
                groupName = attribute;
            }

            return(groupName);
        }
Exemplo n.º 7
0
        public void GetAttributeTypeTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name   = "TestField";
            fieldElement.Access = CodeAccess.Protected;
            fieldElement.Type   = "int";

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Type, fieldElement);

            Assert.AreEqual("int", attribute, "Unexpected attribute.");

            TypeElement typeElement = new TypeElement();

            typeElement.Type = TypeElementType.Interface;

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Type, typeElement);
            Assert.AreEqual("Interface", attribute, "Unexpected attribute.");

            CommentElement commentElement = new CommentElement(CommentType.Block);

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Type, commentElement);
            Assert.AreEqual("Block", attribute, "Unexpected attribute.");

            UsingElement usingElement = new UsingElement();

            usingElement.Name     = "MySystem";
            usingElement.Redefine = "System";

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Type, usingElement);
            Assert.AreEqual("Alias", attribute, "Unexpected attribute.");

            ConditionDirectiveElement conditionElement = new ConditionDirectiveElement();

            attribute = ElementUtilities.GetAttribute(ElementAttributeType.Type, conditionElement);
            Assert.AreEqual(string.Empty, attribute, "Unexpected attribute.");
        }