Browse Source

Removed unused object allocations in XML editor.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5216 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 16 years ago
parent
commit
55490f9e3e
  1. 24
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedName.cs
  2. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedNameCollection.cs
  3. 48
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeMatch.cs
  4. 21
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionItemCollection.cs
  5. 16
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespace.cs
  6. 334
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs
  7. 15
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionDataCollection.cs
  8. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/EmptyXmlSchemasPanelTestFixture.cs

24
src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedName.cs

@ -41,15 +41,14 @@ namespace ICSharpCode.XmlEditor
public static bool operator ==(QualifiedName lhs, QualifiedName rhs) public static bool operator ==(QualifiedName lhs, QualifiedName rhs)
{ {
bool equals = false; object lhsObject = (object)lhs;
object rhsObject = (object)rhs;
if (((object)lhs != null) && ((object)rhs != null)) { if ((lhsObject != null) && (rhsObject != null)) {
equals = lhs.Equals(rhs); return lhs.Equals(rhs);
} else if (((object)lhs == null) && ((object)rhs == null)) { } else if ((lhsObject == null) && (rhsObject == null)) {
equals = true; return true;
} }
return false;
return equals;
} }
public static bool operator !=(QualifiedName lhs, QualifiedName rhs) public static bool operator !=(QualifiedName lhs, QualifiedName rhs)
@ -63,19 +62,16 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
bool equals = false;
QualifiedName qualifiedName = obj as QualifiedName; QualifiedName qualifiedName = obj as QualifiedName;
if (qualifiedName != null) { if (qualifiedName != null) {
equals = xmlQualifiedName.Equals(qualifiedName.xmlQualifiedName); return xmlQualifiedName.Equals(qualifiedName.xmlQualifiedName);
} else { } else {
XmlQualifiedName name = obj as XmlQualifiedName; XmlQualifiedName name = obj as XmlQualifiedName;
if (name != null) { if (name != null) {
equals = xmlQualifiedName.Equals(name); return xmlQualifiedName.Equals(name);
} }
} }
return false;
return equals;
} }
public override int GetHashCode() public override int GetHashCode()

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/QualifiedNameCollection.cs

@ -66,9 +66,10 @@ namespace ICSharpCode.XmlEditor
/// <seealso cref='QualifiedNameCollection.Add'/> /// <seealso cref='QualifiedNameCollection.Add'/>
public void AddRange(QualifiedName[] val) public void AddRange(QualifiedName[] val)
{ {
for (int i = 0; i < val.Length; i++) for (int i = 0; i < val.Length; i++) {
this.Add(val[i]); this.Add(val[i]);
} }
}
/// <summary> /// <summary>
/// Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection. /// Adds the contents of another <see cref='QualifiedNameCollection'/> to the end of the collection.
@ -79,9 +80,10 @@ namespace ICSharpCode.XmlEditor
/// <seealso cref='QualifiedNameCollection.Add'/> /// <seealso cref='QualifiedNameCollection.Add'/>
public void AddRange(QualifiedNameCollection val) public void AddRange(QualifiedNameCollection val)
{ {
for (int i = 0; i < val.Count; i++) for (int i = 0; i < val.Count; i++) {
this.Add(val[i]); this.Add(val[i]);
} }
}
/// <summary> /// <summary>
/// Removes the last item in this collection. /// Removes the last item in this collection.

48
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeMatch.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.XmlEditor
{ {
int? lineNumber; int? lineNumber;
int linePosition; int linePosition;
string value; string nodeValue;
string displayValue; string displayValue;
XPathNodeType nodeType; XPathNodeType nodeType;
@ -55,8 +55,8 @@ namespace ICSharpCode.XmlEditor
SetAttributeValue(currentNavigator); SetAttributeValue(currentNavigator);
break; break;
default: default:
value = currentNavigator.LocalName; nodeValue = currentNavigator.LocalName;
displayValue = value; displayValue = nodeValue;
break; break;
} }
} }
@ -65,18 +65,14 @@ namespace ICSharpCode.XmlEditor
/// Line numbers are zero based. /// Line numbers are zero based.
/// </summary> /// </summary>
public int LineNumber { public int LineNumber {
get { get { return lineNumber.GetValueOrDefault(0); }
return lineNumber.GetValueOrDefault(0);
}
} }
/// <summary> /// <summary>
/// Line positions are zero based. /// Line positions are zero based.
/// </summary> /// </summary>
public int LinePosition { public int LinePosition {
get { get { return linePosition; }
return linePosition;
}
} }
public bool HasLineInfo() public bool HasLineInfo()
@ -88,9 +84,7 @@ namespace ICSharpCode.XmlEditor
/// Gets the text value of the node. /// Gets the text value of the node.
/// </summary> /// </summary>
public string Value { public string Value {
get { get { return nodeValue; }
return value;
}
} }
/// <summary> /// <summary>
@ -98,55 +92,51 @@ namespace ICSharpCode.XmlEditor
/// an element, for example. /// an element, for example.
/// </summary> /// </summary>
public string DisplayValue { public string DisplayValue {
get { get { return displayValue; }
return displayValue;
}
} }
public XPathNodeType NodeType { public XPathNodeType NodeType {
get { get { return nodeType; }
return nodeType;
}
} }
void SetElementValue(XPathNavigator navigator) void SetElementValue(XPathNavigator navigator)
{ {
value = navigator.Name; nodeValue = navigator.Name;
if (navigator.IsEmptyElement) { if (navigator.IsEmptyElement) {
displayValue = string.Concat("<", value, "/>"); displayValue = String.Concat("<", nodeValue, "/>");
} else { } else {
displayValue = string.Concat("<", value, ">"); displayValue = String.Concat("<", nodeValue, ">");
} }
} }
void SetTextValue(XPathNavigator navigator) void SetTextValue(XPathNavigator navigator)
{ {
value = navigator.Value; nodeValue = navigator.Value;
displayValue = value; displayValue = nodeValue;
} }
void SetCommentValue(XPathNavigator navigator) void SetCommentValue(XPathNavigator navigator)
{ {
value = navigator.Value; nodeValue = navigator.Value;
displayValue = navigator.OuterXml; displayValue = navigator.OuterXml;
} }
void SetNamespaceValue(XPathNavigator navigator) void SetNamespaceValue(XPathNavigator navigator)
{ {
value = navigator.OuterXml; nodeValue = navigator.OuterXml;
displayValue = value; displayValue = nodeValue;
} }
void SetProcessingInstructionValue(XPathNavigator navigator) void SetProcessingInstructionValue(XPathNavigator navigator)
{ {
value = navigator.Name; nodeValue = navigator.Name;
displayValue = navigator.OuterXml; displayValue = navigator.OuterXml;
} }
void SetAttributeValue(XPathNavigator navigator) void SetAttributeValue(XPathNavigator navigator)
{ {
value = navigator.Name; nodeValue = navigator.Name;
displayValue = string.Concat("@", value); displayValue = String.Concat("@", nodeValue);
} }
/// <summary> /// <summary>

