Browse Source

SD2-758. XML element completion now working for xs:all child elements.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.0@1303 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 20 years ago
parent
commit
2c64f4131b
  1. 16
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionData.cs
  2. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs
  3. 54
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs
  4. 48
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs
  5. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

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

@ -320,6 +320,7 @@ namespace ICSharpCode.XmlEditor @@ -320,6 +320,7 @@ namespace ICSharpCode.XmlEditor
XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef;
XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent;
XmlSchemaAll all = complexType.Particle as XmlSchemaAll;
if (sequence != null) {
data = GetChildElementCompletionData(sequence.Items, prefix);
@ -329,6 +330,8 @@ namespace ICSharpCode.XmlEditor @@ -329,6 +330,8 @@ namespace ICSharpCode.XmlEditor
data = GetChildElementCompletionData(complexContent, prefix);
} else if (groupRef != null) {
data = GetChildElementCompletionData(groupRef, prefix);
} else if (all != null) {
data = GetChildElementCompletionData(all.Items, prefix);
}
return data;
@ -445,12 +448,15 @@ namespace ICSharpCode.XmlEditor @@ -445,12 +448,15 @@ namespace ICSharpCode.XmlEditor
if (restriction.Particle != null) {
XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence;
XmlSchemaChoice choice = restriction.Particle as XmlSchemaChoice;
XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef;
if(sequence != null) {
data = GetChildElementCompletionData(sequence.Items, prefix);
} else if (choice != null) {
data = GetChildElementCompletionData(choice.Items, prefix);
}
} else if (groupRef != null) {
data = GetChildElementCompletionData(groupRef, prefix);
}
}
return data;
@ -765,7 +771,6 @@ namespace ICSharpCode.XmlEditor @@ -765,7 +771,6 @@ namespace ICSharpCode.XmlEditor
return matchedComplexType;
}
/// <summary>
/// Finds an element that matches the specified <paramref name="name"/>
/// from the children of the given <paramref name="element"/>.
@ -847,10 +852,13 @@ namespace ICSharpCode.XmlEditor @@ -847,10 +852,13 @@ namespace ICSharpCode.XmlEditor
{
XmlSchemaElement matchedElement = null;
XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence;
XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef;
if (sequence != null) {
matchedElement = FindElement(sequence.Items, name);
}
} else if (groupRef != null) {
matchedElement = FindElement(groupRef, name);
}
return matchedElement;
}

8
src/AddIns/DisplayBindings/XmlEditor/Test/Parser/AttributeNameTestFixture.cs

@ -86,6 +86,12 @@ namespace XmlEditor.Tests.Parser @@ -86,6 +86,12 @@ namespace XmlEditor.Tests.Parser
{
string text = " a";
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(text, text.Length), "Should have retrieved the attribute name 'foo'");
}
}
[Test]
public void EmptyString()
{
Assert.AreEqual(String.Empty, XmlParser.GetAttributeName(String.Empty, 10));
}
}
}

54
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/AllElementTestFixture.cs

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using System;
using System.IO;
namespace XmlEditor.Tests.Schema
{
/// <summary>
/// Tests that element completion works for any child elements
/// inside an xs:all schema element.
/// </summary>
[TestFixture]
public class AllElementTestFixture : SchemaTestFixtureBase
{
ICompletionData[] personElementChildren;
public override void FixtureInit()
{
XmlElementPath path = new XmlElementPath();
path.Elements.Add(new QualifiedName("person", "http://foo"));
personElementChildren = SchemaCompletionData.GetChildElementCompletionData(path);
}
[Test]
public void PersonElementHasTwoChildElements()
{
Assert.AreEqual(2, personElementChildren.Length,
"Should be 2 child elements.");
}
protected override string GetSchema()
{
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\" targetNamespace=\"http://foo\">\r\n" +
" <xs:element name=\"person\">\r\n" +
" <xs:complexType>\r\n" +
" <xs:all>\r\n" +
" <xs:element name=\"firstname\" type=\"xs:string\"/>\r\n" +
" <xs:element name=\"lastname\" type=\"xs:string\"/>\r\n" +
" </xs:all>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
"</xs:schema>";
}
}
}

48
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs

@ -26,6 +26,8 @@ namespace XmlEditor.Tests.Schema @@ -26,6 +26,8 @@ namespace XmlEditor.Tests.Schema
XmlElementPath elementPath;
XmlElementPath simpleEnumPath;
XmlElementPath enumPath;
XmlElementPath allElementPath;
XmlElementPath allElementAnnotationPath;
ICompletionData[] choiceAttributes;
ICompletionData[] elementAttributes;
ICompletionData[] simpleEnumElements;
@ -35,6 +37,8 @@ namespace XmlEditor.Tests.Schema @@ -35,6 +37,8 @@ namespace XmlEditor.Tests.Schema
ICompletionData[] finalDefaultAttributeValues;
ICompletionData[] mixedAttributeValues;
ICompletionData[] maxOccursAttributeValues;
ICompletionData[] allElementChildElements;
ICompletionData[] allElementAnnotationChildElements;
string namespaceURI = "http://www.w3.org/2001/XMLSchema";
string prefix = "xs";
@ -90,6 +94,27 @@ namespace XmlEditor.Tests.Schema @@ -90,6 +94,27 @@ namespace XmlEditor.Tests.Schema
// Get attributes.
enumAttributes = schemaCompletionData.GetAttributeCompletionData(enumPath);
// Set up xs:all path.
allElementPath = new XmlElementPath();
allElementPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix));
allElementPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix));
// Get child elements of the xs:all element.
allElementChildElements = schemaCompletionData.GetChildElementCompletionData(allElementPath);
// Set up the path to the annotation element that is a child of xs:all.
allElementAnnotationPath = new XmlElementPath();
allElementAnnotationPath.Elements.Add(new QualifiedName("schema", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("element", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("complexType", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("all", namespaceURI, prefix));
allElementAnnotationPath.Elements.Add(new QualifiedName("annotation", namespaceURI, prefix));
// Get the xs:all annotation child element.
allElementAnnotationChildElements = schemaCompletionData.GetChildElementCompletionData(allElementAnnotationPath);
}
[Test]
@ -206,6 +231,27 @@ namespace XmlEditor.Tests.Schema @@ -206,6 +231,27 @@ namespace XmlEditor.Tests.Schema
{
Assert.IsTrue(SchemaTestFixtureBase.Contains(maxOccursAttributeValues, "unbounded"),
"Attribute value 'unbounded' missing.");
}
}
[Test]
public void AllElementHasAnnotationChildElement()
{
Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementChildElements, "xs:annotation"),
"Should have an annotation child element.");
}
[Test]
public void AllElementHasElementChildElement()
{
Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementChildElements, "xs:element"),
"Should have an child element called 'element'.");
}
[Test]
public void AllElementAnnotationHasDocumentationChildElement()
{
Assert.IsTrue(SchemaTestFixtureBase.Contains(allElementAnnotationChildElements, "xs:documentation"),
"Should have documentation child element.");
}
}
}

1
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -90,6 +90,7 @@ @@ -90,6 +90,7 @@
<Compile Include="Schema\AbstractElementTestFixture.cs" />
<Compile Include="Utils\SchemaIncludeTestFixtureHelper.cs" />
<Compile Include="Schema\MissingSchemaElementTestFixture.cs" />
<Compile Include="Schema\AllElementTestFixture.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Schema\" />

Loading…
Cancel
Save