Browse Source

Added support for attributes defined in the simple content extension's base type.

Added support for attribute references that use a different schema namespace and need to have a prefix.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5324 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
94944b0dd6
  1. 10
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespaceCollection.cs
  2. 73
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  3. 18
      src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceCollectionTests.cs
  4. 85
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SimpleContentExtensionBaseTypeWithAttributeTestFixture.cs
  5. 1
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

10
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlNamespaceCollection.cs

@ -32,5 +32,15 @@ namespace ICSharpCode.XmlEditor @@ -32,5 +32,15 @@ namespace ICSharpCode.XmlEditor
}
return String.Empty;
}
public string GetPrefix(string namespaceToMatch)
{
foreach (XmlNamespace ns in this) {
if (ns.Name == namespaceToMatch) {
return ns.Prefix;
}
}
return String.Empty;
}
}
}

73
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -158,7 +158,7 @@ namespace ICSharpCode.XmlEditor @@ -158,7 +158,7 @@ namespace ICSharpCode.XmlEditor
// Get completion data.
if (element != null) {
prohibitedAttributes.Clear();
return GetAttributeCompletion(element);
return GetAttributeCompletion(element, path.NamespacesInScope);
}
return new XmlCompletionItemCollection();
@ -593,34 +593,31 @@ namespace ICSharpCode.XmlEditor @@ -593,34 +593,31 @@ namespace ICSharpCode.XmlEditor
}
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaElement element)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaElement element, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
XmlSchemaComplexType complexType = GetElementAsComplexType(element);
XmlSchemaComplexType complexType = GetElementAsComplexType(element);
if (complexType != null) {
completionItems.AddRange(GetAttributeCompletion(complexType));
completionItems.AddRange(GetAttributeCompletion(complexType, namespacesInScope));
}
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexContentRestriction restriction)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexContentRestriction restriction, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
completionItems.AddRange(GetAttributeCompletion(restriction.Attributes));
XmlSchemaComplexType baseComplexType = FindNamedType(schema, restriction.BaseTypeName);
if (baseComplexType != null) {
completionItems.AddRange(GetAttributeCompletion(baseComplexType));
}
completionItems.AddRange(GetAttributeCompletion(restriction.Attributes, namespacesInScope));
completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(restriction.BaseTypeName, namespacesInScope));
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexType complexType)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexType complexType, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = GetAttributeCompletion(complexType.Attributes);
XmlCompletionItemCollection completionItems = GetAttributeCompletion(complexType.Attributes, namespacesInScope);
// Add any complex content attributes.
XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent;
@ -628,53 +625,62 @@ namespace ICSharpCode.XmlEditor @@ -628,53 +625,62 @@ namespace ICSharpCode.XmlEditor
XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension;
XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction;
if (extension != null) {
completionItems.AddRange(GetAttributeCompletion(extension));
completionItems.AddRange(GetAttributeCompletion(extension, namespacesInScope));
} else if (restriction != null) {
completionItems.AddRange(GetAttributeCompletion(restriction));
completionItems.AddRange(GetAttributeCompletion(restriction, namespacesInScope));
}
} else {
XmlSchemaSimpleContent simpleContent = complexType.ContentModel as XmlSchemaSimpleContent;
if (simpleContent != null) {
completionItems.AddRange(GetAttributeCompletion(simpleContent));
completionItems.AddRange(GetAttributeCompletion(simpleContent, namespacesInScope));
}
}
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexContentExtension extension)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaComplexContentExtension extension, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
completionItems.AddRange(GetAttributeCompletion(extension.Attributes));
XmlSchemaComplexType baseComplexType = FindNamedType(schema, extension.BaseTypeName);
if (baseComplexType != null) {
completionItems.AddRange(GetAttributeCompletion(baseComplexType));
}
completionItems.AddRange(GetAttributeCompletion(extension.Attributes, namespacesInScope));
completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(extension.BaseTypeName, namespacesInScope));
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContent simpleContent)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContent simpleContent, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
XmlSchemaSimpleContentExtension extension = simpleContent.Content as XmlSchemaSimpleContentExtension;
if (extension != null) {
completionItems.AddRange(GetAttributeCompletion(extension));
completionItems.AddRange(GetAttributeCompletion(extension, namespacesInScope));
}
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContentExtension extension)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaSimpleContentExtension extension, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
completionItems.AddRange(GetAttributeCompletion(extension.Attributes));
completionItems.AddRange(GetAttributeCompletion(extension.Attributes, namespacesInScope));
completionItems.AddRange(GetBaseComplexTypeAttributeCompletion(extension.BaseTypeName, namespacesInScope));
return completionItems;
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaObjectCollection attributes)
XmlCompletionItemCollection GetBaseComplexTypeAttributeCompletion(XmlQualifiedName baseTypeName, XmlNamespaceCollection namespacesInScope)
{
XmlSchemaComplexType baseComplexType = FindNamedType(schema, baseTypeName);
if (baseComplexType != null) {
return GetAttributeCompletion(baseComplexType, namespacesInScope);
}
return new XmlCompletionItemCollection();
}
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaObjectCollection attributes, XmlNamespaceCollection namespacesInScope)
{
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
@ -683,12 +689,12 @@ namespace ICSharpCode.XmlEditor @@ -683,12 +689,12 @@ namespace ICSharpCode.XmlEditor
XmlSchemaAttributeGroupRef attributeGroupRef = schemaObject as XmlSchemaAttributeGroupRef;
if (attribute != null) {
if (!IsProhibitedAttribute(attribute)) {
AddAttribute(completionItems, attribute);
AddAttribute(completionItems, attribute, namespacesInScope);
} else {
prohibitedAttributes.Add(attribute);
}
} else if (attributeGroupRef != null) {
completionItems.AddRange(GetAttributeCompletion(attributeGroupRef));
completionItems.AddRange(GetAttributeCompletion(attributeGroupRef, namespacesInScope));
}
}
return completionItems;
@ -718,12 +724,17 @@ namespace ICSharpCode.XmlEditor @@ -718,12 +724,17 @@ namespace ICSharpCode.XmlEditor
/// <remarks>
/// Note the special handling of xml:lang attributes.
/// </remarks>
static void AddAttribute(XmlCompletionItemCollection completionItems, XmlSchemaAttribute attribute)
void AddAttribute(XmlCompletionItemCollection completionItems, XmlSchemaAttribute attribute, XmlNamespaceCollection namespacesInScope)
{
string name = attribute.Name;
if (name == null) {
if (attribute.RefName.Namespace == "http://www.w3.org/XML/1998/namespace") {
name = String.Concat("xml:", attribute.RefName.Name);
} else {
string prefix = namespacesInScope.GetPrefix(attribute.RefName.Namespace);
if (!String.IsNullOrEmpty(prefix)) {
name = String.Concat(prefix, ":", attribute.RefName.Name);
}
}
}
@ -737,11 +748,11 @@ namespace ICSharpCode.XmlEditor @@ -737,11 +748,11 @@ namespace ICSharpCode.XmlEditor
/// <summary>
/// Gets attribute completion data from a group ref.
/// </summary>
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaAttributeGroupRef groupRef)
XmlCompletionItemCollection GetAttributeCompletion(XmlSchemaAttributeGroupRef groupRef, XmlNamespaceCollection namespacesInScope)
{
XmlSchemaAttributeGroup attributeGroup = FindAttributeGroup(schema, groupRef.RefName.Name);
if (attributeGroup != null) {
return GetAttributeCompletion(attributeGroup.Attributes);
return GetAttributeCompletion(attributeGroup.Attributes, namespacesInScope);
}
return new XmlCompletionItemCollection();
}