21
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlCompletionItemCollection.cs

@ -56,10 +56,11 @@ namespace ICSharpCode.XmlEditor
public void AddRange(XmlCompletionItem[] val) public void AddRange(XmlCompletionItem[] val)
{ {
for (int i = 0; i < val.Length; i++) { for (int i = 0; i < val.Length; i++) {
if (!Contains(val[i].Text)) if (!Contains(val[i].Text)) {
this.Add(val[i]); this.Add(val[i]);
} }
} }
}
/// <summary> /// <summary>
/// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection. /// Adds the contents of another <see cref='XmlCompletionDataCollection'/> to the end of the collection.
@ -70,33 +71,27 @@ namespace ICSharpCode.XmlEditor
/// <seealso cref='XmlCompletionDataCollection.Add'/> /// <seealso cref='XmlCompletionDataCollection.Add'/>
public void AddRange(XmlCompletionItemCollection val) public void AddRange(XmlCompletionItemCollection val)
{ {
for (int i = 0; i < val.Count; i++) for (int i = 0; i < val.Count; i++) {
if (!Contains(val[i].Text)) if (!Contains(val[i].Text)) {
this.Add(val[i]); this.Add(val[i]);
} }
}
}
public bool Contains(string name) public bool Contains(string name)
{ {
bool contains = false;
foreach (XmlCompletionItem data in this) { foreach (XmlCompletionItem data in this) {
if (data.Text != null) { if (data.Text != null) {
if (data.Text.Length > 0) { if (data.Text.Length > 0) {
if (data.Text == name) { if (data.Text == name) {
contains = true; return true;
break;
} }
} }
} }
} }
return false;
return contains;
} }
/// <summary>
/// Returns an array of <see cref="ICompletionData"/> items.
/// </summary>
/// <returns></returns>
public ICompletionItem[] ToArray() public ICompletionItem[] ToArray()
{ {
XmlCompletionItem[] data = new XmlCompletionItem[Count]; XmlCompletionItem[] data = new XmlCompletionItem[Count];

16
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespace.cs

@ -14,8 +14,8 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public class XmlNamespace public class XmlNamespace
{ {
string prefix = string.Empty; string prefix = String.Empty;
string uri = string.Empty; string uri = String.Empty;
const string prefixToStringStart = "Prefix ["; const string prefixToStringStart = "Prefix [";
const string uriToStringMiddle = "] Uri ["; const string uriToStringMiddle = "] Uri [";
@ -27,20 +27,16 @@ namespace ICSharpCode.XmlEditor
} }
public string Prefix { public string Prefix {
get { get { return prefix; }
return prefix;
}
} }
public string Uri { public string Uri {
get { get { return uri; }
return uri;
}
} }
public override string ToString() public override string ToString()
{ {
return string.Concat(prefixToStringStart, prefix, uriToStringMiddle, uri, "]"); return String.Concat(prefixToStringStart, prefix, uriToStringMiddle, uri, "]");
} }
/// <summary> /// <summary>
@ -60,7 +56,7 @@ namespace ICSharpCode.XmlEditor
return new XmlNamespace(prefix, uri); return new XmlNamespace(prefix, uri);
} }
} }
return new XmlNamespace(string.Empty, string.Empty); return new XmlNamespace(String.Empty, String.Empty);
} }
} }
} }

334
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs

