/// <inheritdoc/> internal override bool UpdateDataFrom(AXmlObject source) { if (!base.UpdateDataFrom(source)) { return(false); } AXmlAttribute src = (AXmlAttribute)source; if (this.Name != src.Name || this.EqualsSign != src.EqualsSign || this.QuotedValue != src.QuotedValue || this.Value != src.Value) { OnChanging(); this.Name = src.Name; this.EqualsSign = src.EqualsSign; this.QuotedValue = src.QuotedValue; this.Value = src.Value; OnChanged(); return(true); } else { return(false); } }
/// <inheritdoc/> protected override void InsertItem(int index, AXmlAttribute item) { AddToHashtable(item); item.Changing += item_Changing; item.Changed += item_Changed; base.InsertItem(index, item); }
public override void VisitAttribute(AXmlAttribute attribute) { Debug.Assert(document != null); if (attribute.ParentElement != null) { if (attribute.ParentElement.Parent == document && attribute.LocalName == "Class" && attribute.Namespace == CompletionDataHelper.XamlNamespace) { this.generatedClass = AddClass(attribute.Value, attribute.ParentElement); } else if (generatedClass != null && attribute.LocalName == "Name") { string name = attribute.Value; if (!string.IsNullOrEmpty(name)) { IReturnType type = TypeFromXmlNode(CompilationUnit, attribute.ParentElement); DomRegion position = CreateRegion(attribute.ParentElement.StartOffset, attribute.ParentElement.StartOffset + attribute.ParentElement.Name.Length); ModifierEnum fieldModifier = ModifierEnum.Internal; string modifierValue = (attribute.ParentElement.GetAttributeValue(CompletionDataHelper.XamlNamespace, "FieldModifier") ?? string.Empty).Trim(); string publicString = currentAmbience.ConvertAccessibility(ModifierEnum.Public).Trim(); if (projectContent.Language.NameComparer.Compare(modifierValue, publicString) == 0) fieldModifier = ModifierEnum.Public; generatedClass.Fields.Add(new DefaultField(type, name, fieldModifier, position, generatedClass)); } } } base.VisitAttribute(attribute); }
public AttributeWrapper(AXmlAttribute attribute) { this.LocalName = attribute.LocalName; this.Namespace = attribute.Namespace; this.Prefix = attribute.Prefix; this.Value = attribute.Value; this.Offset = attribute.StartOffset; }
/// <summary> Visit RawAttribute </summary> public override void VisitAttribute(AXmlAttribute attribute) { sb.Append(' '); sb.Append(attribute.Name); sb.Append("="); sb.Append('"'); sb.Append(Escape(attribute.Value)); sb.Append('"'); }
void AddToHashtable(AXmlAttribute attr) { string localName = attr.LocalName; if (!hashtable.ContainsKey(localName)) { hashtable[localName] = new List <AXmlAttribute>(1); } hashtable[localName].Add(attr); }
/// <inheritdoc/> protected override void SetItem(int index, AXmlAttribute item) { RemoveFromHashtable(this[index]); this[index].Changing -= item_Changing; this[index].Changed -= item_Changed; AddToHashtable(item); item.Changing += item_Changing; item.Changed += item_Changed; base.SetItem(index, item); }
/// <inheritdoc/> protected override void InsertItem(int index, AXmlAttribute item) { // prevent insertions into the static 'Empty' instance if (this == Empty) { throw new NotSupportedException("Cannot insert into AXmlAttributeCollection.Empty"); } AddToHashtable(item); item.Changing += item_Changing; item.Changed += item_Changed; base.InsertItem(index, item); }
/// <summary> /// Context: "<" /// </summary> AXmlTag ReadTag() { AssertHasMoreData(); AXmlTag tag; if (TryReadFromCacheOrNew(out tag)) { return(tag); } tag.StartOffset = this.CurrentLocation; // Read the opening bracket // It identifies the type of tag and parsing behavior for the rest of it tag.OpeningBracket = ReadOpeningBracket(); if (tag.IsUnknownBang && !TryPeekWhiteSpace()) { OnSyntaxError(tag, tag.StartOffset, this.CurrentLocation, "Unknown tag"); } if (tag.IsStartOrEmptyTag || tag.IsEndTag || tag.IsProcessingInstruction) { // Read the name string name; if (TryReadName(out name)) { if (!IsValidName(name)) { OnSyntaxError(tag, this.CurrentLocation - name.Length, this.CurrentLocation, "The name '{0}' is invalid", name); } } else { OnSyntaxError(tag, "Element name expected"); } tag.Name = name; } else { tag.Name = string.Empty; } bool isXmlDeclr = tag.StartOffset == 0 && tag.Name == "xml"; if (tag.IsStartOrEmptyTag || tag.IsEndTag || isXmlDeclr) { // Read attributes for the tag while (true) { // Chech for all forbiden 'name' charcters first - see ReadName if (IsEndOfFile()) { break; } if (TryPeekWhiteSpace()) { tag.AddChildren(ReadText(TextType.WhiteSpace)); continue; // End of file might be next } if (TryPeek('<')) { break; } string endBr; int endBrStart = this.CurrentLocation; // Just peek if (TryReadClosingBracket(out endBr)) // End tag { GoBack(endBrStart); break; } // We have "=\'\"" or name - read attribute AXmlAttribute attr = ReadAttribulte(); tag.AddChild(attr); if (tag.IsEndTag) { OnSyntaxError(tag, attr.StartOffset, attr.EndOffset, "Attribute not allowed in end tag."); } } } else if (tag.IsDocumentType) { tag.AddChildren(ReadContentOfDTD()); } else { int start = this.CurrentLocation; IEnumerable <AXmlObject> text; if (tag.IsComment) { text = ReadText(TextType.Comment); } else if (tag.IsCData) { text = ReadText(TextType.CData); } else if (tag.IsProcessingInstruction) { text = ReadText(TextType.ProcessingInstruction); } else if (tag.IsUnknownBang) { text = ReadText(TextType.UnknownBang); } else { throw new InternalException(string.Format(CultureInfo.InvariantCulture, "Unknown opening bracket '{0}'", tag.OpeningBracket)); } // Enumerate text = text.ToList(); // Backtrack at complete start if (IsEndOfFile() || (tag.IsUnknownBang && TryPeek('<'))) { GoBack(start); } else { tag.AddChildren(text); } } // Read closing bracket string bracket; TryReadClosingBracket(out bracket); tag.ClosingBracket = bracket; // Error check int brStart = this.CurrentLocation - (tag.ClosingBracket ?? string.Empty).Length; int brEnd = this.CurrentLocation; if (tag.Name == null) { // One error was reported already } else if (tag.IsStartOrEmptyTag) { if (tag.ClosingBracket != ">" && tag.ClosingBracket != "/>") { OnSyntaxError(tag, brStart, brEnd, "'>' or '/>' expected"); } } else if (tag.IsEndTag) { if (tag.ClosingBracket != ">") { OnSyntaxError(tag, brStart, brEnd, "'>' expected"); } } else if (tag.IsComment) { if (tag.ClosingBracket != "-->") { OnSyntaxError(tag, brStart, brEnd, "'-->' expected"); } } else if (tag.IsCData) { if (tag.ClosingBracket != "]]>") { OnSyntaxError(tag, brStart, brEnd, "']]>' expected"); } } else if (tag.IsProcessingInstruction) { if (tag.ClosingBracket != "?>") { OnSyntaxError(tag, brStart, brEnd, "'?>' expected"); } } else if (tag.IsUnknownBang) { if (tag.ClosingBracket != ">") { OnSyntaxError(tag, brStart, brEnd, "'>' expected"); } } else if (tag.IsDocumentType) { if (tag.ClosingBracket != ">") { OnSyntaxError(tag, brStart, brEnd, "'>' expected"); } } else { throw new InternalException(string.Format(CultureInfo.InvariantCulture, "Unknown opening bracket '{0}'", tag.OpeningBracket)); } // Attribute name may not apper multiple times var duplicates = tag.Children.OfType <AXmlAttribute>().GroupBy(attr => attr.Name).SelectMany(g => g.Skip(1)); foreach (AXmlAttribute attr in duplicates) { OnSyntaxError(tag, attr.StartOffset, attr.EndOffset, "Attribute with name '{0}' already exists", attr.Name); } tag.EndOffset = this.CurrentLocation; OnParsed(tag); return(tag); }
/// <summary> Visit RawAttribute </summary> public virtual void VisitAttribute(AXmlAttribute attribute) { }
/// <summary> Visit RawAttribute </summary> public override void VisitAttribute(AXmlAttribute attribute) { sb.Append(attribute.Name); sb.Append(attribute.EqualsSign); sb.Append(attribute.QuotedValue); }
void RemoveFromHashtable(AXmlAttribute attr) { string localName = attr.LocalName; hashtable[localName].Remove(attr); }
/// <summary> Visit RawAttribute </summary> public virtual void VisitAttribute(AXmlAttribute attribute) { }
/// <summary> Visit RawAttribute </summary> public override void VisitAttribute(AXmlAttribute attribute) { sb.Append(attribute.Name); sb.Append(attribute.EqualsSign); sb.Append(attribute.QuotedValue); }
/// <summary> Visit RawAttribute </summary> public override void VisitAttribute(AXmlAttribute attribute) { sb.Append(' '); sb.Append(attribute.Name); sb.Append("="); sb.Append('"'); sb.Append(Escape(attribute.Value)); sb.Append('"'); }
/// <inheritdoc/> protected override void SetItem(int index, AXmlAttribute item) { throw new NotSupportedException(); }