Browse Source

Fixed FxCop issues in ICSharpCode.AvalonEdit.Xml

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4909 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
c7b89dc68f
  1. 17
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlAttributeCollection.cs
  2. 34
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlContainer.cs
  3. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlObject.cs
  4. 13
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/CanonicalPrintAXmlVisitor.cs
  5. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/FilteredCollection.cs
  6. 9
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/MergedCollection.cs
  7. 37
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TagMatchingHeuristics.cs
  8. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TagReader.cs
  9. 5
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TrackedSegmentCollection.cs

17
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlAttributeCollection.cs

@ -16,6 +16,8 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -16,6 +16,8 @@ namespace ICSharpCode.AvalonEdit.Xml
public class AXmlAttributeCollection: FilteredCollection<AXmlAttribute, AXmlObjectCollection<AXmlObject>>
{
/// <summary> Empty unbound collection </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes",
Justification = "InsertItem prevents modifying the Empty collection")]
public static readonly AXmlAttributeCollection Empty = new AXmlAttributeCollection();
/// <summary> Create unbound collection </summary>
@ -73,6 +75,10 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -73,6 +75,10 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <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;
@ -91,10 +97,17 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -91,10 +97,17 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <inheritdoc/>
protected override void SetItem(int index, AXmlAttribute item)
{
throw new NotSupportedException();
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);
}
// Every item in the collectoin should be registered to these handlers
// Every item in the collection should be registered to these handlers
// so that we can handle renames
void item_Changing(object sender, AXmlObjectEventArgs e)

34
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlContainer.cs