18
src/AddIns/DisplayBindings/XmlEditor/Test/Paths/XmlNamespaceCollectionTests.cs

@ -83,5 +83,23 @@ namespace XmlEditor.Tests.Paths @@ -83,5 +83,23 @@ namespace XmlEditor.Tests.Paths
Assert.IsFalse(namespaceCollection.Contains(unknownNamespace));
}
[Test]
public void GetPrefixReturnsNamespaceForKnownNamespaceInCollection()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
Assert.AreEqual("prefix", namespaceCollection.GetPrefix("namespace"));
}
[Test]
public void GetPrefixReturnsEmptyStringForUnknownNamespaceInCollection()
{
XmlNamespace ns = new XmlNamespace("prefix", "namespace");
namespaceCollection.Add(ns);
Assert.AreEqual(String.Empty, namespaceCollection.GetPrefix("unknown-namespace"));
}
}
}

85
src/AddIns/DisplayBindings/XmlEditor/Test/Schema/SimpleContentExtensionBaseTypeWithAttributeTestFixture.cs

@ -0,0 +1,85 @@ @@ -0,0 +1,85 @@
// <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 System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Schema
{
[TestFixture]
public class SimpleContentExtensionBaseTypeWithAttributeTestFixture : SchemaTestFixtureBase
{
XmlCompletionItemCollection linkElementAttributes;
string schemaNamespace = "http://ddue.schemas.microsoft.com/authoring/2003/5";
public override void FixtureInit()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("link", schemaNamespace));
path.NamespacesInScope.Add(new XmlNamespace("xlink", "http://www.w3.org/1999/xlink"));
linkElementAttributes = SchemaCompletion.GetAttributeCompletion(path);
linkElementAttributes.Sort();
}
[Test]
public void LinkElementHasAddressAndXlinkHrefAttribute()
{
XmlCompletionItemCollection expectedAttributes = new XmlCompletionItemCollection();
expectedAttributes.Add(new XmlCompletionItem("address", XmlCompletionItemType.XmlAttribute));
expectedAttributes.Add(new XmlCompletionItem("xlink:href", XmlCompletionItemType.XmlAttribute));
Assert.AreEqual(expectedAttributes.ToArray(), linkElementAttributes.ToArray());
}
protected override string GetSchema()
{
return
"<schema xmlns='http://www.w3.org/2001/XMLSchema'\r\n" +
" xmlns:maml='http://ddue.schemas.microsoft.com/authoring/2003/5' \r\n" +
" xmlns:doc='http://ddue.schemas.microsoft.com/authoring/internal'\r\n" +
" xmlns:xlink='http://www.w3.org/1999/xlink'\r\n" +
" targetNamespace='http://ddue.schemas.microsoft.com/authoring/2003/5' \r\n" +
" elementFormDefault='qualified'\r\n" +
" attributeFormDefault='unqualified'>\r\n" +
"\r\n" +
"<element ref='maml:link' />\r\n" +
"<element name='link' type='maml:inlineLinkType' />\r\n" +
"<element name='legacyLink' type='maml:inlineLinkType' />\r\n" +
"\r\n" +
"<complexType name='inlineLinkType' mixed='true'>\r\n" +
" <simpleContent>\r\n" +
" <extension base='maml:textType'>\r\n" +
" <attributeGroup ref='maml:linkingGroup' />\r\n" +
" </extension>\r\n" +
" </simpleContent>\r\n" +
"</complexType>\r\n" +
"\r\n" +
"<complexType name='textType'>\r\n" +
" <simpleContent>\r\n" +
" <extension base='normalizedString'>\r\n" +
" <attributeGroup ref='maml:contentIdentificationSharingAndConditionGroup'/>\r\n" +
" </extension>\r\n" +
" </simpleContent>\r\n" +
"</complexType>\r\n" +
"\r\n" +
"<attributeGroup name='contentIdentificationSharingAndConditionGroup'>\r\n" +
" <attributeGroup ref='maml:addressAttributeGroup'/>\r\n" +
"</attributeGroup>\r\n" +
"\r\n" +
" <attributeGroup name='addressAttributeGroup'>\r\n" +
" <attribute name='address' type='ID'/>\r\n" +
" </attributeGroup>\r\n" +
"\r\n" +
" <attributeGroup name='linkingGroup'>\r\n" +
" <attribute ref='xlink:href'/>\r\n" +
" </attributeGroup>\r\n" +
"</schema>";
}
}
}

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

@ -158,6 +158,7 @@ @@ -158,6 +158,7 @@
<Compile Include="Schema.Multiple\TwoSchemaChildElementCompletionTestFixture.cs" />
<Compile Include="Schema\ElementAnnotationWithWhitespaceTestFixture.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SimpleContentExtensionBaseTypeWithAttributeTestFixture.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />
<Compile Include="Schema\NestedElementSchemaTestFixture.cs" />

Loading…
Cancel
Save