Esempio n. 1
0
        public static TextTag GetAssociatedTextTag(TextBuffer buffer, TextTag tag)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            DocumentTag      elementTag = (DocumentTag)tag;
            string           elementName = elementTag.Name;
            string           suffix, tagName;

            // Check if element is dynamic:
            // True: We create a tagname with suffix :Text#[0-9]* so its unique.
            // False: We create a tagname with a standard suffix :Text
            if (elementTag.IsDynamic)
            {
                suffix  = "#" + elementName.Split('#') [1];
                tagName = elementName.Split('#')[0] + ":Text" + suffix;
            }
            else
            {
                suffix  = String.Empty;
                tagName = elementName + ":Text";
            }

            TextTag textTag = tagTable.Lookup(tagName);

            if (textTag == null)
            {
                textTag = tagTable.CreateDynamicTag(tagName);
            }

            return(textTag);
        }
Esempio n. 2
0
        private static void DeserializeAttributesType(TextBuffer buffer, ref TextIter insertAt, XmlTextReader xmlReader, string tagSuffix)
        {
            string tagName   = String.Empty;
            string tagPrefix = xmlReader.Name + ":";

            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;

            while (xmlReader.MoveToNextAttribute())
            {
                tagName = tagPrefix + xmlReader.Name + tagSuffix;

                TextTag tag = tagTable.Lookup(tagName);
                if (tag == null)
                {
                    tag = tagTable.CreateDynamicTag(tagName);
                }

                buffer.InsertWithTags(ref insertAt, xmlReader.Value, tag);

                        #if DEBUG
                Console.WriteLine("Attribute: {0} End: {1}", tagName, insertAt.Offset);
                        #endif
            }

            DocumentUtils.AddNewLine(buffer, ref insertAt, tagSuffix);
        }
Esempio n. 3
0
        public static void AddText(TextBuffer buffer, ref TextIter insertAt, string data, TextTag tag)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            TextTag          textTag  = tagTable.Lookup("significant-whitespace" + "#" + tag.Name);

            if (textTag == null)
            {
                textTag = tagTable.CreateDynamicTag("significant-whitespace" + "#" + tag.Name);
            }

            string trimData = data.Trim();
            int    index    = data.IndexOf(trimData);

            string startSpace  = data.Substring(0, index);
            string prefixSpace = String.Empty;

            if (!startSpace.Equals(String.Empty))
            {
                if (startSpace.Length == 1)
                {
                    prefixSpace = startSpace;
                    startSpace  = String.Empty;
                }
                else
                {
                    prefixSpace = startSpace.Substring(startSpace.Length - 1);
                    startSpace  = startSpace.Substring(0, startSpace.Length - 1);
                }
            }

            string endSpace  = data.Substring(index + trimData.Length);
            string postSpace = String.Empty;

            if (!endSpace.Equals(String.Empty))
            {
                if (endSpace.Length == 1)
                {
                    if (endSpace.Equals(" "))
                    {
                        postSpace = endSpace;
                        endSpace  = String.Empty;
                    }
                }
                else
                {
                    if (endSpace.Substring(0, 1).Equals(" "))
                    {
                        postSpace = endSpace.Substring(0, 1);
                        endSpace  = endSpace.Substring(1);
                    }
                }
            }

            buffer.InsertWithTags(ref insertAt, Escape(startSpace), textTag);
            buffer.InsertWithTags(ref insertAt, prefixSpace + trimData + postSpace, tag);
            buffer.InsertWithTags(ref insertAt, Escape(endSpace), textTag);
        }
Esempio n. 4
0
        public static void AddPaddingEmpty(TextBuffer buffer, ref TextIter insertAt, string suffix)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            TextTag          tag      = tagTable.Lookup("padding-empty" + suffix);

            if (tag == null)
            {
                tag = tagTable.CreateDynamicTag("padding-empty" + suffix);
            }
            buffer.InsertWithTags(ref insertAt, " ", tag);
        }
Esempio n. 5
0
        public static void AddNewLine(TextBuffer buffer, ref TextIter insertAt, string suffix)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            TextTag          tag      = tagTable.Lookup("newline" + suffix);

            if (tag == null)
            {
                tag = tagTable.CreateDynamicTag("newline" + suffix);
            }
            buffer.InsertWithTags(ref insertAt, "\n", tag);
        }
	public void TestCreateDynamicTag ()
	{
		DocumentTagTable tagTable = new DocumentTagTable ();
		
		TextTag expectedTag = tagTable.Lookup ("format#0");
		Assert.IsNull (expectedTag, "CDT01");
		
		TextTag actualTag = tagTable.CreateDynamicTag ("format#0");
		expectedTag = tagTable.Lookup ("format#0");
		Assert.AreEqual (expectedTag, actualTag, "CDT02");
	}
