1
// Copyright (c) 2009-2013 AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
21
namespace ICSharpCode.NRefactory.Xml
23
internal abstract class InternalObject
25
public int StartRelativeToParent;
27
/// <summary>Length that was touched to parsed this object.</summary>
28
public int LengthTouched;
29
public InternalSyntaxError[] SyntaxErrors;
30
public InternalObject[] NestedObjects;
32
public InternalObject SetStartRelativeToParent(int newStartRelativeToParent)
34
if (newStartRelativeToParent == StartRelativeToParent)
36
InternalObject obj = (InternalObject)MemberwiseClone();
37
obj.StartRelativeToParent = newStartRelativeToParent;
41
public abstract AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset);
44
sealed class InternalDocument : InternalObject
46
public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
48
return new AXmlDocument(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
52
sealed class InternalText : InternalObject
55
public bool ContainsOnlyWhitespace;
58
public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
60
return new AXmlText(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
63
public override string ToString()
65
return "Text: " + this.Value.Replace("\n", "\\n").Replace("\r", "\\r");
69
sealed class InternalTag : InternalObject
71
public string OpeningBracket;
72
public int RelativeNameStart;
74
public string ClosingBracket;
76
/// <summary> True if tag starts with "<" </summary>
77
public bool IsStartOrEmptyTag { get { return OpeningBracket == "<"; } }
78
/// <summary> True if tag starts with "<" and ends with ">" </summary>
79
public bool IsStartTag { get { return OpeningBracket == "<" && ClosingBracket == ">"; } }
80
/// <summary> True if tag starts with "<" and does not end with ">" </summary>
81
public bool IsEmptyTag { get { return OpeningBracket == "<" && ClosingBracket != ">" ; } }
82
/// <summary> True if tag starts with "</" </summary>
83
public bool IsEndTag { get { return OpeningBracket == "</"; } }
84
/// <summary> True if tag starts with "<?" </summary>
85
public bool IsProcessingInstruction { get { return OpeningBracket == "<?"; } }
86
/// <summary> True if tag starts with "<!--" </summary>
87
public bool IsComment { get { return OpeningBracket == "<!--"; } }
88
/// <summary> True if tag starts with "<![CDATA[" </summary>
89
public bool IsCData { get { return OpeningBracket == "<![CDATA["; } }
90
/// <summary> True if tag starts with one of the DTD starts </summary>
91
public bool IsDocumentType { get { return AXmlTag.DtdNames.Contains(OpeningBracket); } }
92
/// <summary> True if tag starts with "<!" </summary>
93
public bool IsUnknownBang { get { return OpeningBracket == "<!"; } }
95
public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
97
return new AXmlTag(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
100
public override string ToString()
102
return "Tag: " + OpeningBracket + Name + ClosingBracket;
105
public InternalTag AddSyntaxError(string description)
107
if (this.SyntaxErrors != null && this.SyntaxErrors.Length > 0)
108
return this; // don't add error if there already is one
109
InternalTag tag = (InternalTag)MemberwiseClone();
110
tag.SyntaxErrors = new InternalSyntaxError[] { new InternalSyntaxError(0, Length, description) };
115
struct InternalSyntaxError
117
public readonly int RelativeStart;
118
public readonly int RelativeEnd;
119
public readonly string Description;
121
public InternalSyntaxError(int relativeStart, int relativeEnd, string description)
123
this.RelativeStart = relativeStart;
124
this.RelativeEnd = relativeEnd;
125
this.Description = description;
129
sealed class InternalAttribute : InternalObject
132
public int EqualsSignLength; // length of equals sign including the surrounding whitespace
135
public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
137
return new AXmlAttribute(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
140
public override string ToString()
142
return "Attribute: " + Name + "='" + Value + "'";
146
sealed class InternalElement : InternalObject
148
public bool HasEndTag;
149
public bool IsPropertyNested;
150
public readonly string Name;
152
public InternalElement(InternalTag tag)
154
this.Name = tag.Name;
157
public string Prefix {
158
get { return AXmlObject.GetNamespacePrefix(Name); }
161
public string LocalName {
162
get { return AXmlObject.GetLocalName(Name); }
165
public override AXmlObject CreatePublicObject(AXmlObject parent, int parentStartOffset)
167
return new AXmlElement(parent, (parent != null ? parentStartOffset + StartRelativeToParent : parentStartOffset), this);
170
public override string ToString()
172
return "Element: " + NestedObjects[0].ToString();