@ -119,15 +119,12 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public static string GetUri(string fileName) public static string GetUri(string fileName)
{ {
string uri = String.Empty;
if (fileName != null) { if (fileName != null) {
if (fileName.Length > 0) { if (fileName.Length > 0) {
uri = String.Concat("file:///", fileName.Replace('\\', '/')); return String.Concat("file:///", fileName.Replace('\\', '/'));
} }
} }
return String.Empty;
return uri;
} }
/// <summary> /// <summary>
@ -135,7 +132,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public DefaultCompletionItemList GetElementCompletionData() public DefaultCompletionItemList GetElementCompletionData()
{ {
return GetElementCompletionData(string.Empty); return GetElementCompletionData(String.Empty);
} }
/// <summary> /// <summary>
@ -153,7 +150,7 @@ namespace ICSharpCode.XmlEditor
} }
} }
var list = new XmlCompletionItemList(); XmlCompletionItemList list = new XmlCompletionItemList();
list.Items.AddRange(data.ToArray()); list.Items.AddRange(data.ToArray());
list.SortItems(); list.SortItems();
@ -166,18 +163,16 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public ICompletionItem[] GetAttributeCompletionData(XmlElementPath path) public ICompletionItem[] GetAttributeCompletionData(XmlElementPath path)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
// Locate matching element. // Locate matching element.
XmlSchemaElement element = FindElement(path); XmlSchemaElement element = FindElement(path);
// Get completion data. // Get completion data.
if (element != null) { if (element != null) {
prohibitedAttributes.Clear(); prohibitedAttributes.Clear();
data = GetAttributeCompletionData(element); return GetAttributeCompletionData(element).ToArray();
} }
return data.ToArray(); return new ICompletionItem[0];
} }
/// <summary> /// <summary>
@ -186,17 +181,15 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public ICompletionItem[] GetChildElementCompletionData(XmlElementPath path) public ICompletionItem[] GetChildElementCompletionData(XmlElementPath path)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
// Locate matching element. // Locate matching element.
XmlSchemaElement element = FindElement(path); XmlSchemaElement element = FindElement(path);
// Get completion data. // Get completion data.
if (element != null) { if (element != null) {
data = GetChildElementCompletionData(element, path.Elements.LastPrefix); return GetChildElementCompletionData(element, path.Elements.LastPrefix).ToArray();
} }
return data.ToArray(); return new ICompletionItem[0];
} }
/// <summary> /// <summary>
@ -204,17 +197,15 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public ICompletionItem[] GetAttributeValueCompletionData(XmlElementPath path, string name) public ICompletionItem[] GetAttributeValueCompletionData(XmlElementPath path, string name)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
// Locate matching element. // Locate matching element.
XmlSchemaElement element = FindElement(path); XmlSchemaElement element = FindElement(path);
// Get completion data. // Get completion data.
if (element != null) { if (element != null) {
data = GetAttributeValueCompletionData(element, name); return GetAttributeValueCompletionData(element, name).ToArray();
} }
return data.ToArray(); return new ICompletionItem[0];
} }
/// <summary> /// <summary>
@ -233,12 +224,12 @@ namespace ICSharpCode.XmlEditor
// Look for root element. // Look for root element.
element = FindElement(name); element = FindElement(name);
if (element == null) { if (element == null) {
break; return null;
} }
} else { } else {
element = FindChildElement(element, name); element = FindChildElement(element, name);
if (element == null) { if (element == null) {
break; return null;
} }
} }
} }
@ -281,12 +272,11 @@ namespace ICSharpCode.XmlEditor
/// <returns><see langword="null"/> if no attribute can be found.</returns> /// <returns><see langword="null"/> if no attribute can be found.</returns>
public XmlSchemaAttribute FindAttribute(XmlSchemaElement element, string name) public XmlSchemaAttribute FindAttribute(XmlSchemaElement element, string name)
{ {
XmlSchemaAttribute attribute = null;
XmlSchemaComplexType complexType = GetElementAsComplexType(element); XmlSchemaComplexType complexType = GetElementAsComplexType(element);
if (complexType != null) { if (complexType != null) {
attribute = FindAttribute(complexType, name); return FindAttribute(complexType, name);
} }
return attribute; return null;
} }
/// <summary> /// <summary>
@ -327,10 +317,10 @@ namespace ICSharpCode.XmlEditor
{ {
if (name != null) { if (name != null) {
foreach (XmlSchemaObject schemaObject in schema.Groups.Values) { foreach (XmlSchemaObject schemaObject in schema.Groups.Values) {
XmlSchemaGroup group = schemaObject as XmlSchemaGroup; XmlSchemaGroup schemaGroup = schemaObject as XmlSchemaGroup;
if (group != null) { if (schemaGroup != null) {
if (group.Name == name) { if (schemaGroup.Name == name) {
return group; return schemaGroup;
} }
} }
} }
@ -425,34 +415,25 @@ namespace ICSharpCode.XmlEditor
/// </remarks> /// </remarks>
XmlSchemaElement FindElement(XmlQualifiedName name) XmlSchemaElement FindElement(XmlQualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
foreach (XmlSchemaElement element in schema.Elements.Values) { foreach (XmlSchemaElement element in schema.Elements.Values) {
if (name.Equals(element.QualifiedName)) { if (name.Equals(element.QualifiedName)) {
matchedElement = element; return element;
break;
} }
} }
return null;
return matchedElement;
} }
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaElement element, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaElement element, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
XmlSchemaComplexType complexType = GetElementAsComplexType(element); XmlSchemaComplexType complexType = GetElementAsComplexType(element);
if (complexType != null) { if (complexType != null) {
data = GetChildElementCompletionData(complexType, prefix); return GetChildElementCompletionData(complexType, prefix);
} }
return new XmlCompletionItemCollection();
return data;
} }
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexType complexType, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexType complexType, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence; XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef;
@ -460,18 +441,17 @@ namespace ICSharpCode.XmlEditor
XmlSchemaAll all = complexType.Particle as XmlSchemaAll; XmlSchemaAll all = complexType.Particle as XmlSchemaAll;
if (sequence != null) { if (sequence != null) {
data = GetChildElementCompletionData(sequence.Items, prefix); return GetChildElementCompletionData(sequence.Items, prefix);
} else if (choice != null) { } else if (choice != null) {
data = GetChildElementCompletionData(choice.Items, prefix); return GetChildElementCompletionData(choice.Items, prefix);
} else if (complexContent != null) { } else if (complexContent != null) {
data = GetChildElementCompletionData(complexContent, prefix); return GetChildElementCompletionData(complexContent, prefix);
} else if (groupRef != null) { } else if (groupRef != null) {
data = GetChildElementCompletionData(groupRef, prefix); return GetChildElementCompletionData(groupRef, prefix);
} else if (all != null) { } else if (all != null) {
data = GetChildElementCompletionData(all.Items, prefix); return GetChildElementCompletionData(all.Items, prefix);
} }
return new XmlCompletionItemCollection();
return data;
} }
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaObjectCollection items, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaObjectCollection items, string prefix)
@ -516,28 +496,26 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContent complexContent, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContent complexContent, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
if (extension != null) { if (extension != null) {
data = GetChildElementCompletionData(extension, prefix); return GetChildElementCompletionData(extension, prefix);
} else { } else {
XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
if (restriction != null) { if (restriction != null) {
data = GetChildElementCompletionData(restriction, prefix); return GetChildElementCompletionData(restriction, prefix);
} }
} }
return new XmlCompletionItemCollection();
return data;
} }
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentExtension extension, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentExtension extension, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlCompletionItemCollection data;
XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName);
if (complexType != null) { if (complexType != null) {
data = GetChildElementCompletionData(complexType, prefix); data = GetChildElementCompletionData(complexType, prefix);
} else {
data = new XmlCompletionItemCollection();
} }
// Add any elements. // Add any elements.
@ -560,27 +538,22 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaGroupRef groupRef, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaGroupRef groupRef, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaGroup schemaGroup = FindGroup(groupRef.RefName.Name);
if (schemaGroup != null) {
XmlSchemaGroup group = FindGroup(groupRef.RefName.Name); XmlSchemaSequence sequence = schemaGroup.Particle as XmlSchemaSequence;
if (group != null) { XmlSchemaChoice choice = schemaGroup.Particle as XmlSchemaChoice;
XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = group.Particle as XmlSchemaChoice;
if(sequence != null) { if(sequence != null) {
data = GetChildElementCompletionData(sequence.Items, prefix); return GetChildElementCompletionData(sequence.Items, prefix);
} else if (choice != null) { } else if (choice != null) {
data = GetChildElementCompletionData(choice.Items, prefix); return GetChildElementCompletionData(choice.Items, prefix);
} }
} }
return new XmlCompletionItemCollection();
return data;
} }
XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentRestriction restriction, string prefix) XmlCompletionItemCollection GetChildElementCompletionData(XmlSchemaComplexContentRestriction restriction, string prefix)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection();
// Add any elements. // Add any elements.
if (restriction.Particle != null) { if (restriction.Particle != null) {
XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence;
@ -588,15 +561,14 @@ namespace ICSharpCode.XmlEditor
XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef;
if(sequence != null) { if(sequence != null) {
data = GetChildElementCompletionData(sequence.Items, prefix); return GetChildElementCompletionData(sequence.Items, prefix);
} else if (choice != null) { } else if (choice != null) {
data = GetChildElementCompletionData(choice.Items, prefix); return GetChildElementCompletionData(choice.Items, prefix);
} else if (groupRef != null) { } else if (groupRef != null) {
data = GetChildElementCompletionData(groupRef, prefix); return GetChildElementCompletionData(groupRef, prefix);
} }
} }
return new XmlCompletionItemCollection();
return data;
} }
/// <summary> /// <summary>
@ -607,7 +579,7 @@ namespace ICSharpCode.XmlEditor
{ {
if (!data.Contains(name)) { if (!data.Contains(name)) {
if (prefix.Length > 0) { if (prefix.Length > 0) {
name = string.Concat(prefix, ":", name); name = String.Concat(prefix, ":", name);
} }
XmlCompletionItem item = new XmlCompletionItem(name, documentation); XmlCompletionItem item = new XmlCompletionItem(name, documentation);
data.Add(item); data.Add(item);
@ -647,8 +619,6 @@ namespace ICSharpCode.XmlEditor
/// </remarks> /// </remarks>
static string GetDocumentation(XmlSchemaAnnotation annotation) static string GetDocumentation(XmlSchemaAnnotation annotation)
{ {
string documentation = string.Empty;
if (annotation != null) { if (annotation != null) {
StringBuilder documentationBuilder = new StringBuilder(); StringBuilder documentationBuilder = new StringBuilder();
foreach (XmlSchemaObject schemaObject in annotation.Items) { foreach (XmlSchemaObject schemaObject in annotation.Items) {
@ -666,17 +636,14 @@ namespace ICSharpCode.XmlEditor
} }
} }
} }
return documentationBuilder.ToString();
documentation = documentationBuilder.ToString();
} }
return String.Empty;
return documentation;
} }
XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaElement element) XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaElement element)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlCompletionItemCollection data = new XmlCompletionItemCollection();
XmlSchemaComplexType complexType = GetElementAsComplexType(element); XmlSchemaComplexType complexType = GetElementAsComplexType(element);
if (complexType != null) { if (complexType != null) {
@ -689,7 +656,6 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexContentRestriction restriction) XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexContentRestriction restriction)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlCompletionItemCollection data = new XmlCompletionItemCollection();
data.AddRange(GetAttributeCompletionData(restriction.Attributes)); data.AddRange(GetAttributeCompletionData(restriction.Attributes));
XmlSchemaComplexType baseComplexType = FindNamedType(schema, restriction.BaseTypeName); XmlSchemaComplexType baseComplexType = FindNamedType(schema, restriction.BaseTypeName);
@ -702,9 +668,7 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexType complexType) XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaComplexType complexType)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlCompletionItemCollection data = GetAttributeCompletionData(complexType.Attributes);
data = GetAttributeCompletionData(complexType.Attributes);
// Add any complex content attributes. // Add any complex content attributes.
XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent;
@ -754,9 +718,7 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaSimpleContentExtension extension) XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaSimpleContentExtension extension)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlCompletionItemCollection data = new XmlCompletionItemCollection();
data.AddRange(GetAttributeCompletionData(extension.Attributes)); data.AddRange(GetAttributeCompletionData(extension.Attributes));
return data; return data;
} }
@ -786,19 +748,16 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
bool IsProhibitedAttribute(XmlSchemaAttribute attribute) bool IsProhibitedAttribute(XmlSchemaAttribute attribute)
{ {
bool prohibited = false;
if (attribute.Use == XmlSchemaUse.Prohibited) { if (attribute.Use == XmlSchemaUse.Prohibited) {
prohibited = true; return true;
} else { } else {
foreach (XmlSchemaAttribute prohibitedAttribute in prohibitedAttributes) { foreach (XmlSchemaAttribute prohibitedAttribute in prohibitedAttributes) {
if (prohibitedAttribute.QualifiedName == attribute.QualifiedName) { if (prohibitedAttribute.QualifiedName == attribute.QualifiedName) {
prohibited = true; return true;
break;
} }
} }
} }
return false;
return prohibited;
} }
/// <summary> /// <summary>
@ -812,7 +771,7 @@ namespace ICSharpCode.XmlEditor
string name = attribute.Name; string name = attribute.Name;
if (name == null) { if (name == null) {
if (attribute.RefName.Namespace == "http://www.w3.org/XML/1998/namespace") { if (attribute.RefName.Namespace == "http://www.w3.org/XML/1998/namespace") {
name = string.Concat("xml:", attribute.RefName.Name); name = String.Concat("xml:", attribute.RefName.Name);
} }
} }
@ -828,44 +787,39 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaAttributeGroupRef groupRef) XmlCompletionItemCollection GetAttributeCompletionData(XmlSchemaAttributeGroupRef groupRef)
{ {
XmlCompletionItemCollection data = new XmlCompletionItemCollection(); XmlSchemaAttributeGroup attributeGroup = FindAttributeGroup(schema, groupRef.RefName.Name);
XmlSchemaAttributeGroup group = FindAttributeGroup(schema, groupRef.RefName.Name); if (attributeGroup != null) {
if (group != null) { return GetAttributeCompletionData(attributeGroup.Attributes);
data = GetAttributeCompletionData(group.Attributes);
} }
return new XmlCompletionItemCollection();
return data;
} }
static XmlSchemaComplexType FindNamedType(XmlSchema schema, XmlQualifiedName name) static XmlSchemaComplexType FindNamedType(XmlSchema schema, XmlQualifiedName name)
{ {
XmlSchemaComplexType matchedComplexType = null;
if (name != null) { if (name != null) {
foreach (XmlSchemaObject schemaObject in schema.Items) { foreach (XmlSchemaObject schemaObject in schema.Items) {
XmlSchemaComplexType complexType = schemaObject as XmlSchemaComplexType; XmlSchemaComplexType complexType = schemaObject as XmlSchemaComplexType;
if (complexType != null) { if (complexType != null) {
if (complexType.QualifiedName == name) { if (complexType.QualifiedName == name) {
matchedComplexType = complexType; return complexType;
break;
} }
} }
} }
// Try included schemas. // Try included schemas.
if (matchedComplexType == null) {
foreach (XmlSchemaExternal external in schema.Includes) { foreach (XmlSchemaExternal external in schema.Includes) {
XmlSchemaInclude include = external as XmlSchemaInclude; XmlSchemaInclude include = external as XmlSchemaInclude;
if (include != null) { if (include != null) {
if (include.Schema != null) { if (include.Schema != null) {
matchedComplexType = FindNamedType(include.Schema, name); XmlSchemaComplexType matchedComplexType = FindNamedType(include.Schema, name);
if (matchedComplexType != null) {
return matchedComplexType;
} }
} }
} }
} }
} }
return null;
return matchedComplexType;
} }
/// <summary> /// <summary>
@ -874,20 +828,15 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
XmlSchemaElement FindChildElement(XmlSchemaElement element, QualifiedName name) XmlSchemaElement FindChildElement(XmlSchemaElement element, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
XmlSchemaComplexType complexType = GetElementAsComplexType(element); XmlSchemaComplexType complexType = GetElementAsComplexType(element);
if (complexType != null) { if (complexType != null) {
matchedElement = FindChildElement(complexType, name); return FindChildElement(complexType, name);
} }
return null;
return matchedElement;
} }
XmlSchemaElement FindChildElement(XmlSchemaComplexType complexType, QualifiedName name) XmlSchemaElement FindChildElement(XmlSchemaComplexType complexType, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence; XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef;
@ -895,24 +844,23 @@ namespace ICSharpCode.XmlEditor
XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent;
if (sequence != null) { if (sequence != null) {
matchedElement = FindElement(sequence.Items, name); return FindElement(sequence.Items, name);
} else if (choice != null) { } else if (choice != null) {
matchedElement = FindElement(choice.Items, name); return FindElement(choice.Items, name);
} else if (complexContent != null) { } else if (complexContent != null) {
XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
if (extension != null) { if (extension != null) {
matchedElement = FindChildElement(extension, name); return FindChildElement(extension, name);
} else if (restriction != null) { } else if (restriction != null) {
matchedElement = FindChildElement(restriction, name); return FindChildElement(restriction, name);
} }
} else if (groupRef != null) { } else if (groupRef != null) {
matchedElement = FindElement(groupRef, name); return FindElement(groupRef, name);
} else if (all != null) { } else if (all != null) {
matchedElement = FindElement(all.Items, name); return FindElement(all.Items, name);
} }
return null;
return matchedElement;
} }
/// <summary> /// <summary>
@ -920,29 +868,26 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name) XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName);
if (complexType != null) { if (complexType != null) {
matchedElement = FindChildElement(complexType, name); XmlSchemaElement matchedElement = FindChildElement(complexType, name);
if (matchedElement == null) { if (matchedElement == null) {
XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence; XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice; XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef;
if (sequence != null) { if (sequence != null) {
matchedElement = FindElement(sequence.Items, name); return FindElement(sequence.Items, name);
} else if (choice != null) { } else if (choice != null) {
matchedElement = FindElement(choice.Items, name); return FindElement(choice.Items, name);
} else if (groupRef != null) { } else if (groupRef != null) {
matchedElement = FindElement(groupRef, name); return FindElement(groupRef, name);
} }
} else {
return matchedElement;
} }
} }
return null;
return matchedElement;
} }
/// <summary> /// <summary>
@ -950,17 +895,14 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
XmlSchemaElement FindChildElement(XmlSchemaComplexContentRestriction restriction, QualifiedName name) XmlSchemaElement FindChildElement(XmlSchemaComplexContentRestriction restriction, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence;
XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef;
if (sequence != null) { if (sequence != null) {
matchedElement = FindElement(sequence.Items, name); return FindElement(sequence.Items, name);
} else if (groupRef != null) { } else if (groupRef != null) {
matchedElement = FindElement(groupRef, name); return FindElement(groupRef, name);
} }
return null;
return matchedElement;
} }
/// <summary> /// <summary>
@ -968,18 +910,18 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
XmlSchemaElement FindElement(XmlSchemaObjectCollection items, QualifiedName name) XmlSchemaElement FindElement(XmlSchemaObjectCollection items, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
foreach (XmlSchemaObject schemaObject in items) { foreach (XmlSchemaObject schemaObject in items) {
XmlSchemaElement element = schemaObject as XmlSchemaElement; XmlSchemaElement element = schemaObject as XmlSchemaElement;
XmlSchemaSequence sequence = schemaObject as XmlSchemaSequence; XmlSchemaSequence sequence = schemaObject as XmlSchemaSequence;
XmlSchemaChoice choice = schemaObject as XmlSchemaChoice; XmlSchemaChoice choice = schemaObject as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = schemaObject as XmlSchemaGroupRef; XmlSchemaGroupRef groupRef = schemaObject as XmlSchemaGroupRef;
XmlSchemaElement matchedElement = null;
if (element != null) { if (element != null) {
if (element.Name != null) { if (element.Name != null) {
if (name.Name == element.Name) { if (name.Name == element.Name) {
matchedElement = element; return element;
} }
} else if (element.RefName != null) { } else if (element.RefName != null) {
if (name.Name == element.RefName.Name) { if (name.Name == element.RefName.Name) {
@ -1002,62 +944,52 @@ namespace ICSharpCode.XmlEditor
// Did we find a match? // Did we find a match?
if (matchedElement != null) { if (matchedElement != null) {
break; return matchedElement;
} }
} }
return null;
return matchedElement;
} }
XmlSchemaElement FindElement(XmlSchemaGroupRef groupRef, QualifiedName name) XmlSchemaElement FindElement(XmlSchemaGroupRef groupRef, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null; XmlSchemaGroup schemaGroup = FindGroup(groupRef.RefName.Name);
if (schemaGroup != null) {
XmlSchemaGroup group = FindGroup(groupRef.RefName.Name); XmlSchemaSequence sequence = schemaGroup.Particle as XmlSchemaSequence;
if (group != null) { XmlSchemaChoice choice = schemaGroup.Particle as XmlSchemaChoice;
XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = group.Particle as XmlSchemaChoice;
if(sequence != null) { if(sequence != null) {
matchedElement = FindElement(sequence.Items, name); return FindElement(sequence.Items, name);
} else if (choice != null) { } else if (choice != null) {
matchedElement = FindElement(choice.Items, name); return FindElement(choice.Items, name);
} }
} }
return null;
return matchedElement;
} }
static XmlSchemaAttributeGroup FindAttributeGroup(XmlSchema schema, string name) static XmlSchemaAttributeGroup FindAttributeGroup(XmlSchema schema, string name)
{ {
XmlSchemaAttributeGroup matchedGroup = null;
if (name != null) { if (name != null) {
foreach (XmlSchemaObject schemaObject in schema.Items) { foreach (XmlSchemaObject schemaObject in schema.Items) {
XmlSchemaAttributeGroup group = schemaObject as XmlSchemaAttributeGroup; XmlSchemaAttributeGroup attributeGroup = schemaObject as XmlSchemaAttributeGroup;
if (group != null) { if (attributeGroup != null) {
if (group.Name == name) { if (attributeGroup.Name == name) {
matchedGroup = group; return attributeGroup;
break;
} }
} }
} }
// Try included schemas. // Try included schemas.
if (matchedGroup == null) {
foreach (XmlSchemaExternal external in schema.Includes) { foreach (XmlSchemaExternal external in schema.Includes) {
XmlSchemaInclude include = external as XmlSchemaInclude; XmlSchemaInclude include = external as XmlSchemaInclude;
if (include != null) { if (include != null) {
if (include.Schema != null) { if (include.Schema != null) {
matchedGroup = FindAttributeGroup(include.Schema, name); return FindAttributeGroup(include.Schema, name);
}
} }
} }
} }
} }
return null;
return matchedGroup;
} }
XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaElement element, string name) XmlCompletionItemCollection GetAttributeValueCompletionData(XmlSchemaElement element, string name)
@ -1179,72 +1111,58 @@ namespace ICSharpCode.XmlEditor
XmlSchemaAttribute FindAttribute(XmlSchemaComplexType complexType, string name) XmlSchemaAttribute FindAttribute(XmlSchemaComplexType complexType, string name)
{ {
XmlSchemaAttribute matchedAttribute = null; XmlSchemaAttribute matchedAttribute = FindAttribute(complexType.Attributes, name);
matchedAttribute = FindAttribute(complexType.Attributes, name);
if (matchedAttribute == null) { if (matchedAttribute == null) {
XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent;
if (complexContent != null) { if (complexContent != null) {
matchedAttribute = FindAttribute(complexContent, name); return FindAttribute(complexContent, name);
} }
} }
return matchedAttribute; return matchedAttribute;
} }
XmlSchemaAttribute FindAttribute(XmlSchemaObjectCollection schemaObjects, string name) XmlSchemaAttribute FindAttribute(XmlSchemaObjectCollection schemaObjects, string name)
{ {
XmlSchemaAttribute matchedAttribute = null;
foreach (XmlSchemaObject schemaObject in schemaObjects) { foreach (XmlSchemaObject schemaObject in schemaObjects) {
XmlSchemaAttribute attribute = schemaObject as XmlSchemaAttribute; XmlSchemaAttribute attribute = schemaObject as XmlSchemaAttribute;
XmlSchemaAttributeGroupRef groupRef = schemaObject as XmlSchemaAttributeGroupRef; XmlSchemaAttributeGroupRef groupRef = schemaObject as XmlSchemaAttributeGroupRef;
if (attribute != null) { if (attribute != null) {
if (attribute.Name == name) { if (attribute.Name == name) {
matchedAttribute = attribute; return attribute;
break;
} }
} else if (groupRef != null) { } else if (groupRef != null) {
matchedAttribute = FindAttribute(groupRef, name); XmlSchemaAttribute matchedAttribute = FindAttribute(groupRef, name);
if (matchedAttribute != null) { if (matchedAttribute != null) {
break; return matchedAttribute;
} }
} }
} }
return null;
return matchedAttribute;
} }
XmlSchemaAttribute FindAttribute(XmlSchemaAttributeGroupRef groupRef, string name) XmlSchemaAttribute FindAttribute(XmlSchemaAttributeGroupRef groupRef, string name)
{ {
XmlSchemaAttribute matchedAttribute = null;
if (groupRef.RefName != null) { if (groupRef.RefName != null) {
XmlSchemaAttributeGroup group = FindAttributeGroup(schema, groupRef.RefName.Name); XmlSchemaAttributeGroup attributeGroup = FindAttributeGroup(schema, groupRef.RefName.Name);
if (group != null) { if (attributeGroup != null) {
matchedAttribute = FindAttribute(group.Attributes, name); return FindAttribute(attributeGroup.Attributes, name);
} }
} }
return null;
return matchedAttribute;
} }
XmlSchemaAttribute FindAttribute(XmlSchemaComplexContent complexContent, string name) XmlSchemaAttribute FindAttribute(XmlSchemaComplexContent complexContent, string name)
{ {
XmlSchemaAttribute matchedAttribute = null;
XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
if (extension != null) { if (extension != null) {
matchedAttribute = FindAttribute(extension, name); return FindAttribute(extension, name);
} else if (restriction != null) { } else if (restriction != null) {
matchedAttribute = FindAttribute(restriction, name); return FindAttribute(restriction, name);
} }
return null;
return matchedAttribute;
} }
XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentExtension extension, string name) XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentExtension extension, string name)
@ -1255,14 +1173,12 @@ namespace ICSharpCode.XmlEditor
XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentRestriction restriction, string name) XmlSchemaAttribute FindAttribute(XmlSchemaComplexContentRestriction restriction, string name)
{ {
XmlSchemaAttribute matchedAttribute = FindAttribute(restriction.Attributes, name); XmlSchemaAttribute matchedAttribute = FindAttribute(restriction.Attributes, name);
if (matchedAttribute == null) { if (matchedAttribute == null) {
XmlSchemaComplexType complexType = FindNamedType(schema, restriction.BaseTypeName); XmlSchemaComplexType complexType = FindNamedType(schema, restriction.BaseTypeName);
if (complexType != null) { if (complexType != null) {
matchedAttribute = FindAttribute(complexType, name); return FindAttribute(complexType, name);
} }
} }
return matchedAttribute; return matchedAttribute;
} }
@ -1296,28 +1212,24 @@ namespace ICSharpCode.XmlEditor
XmlSchemaSimpleType FindSimpleType(XmlQualifiedName name) XmlSchemaSimpleType FindSimpleType(XmlQualifiedName name)
{ {
XmlSchemaSimpleType matchedSimpleType = null;
foreach (XmlSchemaObject schemaObject in schema.SchemaTypes.Values) { foreach (XmlSchemaObject schemaObject in schema.SchemaTypes.Values) {
XmlSchemaSimpleType simpleType = schemaObject as XmlSchemaSimpleType; XmlSchemaSimpleType simpleType = schemaObject as XmlSchemaSimpleType;
if (simpleType != null) { if (simpleType != null) {
if (simpleType.QualifiedName == name) { if (simpleType.QualifiedName == name) {
matchedSimpleType = simpleType; return simpleType;
break;
} }
} }
} }
return null;
return matchedSimpleType;
} }
/// <summary> /// <summary>
/// Adds any elements that have the specified substitution group. /// Adds any elements that have the specified substitution group.
/// </summary> /// </summary>
void AddSubstitionGroupElements(XmlCompletionItemCollection data, XmlQualifiedName group, string prefix) void AddSubstitionGroupElements(XmlCompletionItemCollection data, XmlQualifiedName groupName, string prefix)
{ {
foreach (XmlSchemaElement element in schema.Elements.Values) { foreach (XmlSchemaElement element in schema.Elements.Values) {
if (element.SubstitutionGroup == group) { if (element.SubstitutionGroup == groupName) {
AddElement(data, element.Name, prefix, element.Annotation); AddElement(data, element.Name, prefix, element.Annotation);
} }
} }
@ -1326,22 +1238,18 @@ namespace ICSharpCode.XmlEditor
/// <summary> /// <summary>
/// Looks for the substitution group element of the specified name. /// Looks for the substitution group element of the specified name.
/// </summary> /// </summary>
XmlSchemaElement FindSubstitutionGroupElement(XmlQualifiedName group, QualifiedName name) XmlSchemaElement FindSubstitutionGroupElement(XmlQualifiedName groupName, QualifiedName name)
{ {
XmlSchemaElement matchedElement = null;
foreach (XmlSchemaElement element in schema.Elements.Values) { foreach (XmlSchemaElement element in schema.Elements.Values) {
if (element.SubstitutionGroup == group) { if (element.SubstitutionGroup == groupName) {
if (element.Name != null) { if (element.Name != null) {
if (element.Name == name.Name) { if (element.Name == name.Name) {
matchedElement = element; return element;
break;
} }
} }
} }
} }
return null;
return matchedElement;
} }
} }
} }

