Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5323 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
5 changed files with 141 additions and 31 deletions
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
// <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 System.Text; |
||||
using System.Xml; |
||||
using System.Xml.Schema; |
||||
|
||||
namespace ICSharpCode.XmlEditor |
||||
{ |
||||
public class SchemaDocumentation |
||||
{ |
||||
XmlSchemaAnnotation annotation; |
||||
StringBuilder documentation = new StringBuilder(); |
||||
StringBuilder documentationWithoutWhitespace = new StringBuilder(); |
||||
|
||||
public SchemaDocumentation(XmlSchemaAnnotation annotation) |
||||
{ |
||||
this.annotation = annotation; |
||||
if (annotation != null) { |
||||
ReadDocumentationFromAnnotation(annotation.Items); |
||||
} |
||||
} |
||||
|
||||
void ReadDocumentationFromAnnotation(XmlSchemaObjectCollection annotationItems) |
||||
{ |
||||
foreach (XmlSchemaObject schemaObject in annotationItems) { |
||||
XmlSchemaDocumentation schemaDocumentation = schemaObject as XmlSchemaDocumentation; |
||||
if (schemaDocumentation != null) { |
||||
ReadSchemaDocumentationFromMarkup(schemaDocumentation.Markup); |
||||
} |
||||
} |
||||
RemoveWhitespaceFromDocumentation(); |
||||
} |
||||
|
||||
void ReadSchemaDocumentationFromMarkup(XmlNode[] markup) |
||||
{ |
||||
foreach (XmlNode node in markup) { |
||||
XmlText textNode = node as XmlText; |
||||
AppendTextToDocumentation(textNode); |
||||
} |
||||
} |
||||
|
||||
void AppendTextToDocumentation(XmlText textNode) |
||||
{ |
||||
if (textNode != null) { |
||||
if (textNode.Data != null) { |
||||
documentation.Append(textNode.Data); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void RemoveWhitespaceFromDocumentation() |
||||
{ |
||||
string[] lines = documentation.ToString().Split('\n'); |
||||
RemoveWhitespaceFromLines(lines); |
||||
} |
||||
|
||||
void RemoveWhitespaceFromLines(string[] lines) |
||||
{ |
||||
foreach (string line in lines) { |
||||
string lineWithoutWhitespace = line.Trim(); |
||||
documentationWithoutWhitespace.AppendLine(lineWithoutWhitespace); |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return documentationWithoutWhitespace.ToString().Trim(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <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.SharpDevelop.Editor.CodeCompletion; |
||||
using ICSharpCode.XmlEditor; |
||||
using NUnit.Framework; |
||||
|
||||
namespace XmlEditor.Tests.Schema |
||||
{ |
||||
[TestFixture] |
||||
public class ElementAnnotationWithWhitespaceTestFixture : SchemaTestFixtureBase |
||||
{ |
||||
XmlCompletionItemCollection fooChildElementCompletionItems; |
||||
XmlCompletionItemCollection rootElementCompletionItems; |
||||
|
||||
public override void FixtureInit() |
||||
{ |
||||
rootElementCompletionItems = SchemaCompletion.GetRootElementCompletion(); |
||||
|
||||
XmlElementPath path = new XmlElementPath(); |
||||
path.AddElement(new QualifiedName("foo", "http://foo.com")); |
||||
|
||||
fooChildElementCompletionItems = SchemaCompletion.GetChildElementCompletion(path); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhitespaceRemovedFromAnnotation() |
||||
{ |
||||
string expectedText = |
||||
"First line\r\n" + |
||||
"Second line\r\n" + |
||||
"Third line\r\n" + |
||||
"Fourth line"; |
||||
Assert.AreEqual(expectedText, rootElementCompletionItems[0].Description); |
||||
} |
||||
|
||||
protected override string GetSchema() |
||||
{ |
||||
return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://foo.com\" xmlns=\"http://foo.com\" elementFormDefault=\"qualified\">\r\n" + |
||||
"\t<xs:element name=\"foo\">\r\n" + |
||||
"\t\t<xs:annotation>\r\n" + |
||||
"\t\t\t<xs:documentation>\r\n" + |
||||
"\t\t\tFirst line\r\n" + |
||||
"\t\t\tSecond line\r\n" + |
||||
" Third line\r\n" + |
||||
" Fourth line\r\n" + |
||||
"\t\t\t</xs:documentation>\r\n" + |
||||
"\t\t</xs:annotation>\r\n" + |
||||
"\t</xs:element>\r\n" + |
||||
"</xs:schema>"; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue