XML object. Base class for all nodes in the XML document.
Inheritance: ISegment
		void UpdateNode(XamlOutlineNode node, AXmlObject dataNode)
		{
			if (dataNode == null || node == null)
				return;
			if (dataNode is AXmlElement) {
				var item = (AXmlElement)dataNode;
				node.Name = item.GetAttributeValue("Name") ?? item.GetAttributeValue(XamlConst.XamlNamespace, "Name");
				node.ElementName = item.Name;
			}
			node.Marker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.StartOffset, 0, editor.Document.TextLength));
			node.EndMarker = editor.Document.CreateAnchor(Utils.MinMax(dataNode.EndOffset, 0, editor.Document.TextLength));
			
			var dataChildren = dataNode.Children.OfType<AXmlElement>().ToList();
			
			int childrenCount = node.Children.Count;
			int dataCount = dataChildren.Count;
			
			for (int i = 0; i < Math.Max(childrenCount, dataCount); i++) {
				if (i >= childrenCount) {
					node.Children.Add(BuildNode(dataChildren[i]));
				} else if (i >= dataCount) {
					while (node.Children.Count > dataCount)
						node.Children.RemoveAt(dataCount);
				} else {
					UpdateNode(node.Children[i] as XamlOutlineNode, dataChildren[i]);
				}
			}
		}
 /// <summary>
 /// Creates a new documentation element.
 /// </summary>
 public XmlDocumentationElement(AXmlElement element, IEntity declaringEntity, Func<string, IEntity> crefResolver)
 {
     if (element == null)
         throw new ArgumentNullException("element");
     this.element = element;
     this.xmlObject = element;
     this.declaringEntity = declaringEntity;
     this.crefResolver = crefResolver;
 }
 /// <summary>
 /// Creates a new documentation element.
 /// </summary>
 public XmlDocumentationElement(AXmlDocument document, IEntity declaringEntity, Func <string, IEntity> crefResolver)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     this.xmlObject       = document;
     this.declaringEntity = declaringEntity;
     this.crefResolver    = crefResolver;
 }
Exemple #4
0
		IList<AXmlObject> CreatePublic(IList<InternalObject> internalObjects)
		{
			var publicObjects = new AXmlObject[internalObjects.Count];
			int pos = 0;
			for (int i = 0; i < internalObjects.Count; i++) {
				publicObjects[i] = internalObjects[i].CreatePublicObject(null, pos);
				pos += internalObjects[i].Length;
			}
			return Array.AsReadOnly(publicObjects);
		}
        IList <AXmlObject> CreatePublic(IList <InternalObject> internalObjects)
        {
            var publicObjects = new AXmlObject[internalObjects.Count];
            int pos           = 0;

            for (int i = 0; i < internalObjects.Count; i++)
            {
                publicObjects[i] = internalObjects[i].CreatePublicObject(null, pos);
                pos += internalObjects[i].Length;
            }
            return(Array.AsReadOnly(publicObjects));
        }
Exemple #6
0
 int GetAttributeIndex(string name, string ns)
 {
     if (attributes == null)
     {
         return(-1);
     }
     for (int i = 0; i < attributes.Count; i++)
     {
         if (AXmlObject.GetLocalName(attributes[i].Name) == name && LookupNamespace(AXmlObject.GetNamespacePrefix(attributes[i].Name)) == ns)
         {
             return(i);
         }
     }
     return(-1);
 }
