Browse Source

Fix xml completion for SubstitutionGroup elements.

pull/33/merge
Matt Ward 13 years ago
parent
commit
d8e27befb9
  1. 14
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  2. 1134
      src/AddIns/DisplayBindings/XmlEditor/Test/Resources/xslt.xsd
  3. 48
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsltSchemaTests.cs
  4. 8
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/ResourceManager.cs
  5. 4
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
  6. 2
      src/AddIns/DisplayBindings/XmlEditor/XmlEditor.sln

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

@ -335,11 +335,23 @@ namespace ICSharpCode.XmlEditor @@ -335,11 +335,23 @@ namespace ICSharpCode.XmlEditor
{
XmlSchemaComplexType complexType = element.SchemaType as XmlSchemaComplexType;
if (complexType == null) {
complexType = FindNamedType(schema, element.SchemaTypeName);
if (element.SchemaTypeName.IsEmpty) {
return GetComplexTypeFromSubstitutionGroup(element);
}
return FindNamedType(schema, element.SchemaTypeName);
}
return complexType;
}
XmlSchemaComplexType GetComplexTypeFromSubstitutionGroup(XmlSchemaElement element)
{
if (!element.SubstitutionGroup.IsEmpty) {
XmlSchemaElement substitutedElement = FindElement(element.SubstitutionGroup);
return GetElementAsComplexType(substitutedElement);
}
return null;
}
/// <summary>
/// Handler for schema validation errors.
/// </summary>

1134
src/AddIns/DisplayBindings/XmlEditor/Test/Resources/xslt.xsd

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using XmlEditor.Tests.Utils;
namespace XmlEditor.Tests.Schema
{
[TestFixture]
public class XsltSchemaTests
{
string namespaceURI = "http://www.w3.org/1999/XSL/Transform";
XmlSchemaCompletion schemaCompletion;
[TestFixtureSetUp]
public void SetUp()
{
schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsltSchema());
}
[Test]
public void GetChildElementCompletion_StylesheetElement_SubstitutionGroupUsedForTemplateAndTemplateElementReturned()
{
var path = new XmlElementPath();
path.AddElement(new QualifiedName("stylesheet", namespaceURI));
XmlCompletionItemCollection completionItems = schemaCompletion.GetChildElementCompletion(path);
bool contains = completionItems.Contains("template");
Assert.IsTrue(contains);
}
[Test]
public void GetAttributeCompletion_TemplateElementIsChildOfStylesheetElement_SubstitutionGroupUsedForTemplateAndMatchAttributeReturned()
{
var path = new XmlElementPath();
path.AddElement(new QualifiedName("stylesheet", namespaceURI));
path.AddElement(new QualifiedName("template", namespaceURI));
XmlCompletionItemCollection completionItems = schemaCompletion.GetAttributeCompletion(path);
bool contains = completionItems.Contains("match");
Assert.IsTrue(contains);
}
}
}

8
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/ResourceManager.cs

@ -35,6 +35,14 @@ namespace XmlEditor.Tests.Utils @@ -35,6 +35,14 @@ namespace XmlEditor.Tests.Utils
return manager.ReadXml("XMLSchema.xsd");
}
/// <summary>
/// Reads the XSL Transforms schema.
/// </summary>
public static StreamReader ReadXsltSchema()
{
return manager.ReadXml("xslt.xsd");
}
/// <summary>
/// Returns the xml read from the specified file which is embedded
/// in this assembly as a resource.

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

@ -168,6 +168,7 @@ @@ -168,6 +168,7 @@
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
<Compile Include="Schema\ElementWithAttributeSchemaTestFixture.cs" />
<Compile Include="Schema\NestedElementSchemaTestFixture.cs" />
<Compile Include="Schema\XsltSchemaTests.cs" />
<Compile Include="Schema\TwoElementSchemaTestFixture.cs" />
<Compile Include="Schema\ReferencedElementsTestFixture.cs" />
<Compile Include="Schema\NamespaceCompletionTestFixture.cs" />
@ -386,5 +387,8 @@ @@ -386,5 +387,8 @@
<Folder Include="FindSchemaObject" />
<Folder Include="Tree" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\xslt.xsd" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

2
src/AddIns/DisplayBindings/XmlEditor/XmlEditor.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.1.0.7289-alpha
# SharpDevelop 4.3
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "Project\XmlEditor.csproj", "{DCA2703D-250A-463E-A68A-07ED105AE6BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor.Tests", "Test\XmlEditor.Tests.csproj", "{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}"

Loading…
Cancel
Save