15
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionDataCollection.cs

@ -69,9 +69,7 @@ namespace ICSharpCode.XmlEditor
/// <param name='namespaceUri'>The schema's namespace URI.</param> /// <param name='namespaceUri'>The schema's namespace URI.</param>
/// <value>The entry with the specified namespace URI.</value> /// <value>The entry with the specified namespace URI.</value>
public XmlSchemaCompletionData this[string namespaceUri] { public XmlSchemaCompletionData this[string namespaceUri] {
get { get { return GetItem(namespaceUri); }
return GetItem(namespaceUri);
}
} }
/// <summary> /// <summary>
@ -118,17 +116,12 @@ namespace ICSharpCode.XmlEditor
XmlSchemaCompletionData GetItem(string namespaceUri) XmlSchemaCompletionData GetItem(string namespaceUri)
{ {
XmlSchemaCompletionData matchedItem = null; foreach(XmlSchemaCompletionData item in this) {
foreach(XmlSchemaCompletionData item in this)
{
if (item.NamespaceUri == namespaceUri) { if (item.NamespaceUri == namespaceUri) {
matchedItem = item; return item;
break;
} }
} }
return null;
return matchedItem;
} }
} }
} }

1
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/EmptyXmlSchemasPanelTestFixture.cs

@ -19,7 +19,6 @@ namespace XmlEditor.Tests.Editor
[TestFixture] [TestFixture]
public class EmptyXmlSchemasPanelTestFixture public class EmptyXmlSchemasPanelTestFixture
{ {
Button removeSchemaButton;
MockXmlSchemasPanel panel; MockXmlSchemasPanel panel;
RegisteredXmlSchemasEditor schemasEditor; RegisteredXmlSchemasEditor schemasEditor;

Loading…
Cancel
Save