Attribute code element.
상속: TextCodeElement, IAttributeElement
예제 #1
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.");
        }
예제 #2
0
        /// <summary>
        /// Parses an attribute.
        /// </summary>
        /// <param name="comments">The comments.</param>
        /// <param name="nested">Whether or not the attribute is nested/chained.</param>
        /// <returns>An attribute code element.</returns>
        private AttributeElement ParseAttribute(ReadOnlyCollection<ICommentElement> comments, bool nested)
        {
            AttributeElement attributeElement = new AttributeElement();

            string typeName = CaptureTypeName(false);
            EatLineContinuation();

            //
            // Check for an attribute target
            //
            if (TryReadChar(VBSymbol.LineDelimiter))
            {
                attributeElement.Target = typeName;
                typeName = CaptureTypeName(false);
                EatLineContinuation();
            }

            attributeElement.Name = typeName;

            if (NextChar == VBSymbol.BeginParameterList)
            {
                string attributeText = ParseNestedText(
                    VBSymbol.BeginParameterList, VBSymbol.EndParameterList, true, true);
                attributeElement.BodyText = attributeText;
            }

            EatLineContinuation();

            while (!nested && TryReadChar(VBSymbol.AliasSeparator))
            {
                if (NextChar != VBSymbol.AliasSeparator)
                {
                    AttributeElement childAttributeElement = ParseAttribute(null, true);
                    if (string.IsNullOrEmpty(childAttributeElement.Target))
                    {
                        childAttributeElement.Target = attributeElement.Target;
                    }
                    attributeElement.AddChild(childAttributeElement);
                }
            }

            EatLineContinuation();

            if (!nested)
            {
                EatChar(VBSymbol.EndAttribute);
            }

            if (comments != null && comments.Count > 0)
            {
                foreach (ICommentElement comment in comments)
                {
                    attributeElement.AddHeaderComment(comment);
                }
            }

            return attributeElement;
        }
예제 #3
0
        /// <summary>
        /// Parses a VB Option directive from comments.
        /// </summary>
        /// <param name="comments">Comments to analyze.</param>
        /// <returns>The code element.</returns>
        private ICodeElement ParseOption(ReadOnlyCollection<ICommentElement> comments)
        {
            // HACK: Create an explicit element type for Option (or compiler directive)
            string option = VBKeyword.Option + ReadCodeLine();
            AttributeElement optionElement = new AttributeElement();
            optionElement.BodyText = option;
            optionElement[VBExtendedProperties.Option] = true;

            foreach (ICommentElement comment in comments)
            {
                optionElement.AddHeaderComment(comment);
            }

            return optionElement;
        }
예제 #4
0
 /// <summary>
 /// Processes an attribute element.
 /// </summary>
 /// <param name="element">Attribute code element.</param>
 public abstract void VisitAttributeElement(AttributeElement element);
예제 #5
0
        /// <summary>
        /// Processes an attribute element.
        /// </summary>
        /// <param name="element">Attribute code element.</param>
        public override void VisitAttributeElement(AttributeElement element)
        {
            this.WriteComments(element.HeaderComments);

            // HACK: Create an explicit element type for Option (or compiler directive)
            if (element[VBExtendedProperties.Option] is bool &&
                (bool)element[VBExtendedProperties.Option])
            {
                WriteIndented(element.BodyText);
            }
            else
            {
                bool nested = element.Parent is AttributeElement;
                if (!nested)
                {
                    WriteIndented(VBSymbol.BeginAttribute.ToString());
                }

                if (!string.IsNullOrEmpty(element.Target))
                {
                    Writer.Write(element.Target);
                    Writer.Write(VBSymbol.LineDelimiter);
                    Writer.Write(' ');
                }

                Writer.Write(element.Name);
                if (!string.IsNullOrEmpty(element.BodyText))
                {
                    Writer.Write(VBSymbol.BeginParameterList);
                    Writer.Write(element.BodyText);
                    Writer.Write(VBSymbol.EndParameterList);
                }

                //
                // Nested list of attributes?
                //
                foreach (ICodeElement childElement in element.Children)
                {
                    AttributeElement childAttribute = childElement as AttributeElement;
                    if (childAttribute != null)
                    {
                        Writer.Write(", _");
                        Writer.WriteLine();
                        WriteIndented(string.Empty);
                        childAttribute.Accept(this);
                    }
                }

                if (!nested)
                {
                    Writer.Write(VBSymbol.EndAttribute);

                    if (element.Parent is TextCodeElement)
                    {
                        Writer.Write(" _");
                    }
                }

                if (!nested && element.Parent != null)
                {
                    Writer.WriteLine();
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Processes an attribute element.
        /// </summary>
        /// <param name="element">Attribute code element.</param>
        public override void VisitAttributeElement(AttributeElement element)
        {
            this.WriteComments(element.HeaderComments);

            bool nested = element.Parent is AttributeElement;

            if (!nested)
            {
                WriteIndented(CSharpSymbol.BeginAttribute.ToString());
                if (!string.IsNullOrEmpty(element.Target))
                {
                    Writer.Write(element.Target);
                    Writer.Write(CSharpSymbol.TypeImplements);
                    Writer.Write(' ');
                }
            }

            Writer.Write(element.Name);
            if (!string.IsNullOrEmpty(element.BodyText))
            {
                Writer.Write(CSharpSymbol.BeginParameterList);
                Writer.Write(element.BodyText);
                Writer.Write(CSharpSymbol.EndParameterList);
            }

            //
            // Nested list of attributes?
            //
            foreach (ICodeElement childElement in element.Children)
            {
                AttributeElement childAttribute = childElement as AttributeElement;
                if (childAttribute != null)
                {
                    Writer.Write(',');
                    Writer.WriteLine();
                    WriteIndented(string.Empty);
                    childAttribute.Accept(this);
                }
            }

            if (!nested)
            {
                Writer.Write(CSharpSymbol.EndAttribute);
            }

            if (!nested && element.Parent != null)
            {
                Writer.WriteLine();
            }
        }