Esempio n. 7
0
        private static int DeserializeAttributes(TextBuffer buffer, int offset, XmlTextReader xmlReader, string tagSuffix)
        {
            string elementName, tagName;

            elementName = tagName = xmlReader.Name;
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            TextIter         insertAt, applyStart, applyEnd;

            insertAt = buffer.GetIterAtOffset(offset);
            TextTag tagAttributes;

            // Lookup Attributes tag in table, if it is not present we create one.
            tagName      += ":Attributes" + tagSuffix;
            tagAttributes = tagTable.Lookup(tagName);
            if (tagAttributes == null)
            {
                tagAttributes = tagTable.CreateDynamicTag(tagName);
            }

            switch (elementName)
            {
            case "Type":
                DeserializeAttributesType(buffer, ref insertAt, xmlReader, tagSuffix);
                break;

            case "TypeSignature":
                DeserializeAttributesTypeSignature(buffer, ref insertAt, xmlReader, tagSuffix);
                break;

            case "Member":
                DeserializeAttributesMember(buffer, ref insertAt, xmlReader, tagSuffix);
                break;

            case "MemberSignature":
                DeserializeAttributesMemberSignature(buffer, ref insertAt, xmlReader, tagSuffix);
                break;

            default:
                DeserializeAttributesNone(buffer, ref insertAt, xmlReader, tagSuffix);
                break;
            }

            applyStart = buffer.GetIterAtOffset(offset);
            applyEnd   = buffer.GetIterAtOffset(insertAt.Offset);
            buffer.ApplyTag(tagAttributes, applyStart, applyEnd);

                #if DEBUG
            Console.WriteLine("Attributes: {0} Start: {1} End: {2}", tagName, offset, insertAt.Offset);
                #endif

            return(insertAt.Offset);
        }
	public void TestCreateDynamicTagInvalid ()
	{
		DocumentTagTable tagTable = new DocumentTagTable ();
		TextTag tag = null;
		
		try {
			tag = tagTable.CreateDynamicTag ("foo-tag");
		} catch (ArgumentException exception) {
			Assert.AreEqual ("Error -> The tag \"foo-tag\" is not a Dynamic Tag", exception.Message, "TCDTI01");
		}
		
		Assert.IsNull (tag);
	}
        public void TestCreateDynamicTagInvalid()
        {
            DocumentTagTable tagTable = new DocumentTagTable();
            TextTag          tag      = null;

            try {
                tag = tagTable.CreateDynamicTag("foo-tag");
            } catch (ArgumentException exception) {
                Assert.AreEqual("Error -> The tag \"foo-tag\" is not a Dynamic Tag", exception.Message, "TCDTI01");
            }

            Assert.IsNull(tag);
        }
        public void TestCreateDynamicTag()
        {
            DocumentTagTable tagTable = new DocumentTagTable();

            TextTag expectedTag = tagTable.Lookup("format#0");

            Assert.IsNull(expectedTag, "CDT01");

            TextTag actualTag = tagTable.CreateDynamicTag("format#0");

            expectedTag = tagTable.Lookup("format#0");
            Assert.AreEqual(expectedTag, actualTag, "CDT02");
        }
Esempio n. 11
0
        public static void AddStub(TextBuffer buffer, ref TextIter insertAt, string data, string suffix)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;

            TextTag textTag = tagTable.Lookup("stub" + suffix + "#" + counter);

            if (textTag == null)
            {
                textTag = tagTable.CreateDynamicTag("stub" + suffix + "#" + counter);
            }

            counter++;
            buffer.InsertWithTags(ref insertAt, data, textTag);
        }