Exemple #7
0
 internal AXmlElement(AXmlObject parent, int startOffset, InternalElement internalObject)
     : base(parent, startOffset, internalObject)
 {
     Log.Assert(internalObject.NestedObjects[0] is InternalTag, "First child of element must be start tag");
 }
		public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
		{
			return new AXmlTag(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
		}
Exemple #9
0
		internal AXmlText(AXmlObject parent, int startOffset, InternalText internalObject)
			: base(parent, startOffset, internalObject)
		{
		}
Exemple #10
0
 public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
 {
     return(new AXmlText(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this));
 }
Exemple #11
0
 internal AXmlAttribute(AXmlObject parent, int startOffset, InternalAttribute internalObject)
     : base(parent, startOffset, internalObject)
 {
 }
Exemple #12
0
		internal AXmlElement(AXmlObject parent, int startOffset, InternalElement internalObject)
			: base(parent, startOffset, internalObject)
		{
			Log.Assert(internalObject.NestedObjects[0] is InternalTag, "First child of element must be start tag");
		}
        static void CompareResults(AXmlObject obj1, AXmlObject obj2)
        {
            if (obj1.GetType() != obj2.GetType())
                throw new InvalidOperationException();
            if (obj1.StartOffset != obj2.StartOffset)
                throw new InvalidOperationException();
            if (obj1.EndOffset != obj2.EndOffset)
                throw new InvalidOperationException();

            if (obj1.MySyntaxErrors.Count() != obj2.MySyntaxErrors.Count())
                throw new InvalidOperationException();
            foreach (var pair in obj1.MySyntaxErrors.Zip(obj2.MySyntaxErrors, (a,b) => new { a, b })) {
                if (pair.a.StartOffset != pair.b.StartOffset)
                    throw new InvalidOperationException();
                if (pair.a.EndOffset != pair.b.EndOffset)
                    throw new InvalidOperationException();
                if (pair.a.Description != pair.b.Description)
                    throw new InvalidOperationException();
            }

            if (obj1 is AXmlText) {
                var a = (AXmlText)obj1;
                var b = (AXmlText)obj2;
                if (a.ContainsOnlyWhitespace != b.ContainsOnlyWhitespace)
                    throw new InvalidOperationException();
                if (a.Value != b.Value)
                    throw new InvalidOperationException();
            } else if (obj1 is AXmlTag) {
                var a = (AXmlTag)obj1;
                var b = (AXmlTag)obj2;
                if (a.OpeningBracket != b.OpeningBracket)
                    throw new InvalidOperationException();
                if (a.ClosingBracket != b.ClosingBracket)
                    throw new InvalidOperationException();
                if (a.Name != b.Name)
                    throw new InvalidOperationException();
            } else if (obj1 is AXmlAttribute) {
                var a = (AXmlAttribute)obj1;
                var b = (AXmlAttribute)obj2;
                if (a.Name != b.Name)
                    throw new InvalidOperationException();
                if (a.Value != b.Value)
                    throw new InvalidOperationException();
            } else if (obj1 is AXmlElement) {
                var a = (AXmlElement)obj1;
                var b = (AXmlElement)obj2;
                if (a.Name != b.Name)
                    throw new InvalidOperationException();
                if (a.IsProperlyNested != b.IsProperlyNested)
                    throw new InvalidOperationException();
                if (a.HasEndTag != b.HasEndTag)
                    throw new InvalidOperationException();
            } else if (obj1 is AXmlDocument) {
                // only compare the children
            } else {
                throw new NotSupportedException();
            }

            CompareResults(obj1.Children, obj2.Children);
        }
Exemple #14
0
		internal AXmlTag(AXmlObject parent, int startOffset, InternalTag internalObject)
			: base(parent, startOffset, internalObject)
		{
			this.internalObject = internalObject;
		}
Exemple #15
0
 internal AXmlTag(AXmlObject parent, int startOffset, InternalTag internalObject)
     : base(parent, startOffset, internalObject)
 {
     this.internalObject = internalObject;
 }
Exemple #16
0
 internal AXmlText(AXmlObject parent, int startOffset, InternalText internalObject)
     : base(parent, startOffset, internalObject)
 {
 }
Exemple #17
0
 internal AXmlDocument(AXmlObject parent, int startOffset, InternalDocument internalObject)
     : base(parent, startOffset, internalObject)
 {
 }
Exemple #18
0
		internal AXmlAttribute(AXmlObject parent, int startOffset, InternalAttribute internalObject)
			: base(parent, startOffset, internalObject)
		{
		}
Exemple #19
0
 public abstract AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset);
 internal AXmlObject(AXmlObject parent, int startOffset, InternalObject internalObject)
 {
     this.parent         = parent;
     this.startOffset    = startOffset;
     this.internalObject = internalObject;
 }
Exemple #21
0
 internal AXmlDocument(AXmlObject parent, int startOffset, InternalDocument internalObject)
     : base(parent, startOffset, internalObject)
 {
 }
Exemple #22
0
		public abstract AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset);
Exemple #23
0
		internal AXmlObject(AXmlObject parent, int startOffset, InternalObject internalObject)
		{
			this.parent = parent;
			this.startOffset = startOffset;
			this.internalObject = internalObject;
		}
Exemple #24
0
 bool ReadCurrentPosition()
 {
     attributes       = null;
     attributeIndex   = -1;
     inAttributeValue = false;
     while (true)
     {
         var obj = objectIterator.CurrentObject;
         if (obj == null)
         {
             readState       = ReadState.EndOfFile;
             elementNodeType = XmlNodeType.None;
             return(false);
         }
         else if (objectIterator.IsAtElementEnd)
         {
             if (IsEmptyElement)
             {
                 // Don't report EndElement for empty elements
                 nsManager.PopScope();
             }
             else
             {
                 elementNodeType = XmlNodeType.EndElement;
                 return(true);
             }
         }
         else if (obj is InternalElement)
         {
             // element start
             elementNodeType = XmlNodeType.Element;
             InternalTag startTag = ((InternalTag)obj.NestedObjects[0]);
             nsManager.PushScope();
             if (startTag.NestedObjects != null)
             {
                 attributes = startTag.NestedObjects.OfType <InternalAttribute>().ToList();
                 for (int i = 0; i < attributes.Count; i++)
                 {
                     var attr = attributes[i];
                     if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal))
                     {
                         nsManager.AddNamespace(AXmlObject.GetLocalName(attr.Name), attr.Value);
                     }
                     else if (attr.Name == "xmlns")
                     {
                         nsManager.AddNamespace(string.Empty, attr.Value);
                     }
                 }
             }
             return(true);
         }
         else if (obj is InternalText)
         {
             InternalText text = (InternalText)obj;
             if (text.ContainsOnlyWhitespace)
             {
                 elementNodeType = XmlNodeType.Whitespace;
             }
             else
             {
                 elementNodeType = XmlNodeType.Text;
             }
             return(true);
         }
         else if (obj is InternalTag)
         {
             InternalTag tag = (InternalTag)obj;
             if (tag.IsStartOrEmptyTag || tag.IsEndTag)
             {
                 // start/end tags can be skipped as the parent InternalElement already handles them
             }
             else if (tag.IsComment && !settings.IgnoreComments)
             {
                 elementNodeType = XmlNodeType.Comment;
                 return(true);
             }
             else if (tag.IsProcessingInstruction && !settings.IgnoreProcessingInstructions)
             {
                 if (tag.Name == "xml")
                 {
                     elementNodeType = XmlNodeType.XmlDeclaration;
                     attributes      = tag.NestedObjects.OfType <InternalAttribute>().ToList();
                 }
                 else
                 {
                     elementNodeType = XmlNodeType.ProcessingInstruction;
                 }
                 return(true);
             }
             else if (tag.IsCData)
             {
                 elementNodeType = XmlNodeType.CDATA;
                 return(true);
             }
             else
             {
                 // TODO all other tags
             }
         }
         else
         {
             throw new NotSupportedException();
         }
         objectIterator.MoveInto();
     }
 }