[11804] | 1 | // Copyright (c) 2009-2013 AlphaSierraPapa for the SharpDevelop Team |
---|
| 2 | // |
---|
| 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this |
---|
| 4 | // software and associated documentation files (the "Software"), to deal in the Software |
---|
| 5 | // without restriction, including without limitation the rights to use, copy, modify, merge, |
---|
| 6 | // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons |
---|
| 7 | // to whom the Software is furnished to do so, subject to the following conditions: |
---|
| 8 | // |
---|
| 9 | // The above copyright notice and this permission notice shall be included in all copies or |
---|
| 10 | // substantial portions of the Software. |
---|
| 11 | // |
---|
| 12 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
---|
| 13 | // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
---|
| 14 | // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE |
---|
| 15 | // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
---|
| 16 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 17 | // DEALINGS IN THE SOFTWARE. |
---|
| 18 | |
---|
| 19 | using System; |
---|
| 20 | using System.Collections.ObjectModel; |
---|
| 21 | using System.Globalization; |
---|
| 22 | using ICSharpCode.NRefactory.Editor; |
---|
| 23 | |
---|
| 24 | namespace ICSharpCode.NRefactory.Xml |
---|
| 25 | { |
---|
| 26 | /// <summary> |
---|
| 27 | /// Represents any markup starting with "<" and (hopefully) ending with ">" |
---|
| 28 | /// </summary> |
---|
| 29 | public class AXmlTag : AXmlObject |
---|
| 30 | { |
---|
| 31 | /// <summary> These identify the start of DTD elements </summary> |
---|
| 32 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="ReadOnlyCollection is immutable")] |
---|
| 33 | public static readonly ReadOnlyCollection<string> DtdNames = new ReadOnlyCollection<string>( |
---|
| 34 | new string[] {"<!DOCTYPE", "<!NOTATION", "<!ELEMENT", "<!ATTLIST", "<!ENTITY" } ); |
---|
| 35 | |
---|
| 36 | new readonly InternalTag internalObject; |
---|
| 37 | |
---|
| 38 | internal AXmlTag(AXmlObject parent, int startOffset, InternalTag internalObject) |
---|
| 39 | : base(parent, startOffset, internalObject) |
---|
| 40 | { |
---|
| 41 | this.internalObject = internalObject; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | /// <summary> Opening bracket - usually "<" </summary> |
---|
| 45 | public string OpeningBracket { |
---|
| 46 | get { return internalObject.OpeningBracket; } |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /// <summary> Name following the opening bracket </summary> |
---|
| 50 | public string Name { |
---|
| 51 | get { return internalObject.Name; } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | /// <summary> Gets the segment containing the tag name </summary> |
---|
| 55 | public ISegment NameSegment { |
---|
| 56 | get { |
---|
| 57 | int start = startOffset + internalObject.RelativeNameStart; |
---|
| 58 | return new XmlSegment(start, start + internalObject.Name.Length); |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /// <summary> Closing bracket - usually ">" </summary> |
---|
| 63 | public string ClosingBracket { |
---|
| 64 | get { return internalObject.ClosingBracket; } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /// <summary> True if tag starts with "<" </summary> |
---|
| 68 | public bool IsStartOrEmptyTag { get { return internalObject.IsStartOrEmptyTag; } } |
---|
| 69 | /// <summary> True if tag starts with "<" and ends with ">" </summary> |
---|
| 70 | public bool IsStartTag { get { return internalObject.IsStartTag; } } |
---|
| 71 | /// <summary> True if tag starts with "<" and does not end with ">" </summary> |
---|
| 72 | public bool IsEmptyTag { get { return internalObject.IsEmptyTag; } } |
---|
| 73 | /// <summary> True if tag starts with "</" </summary> |
---|
| 74 | public bool IsEndTag { get { return internalObject.IsEndTag; } } |
---|
| 75 | /// <summary> True if tag starts with "<?" </summary> |
---|
| 76 | public bool IsProcessingInstruction { get { return internalObject.IsProcessingInstruction; } } |
---|
| 77 | /// <summary> True if tag starts with "<!--" </summary> |
---|
| 78 | public bool IsComment { get { return internalObject.IsComment; } } |
---|
| 79 | /// <summary> True if tag starts with "<![CDATA[" </summary> |
---|
| 80 | public bool IsCData { get { return internalObject.IsCData; } } |
---|
| 81 | /// <summary> True if tag starts with one of the DTD starts </summary> |
---|
| 82 | public bool IsDocumentType { get { return internalObject.IsDocumentType; } } |
---|
| 83 | /// <summary> True if tag starts with "<!" </summary> |
---|
| 84 | public bool IsUnknownBang { get { return internalObject.IsUnknownBang; } } |
---|
| 85 | |
---|
| 86 | /// <inheritdoc/> |
---|
| 87 | public override void AcceptVisitor(AXmlVisitor visitor) |
---|
| 88 | { |
---|
| 89 | visitor.VisitTag(this); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /// <inheritdoc/> |
---|
| 93 | public override string ToString() |
---|
| 94 | { |
---|
| 95 | return string.Format(CultureInfo.InvariantCulture, "[{0} '{1}{2}{3}' Attr:{4}]", base.ToString(), this.OpeningBracket, this.Name, this.ClosingBracket, this.Children.Count); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|