Esempio n. 12
0
        public static void AddString(TextBuffer buffer, ref TextIter insertAt, string data, string suffix)
        {
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            TextTag          tag      = tagTable.Lookup("format" + suffix);

            if (tag == null)
            {
                tag = tagTable.CreateDynamicTag("format" + suffix);
            }
            buffer.InsertWithTags(ref insertAt, data, tag);

            tag = tagTable.Lookup("format-end" + suffix);

            if (tag == null)
            {
                tag = tagTable.CreateDynamicTag("format-end" + suffix);
            }
            buffer.InsertWithTags(ref insertAt, " ", tag);
        }
 public void TestIsDynamicInvalid()
 {
     Assert.IsFalse(DocumentTagTable.IsDynamic("test"), "TIDI");
 }
	public void TestTagTableSize ()
	{
		DocumentTagTable tagTable = new DocumentTagTable ();
		Assert.AreEqual (115, tagTable.Size, "TTS");
	}
        public void TestTagTableSize()
        {
            DocumentTagTable tagTable = new DocumentTagTable();

            Assert.AreEqual(115, tagTable.Size, "TTS");
        }
 public void TestIsDynamicValid()
 {
     Assert.IsTrue(DocumentTagTable.IsDynamic("para"), "TIDV");
 }
Esempio n. 17
0
        private static int InsertStartElement(TextBuffer buffer, int offset, XmlTextReader xmlReader, Stack stack, ref int depth, ref int count)
        {
            string           elementName = xmlReader.Name;
            string           suffix = String.Empty;
            DocumentTagTable tagTable = (DocumentTagTable)buffer.TagTable;
            bool             emptyElement = xmlReader.IsEmptyElement;
            bool             isDynamic = DocumentTagTable.IsDynamic(elementName);
            TextIter         insertAt, applyStart, applyEnd;

            depth++;

            // We define a suffix so each dynamic tag has an unique name.
            // Suffix has format: #{depth level}
            if (isDynamic)
            {
                suffix = "#" + depth;
            }

            // We add any needed string to give format to the document.
            offset = FormatStart(buffer, offset, suffix, elementName);

            TagStart tagStart = new TagStart();

            tagStart.Start = offset;
            tagStart.Name  = elementName;

            // We first lookup the tag name, if the element is dynamic, we can
            // have three scenarios.
            // 1) The tag is not in the table: So we create it in the spot.
            // 2) Tag is in table but it priority is wrong: We created a new
            // dynamic tag with an extra suffix. Format #{depth level}.{count}
            // 3) Tag is in table with right priority: We reuse it and we don't
            // create a new dymamic tag.
            tagStart.Tag = tagTable.Lookup(elementName + suffix);
            if (isDynamic && tagStart.Tag == null)
            {
                tagStart.Tag = tagTable.CreateDynamicTag(elementName + suffix);
            }
            else if (isDynamic && tagStart.Tag != null && tagStart.Tag.Priority < ((TagStart)stack.Peek()).Tag.Priority)
            {
                suffix      += "." + count;
                tagStart.Tag = tagTable.CreateDynamicTag(elementName + suffix);
                count++;
            }

                #if DEBUG
            try {
                Console.WriteLine("Element: {0} Start: {1}", tagStart.Tag.Name, tagStart.Start);
            } catch (NullReferenceException) {
                Console.WriteLine("Error: Missing {0} element", xmlReader.Name);
                Environment.Exit(1);
            }
                #endif

            // If element has attributes we have to get them and deserialize them.
            if (xmlReader.HasAttributes)
            {
                offset = DeserializeAttributes(buffer, offset, xmlReader, suffix);
            }

            // Special case when an elment is empty.
            // Case A: If element is editable a string stub is inserted to allow edition.
            // Case B: If element is not editable then a padding is inserted to handle
            // TextTag behaviour in which zero length ranges are lost.
            if (emptyElement)
            {
                if (((DocumentTag)tagStart.Tag).IsEditable)
                {
                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "[");
                    offset += 1;

                    offset = DocumentUtils.AddStub(buffer, offset, "Click to Add Documentation", suffix);

                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "]");
                    offset += 1;
                }
                else
                {
                    offset = DocumentUtils.AddPaddingEmpty(buffer, offset, suffix);
                }

                applyStart = buffer.GetIterAtOffset(tagStart.Start);
                applyEnd   = buffer.GetIterAtOffset(offset);
                buffer.ApplyTag(tagStart.Tag, applyStart, applyEnd);
                offset = FormatEnd(buffer, offset, suffix, elementName);

                // Padding between tag regions
                offset = DocumentUtils.AddPadding(buffer, offset, suffix);
                depth--;

                        #if DEBUG
                Console.WriteLine("Empty Element: {0}, Start: {1}, End: {2}", tagStart.Tag.Name, tagStart.Start, offset);
                        #endif
            }
            else
            {
                stack.Push(tagStart);

                if (((DocumentTag)tagStart.Tag).IsEditable)
                {
                    insertAt = buffer.GetIterAtOffset(offset);
                    buffer.Insert(ref insertAt, "[");
                    offset += 1;
                }
            }

            return(offset);
        }