@ -64,7 +64,15 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -64,7 +64,15 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <inheritdoc/>
public override IEnumerable<AXmlObject> GetSelfAndAllChildren()
{
return new AXmlObject[] { this }.Flatten(i => i is AXmlContainer ? ((AXmlContainer)i).Children : null);
return (new AXmlObject[] { this }).Flatten(
delegate(AXmlObject i) {
AXmlContainer container = i as AXmlContainer;
if (container != null)
return container.Children;
else
return null;
}
);
}
/// <summary>
@ -77,8 +85,9 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -77,8 +85,9 @@ namespace ICSharpCode.AvalonEdit.Xml
foreach(AXmlObject child in this.Children) {
if ((child is AXmlAttribute || child is AXmlText) && offset == child.EndOffset) return child;
if (child.StartOffset < offset && offset < child.EndOffset) {
if (child is AXmlContainer) {
return ((AXmlContainer)child).GetChildAtOffset(offset);
AXmlContainer container = child as AXmlContainer;
if (container != null) {
return container.GetChildAtOffset(offset);
} else {
return child;
}
@ -139,9 +148,10 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -139,9 +148,10 @@ namespace ICSharpCode.AvalonEdit.Xml
// Dangling object - either a new parser object or removed tree (still cached)
item.Parent = this;
item.Document = this.Document;
if (item is AXmlContainer) {
foreach(AXmlObject child in ((AXmlContainer)item).Children) {
((AXmlContainer)item).SetParentPointersInTree(child);
AXmlContainer container = item as AXmlContainer;
if (container != null) {
foreach(AXmlObject child in container.Children) {
container.SetParentPointersInTree(child);
}
}
} else if (item.Parent == this) {
@ -157,7 +167,7 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -157,7 +167,7 @@ namespace ICSharpCode.AvalonEdit.Xml
// becuase otherwise this item would be included twice => safe to change parents
// Maintain cache constraint by setting parents to null
foreach(AXmlObject ancest in item.GetAncestors().ToList()) {
ancest.Parent = null;
ancest.Parent = null;
}
item.Parent = this;
// Rest of the tree is consistent - do not recurse
@ -237,8 +247,9 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -237,8 +247,9 @@ namespace ICSharpCode.AvalonEdit.Xml
// Keep only one item with given offset (we might have several due to deletion)
srcChildren.Remove(child.StartOffset);
// If contaner that needs updating
if (child is AXmlContainer && child.LastUpdatedFrom != srcChild)
((AXmlContainer)child).RemoveChildrenNotIn(((AXmlContainer)srcChild).Children);
AXmlContainer childAsContainer = child as AXmlContainer;
if (childAsContainer != null && child.LastUpdatedFrom != srcChild)
childAsContainer.RemoveChildrenNotIn(((AXmlContainer)srcChild).Children);
i++;
} else {
RemoveChild(i);
@ -261,8 +272,9 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -261,8 +272,9 @@ namespace ICSharpCode.AvalonEdit.Xml
// Does it need updating?
if (child.LastUpdatedFrom != srcChild) {
child.UpdateDataFrom(srcChild);
if (child is AXmlContainer)
((AXmlContainer)child).InsertAndUpdateChildrenFrom(((AXmlContainer)srcChild).Children);
AXmlContainer childAsContainer = child as AXmlContainer;
if (childAsContainer != null)
childAsContainer.InsertAndUpdateChildrenFrom(((AXmlContainer)srcChild).Children);
}
} else {
InsertChild(i, srcChild);

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlObject.cs

@ -144,12 +144,16 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -144,12 +144,16 @@ namespace ICSharpCode.AvalonEdit.Xml
}
/// <summary> Recursively gets self and all nested nodes. </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Using a method makes the API look more LINQ-like and indicates that the returned collection is computed every time.")]
public virtual IEnumerable<AXmlObject> GetSelfAndAllChildren()
{
return new AXmlObject[] { this };
}
/// <summary> Get all ancestors of this node </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Using a method makes the API look more LINQ-like and indicates that the returned collection is computed every time.")]
public IEnumerable<AXmlObject> GetAncestors()
{
AXmlObject curr = this.Parent;

13
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/CanonicalPrintAXmlVisitor.cs

@ -39,12 +39,15 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -39,12 +39,15 @@ namespace ICSharpCode.AvalonEdit.Xml
public override void VisitDocument(AXmlDocument document)
{
foreach(AXmlObject child in document.Children) {
AXmlTag tag = child as AXmlTag;
AXmlTag childAsTag = child as AXmlTag;
// Only procssing instructions or elements
if (tag != null && tag.IsProcessingInstruction && tag.Name != "xml") {
VisitTag(tag);
} else if (child is AXmlElement) {
VisitElement((AXmlElement)child);
if (childAsTag != null && childAsTag.IsProcessingInstruction && childAsTag.Name != "xml") {
VisitTag(childAsTag);
} else {
AXmlElement childAsElement = child as AXmlElement;
if (childAsElement != null) {
VisitElement(childAsElement);
}
}
}
}

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/FilteredCollection.cs

@ -17,9 +17,9 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -17,9 +17,9 @@ namespace ICSharpCode.AvalonEdit.Xml
/// Collection that presents only some items from the wrapped collection.
/// It implicitely filters object that are not of type T (or derived).
/// </summary>
public class FilteredCollection<T, C>: ObservableCollection<T> where C: INotifyCollectionChanged, IList
public class FilteredCollection<T, TCollection>: ObservableCollection<T> where TCollection : INotifyCollectionChanged, IList
{
C source;
TCollection source;
Predicate<object> condition;
List<int> srcPtrs = new List<int>(); // Index to the original collection
@ -27,10 +27,10 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -27,10 +27,10 @@ namespace ICSharpCode.AvalonEdit.Xml
protected FilteredCollection() {}
/// <summary> Wrap the given collection. Items of type other then T are filtered </summary>
public FilteredCollection(C source) : this (source, x => true) { }
public FilteredCollection(TCollection source) : this (source, x => true) { }
/// <summary> Wrap the given collection. Items of type other then T are filtered. Items not matching the condition are filtered. </summary>
public FilteredCollection(C source, Predicate<object> condition)
public FilteredCollection(TCollection source, Predicate<object> condition)
{
this.source = source;
this.condition = condition;

9
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/MergedCollection.cs

@ -15,13 +15,14 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -15,13 +15,14 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <summary>
/// Two collections in sequence
/// </summary>
public class MergedCollection<T, C>: ObservableCollection<T> where C: INotifyCollectionChanged, IList<T>
public class MergedCollection<T, TCollection> : ObservableCollection<T> where TCollection : INotifyCollectionChanged, IList<T>
{
C a;
C b;
TCollection a;
TCollection b;
/// <summary> Create a wrapper containing elements of 'a' and then 'b' </summary>
public MergedCollection(C a, C b)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly")]
public MergedCollection(TCollection a, TCollection b)
{
this.a = a;
this.b = b;

37
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TagMatchingHeuristics.cs

@ -153,10 +153,12 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -153,10 +153,12 @@ namespace ICSharpCode.AvalonEdit.Xml
break;
}
AXmlObject nested = ReadTextOrElement(objStream);
if (nested is AXmlElement) {
if (!((AXmlElement)nested).IsProperlyNested)
AXmlElement nestedAsElement = nested as AXmlElement;
if (nestedAsElement != null) {
if (!nestedAsElement.IsProperlyNested)
element.IsProperlyNested = false;
element.AddChildren(Split((AXmlElement)nested).ToList());
element.AddChildren(Split(nestedAsElement).ToList());
} else {
element.AddChild(nested);
}
@ -333,15 +335,16 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -333,15 +335,16 @@ namespace ICSharpCode.AvalonEdit.Xml
return bestConfig.Document.Reverse().ToList();
}
/// <summary> Get posible configurations after considering fiven object </summary>
/// <summary> Get posible configurations after considering given object </summary>
Configurations ProcessObject(Configurations oldConfigs, AXmlObject obj)
{
AXmlParser.Log("Processing {0}", obj);
AXmlTag tag = obj as AXmlTag;
AXmlParser.Assert(obj is AXmlTag || obj is AXmlText || obj is AXmlElement, obj.GetType().Name + " not expected");
if (obj is AXmlElement)
AXmlParser.Assert(((AXmlElement)obj).IsProperlyNested, "Element not proprly nested");
AXmlTag objAsTag = obj as AXmlTag;
AXmlElement objAsElement = obj as AXmlElement;
AXmlParser.DebugAssert(objAsTag != null || objAsElement != null || obj is AXmlText, obj.GetType().Name + " not expected");
if (objAsElement != null)
AXmlParser.Assert(objAsElement.IsProperlyNested, "Element not properly nested");
Configurations newConfigs = new Configurations();
@ -351,22 +354,22 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -351,22 +354,22 @@ namespace ICSharpCode.AvalonEdit.Xml
var oldDocument = oldConfig.Document;
int oldCost = oldConfig.Cost;
if (tag != null && tag.IsStartTag) {
if (objAsTag != null && objAsTag.IsStartTag) {
newConfigs.Add(new Configuration { // Push start-tag (cost 0)
StartTags = oldStartTags.Push(tag),
Document = oldDocument.Push(tag),
StartTags = oldStartTags.Push(objAsTag),
Document = oldDocument.Push(objAsTag),
Cost = oldCost,
});
} else if (tag != null && tag.IsEndTag) {
} else if (objAsTag != null && objAsTag.IsEndTag) {
newConfigs.Add(new Configuration { // Ignore (cost 1)
StartTags = oldStartTags,
Document = oldDocument.Push(StartTagPlaceholder).Push(tag),
Document = oldDocument.Push(StartTagPlaceholder).Push(objAsTag),
Cost = oldCost + 1,
});
if (!oldStartTags.IsEmpty && oldStartTags.Peek().Name != tag.Name) {
if (!oldStartTags.IsEmpty && oldStartTags.Peek().Name != objAsTag.Name) {
newConfigs.Add(new Configuration { // Pop 1 item (cost 1) - not mathcing
StartTags = oldStartTags.Pop(),
Document = oldDocument.Push(tag),
Document = oldDocument.Push(objAsTag),
Cost = oldCost + 1,
});
}
@ -375,10 +378,10 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -375,10 +378,10 @@ namespace ICSharpCode.AvalonEdit.Xml
var doc = oldDocument;
foreach(AXmlTag poped in oldStartTags) {
popedCount++;
if (poped.Name == tag.Name) {
if (poped.Name == objAsTag.Name) {
newConfigs.Add(new Configuration { // Pop 'x' items (cost x-1) - last one is matching
StartTags = startTags.Pop(),
Document = doc.Push(tag),
Document = doc.Push(objAsTag),
Cost = oldCost + popedCount - 1,
});
}

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TagReader.cs

@ -208,7 +208,7 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -208,7 +208,7 @@ namespace ICSharpCode.AvalonEdit.Xml
string ReadOpeningBracket()
{
// We are using a lot of string literals so that the memory instances are shared
int start = this.CurrentLocation;
//int start = this.CurrentLocation;
if (TryRead('<')) {
if (TryRead('/')) {
return "</";

5
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/TrackedSegmentCollection.cs

@ -106,8 +106,9 @@ namespace ICSharpCode.AvalonEdit.Xml @@ -106,8 +106,9 @@ namespace ICSharpCode.AvalonEdit.Xml
RemoveSyntaxErrorsOf(obj);
AXmlParser.Log("Stopped tracking {0}", obj);
if (obj is AXmlContainer) {
foreach(AXmlObject child in ((AXmlContainer)obj).Children) {
AXmlContainer container = obj as AXmlContainer;
if (container != null) {
foreach (AXmlObject child in container.Children) {
RemoveParsedObject(child);
}
}

Loading…
Cancel
Save