Skip to content

Commit

Permalink
XSD 1.1 working
Browse files Browse the repository at this point in the history
Fix #363

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jul 17, 2019
1 parent 2c6d46a commit 71caa64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
5 changes: 3 additions & 2 deletions org.eclipse.lsp4xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
</dependency>
<dependency>
<groupId>xerces</groupId>
<groupId>org.exist-db.thirdparty.xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.12.0</version>
</dependency>
<classifier>xml-schema-1.1</classifier>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public Collection<CMElementDeclaration> getPossibleElements(DOMElement parentEle
// Schema constraint
int[] states = validator.startContentModel();
for (QName elementName : qNames) {
Object decl = validator.oneTransition(elementName, states, handler);
Object decl = validator.oneTransition(elementName, states, handler, document);
if (decl == null) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private static String reformatElementNames(boolean hasNamespace, String names) {
stream.advance(2); // Consume quotation and':'
}
sb.append(" - ");
while (stream.peekChar() != _CCB && stream.peekChar() != _CMA) { // } | ,
while (stream.peekChar() != _CCB && stream.peekChar() != _CMA && !stream.eos()) { // } | ,
sb.append(Character.toString((char) stream.peekChar()));
stream.advance(1);
}
Expand All @@ -176,7 +176,7 @@ private static String reformatArrayElementNames(String names) {
while (!stream.eos()) { // ]
stream.advance(1);// Consume ' ' or '[' if first item
sb.append(" - ");
while (stream.peekChar() != _CSB && stream.peekChar() != _CMA) { // ] | ,
while (stream.peekChar() != _CSB && stream.peekChar() != _CMA && !stream.eos()) { // ] | ,
sb.append(Character.toString((char) stream.peekChar()));
stream.advance(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4xml.XMLAssert;
import org.eclipse.lsp4xml.commons.BadLocationException;
import org.eclipse.lsp4xml.extensions.contentmodel.participants.XMLSchemaErrorCode;
import org.eclipse.lsp4xml.extensions.xsd.participants.XSDErrorCode;
import org.eclipse.lsp4xml.extensions.xsd.participants.diagnostics.XSDValidator;
import org.junit.Test;
Expand Down Expand Up @@ -311,6 +312,37 @@ public void src_element_3() throws BadLocationException {
testDiagnosticsFor(xml, d(1, 3, 1, 13, XSDErrorCode.src_element_3));
}

@Test
public void xsd1_1() throws BadLocationException {
// Test with XSD 1.0 -> error
String xmlWithXSD1_0 = getXMLForXSD1_1Test("1.0");
testDiagnosticsFor(xmlWithXSD1_0, d(11, 54, 11, 65, XSDErrorCode.cos_all_limited_2));

// Test with XSD 1.1 -> No error
String xmlWithXSD1_1 = getXMLForXSD1_1Test("1.1");
testDiagnosticsFor(xmlWithXSD1_1);
}

private static String getXMLForXSD1_1Test(String minVersion) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
"<xs:schema \r\n" + //
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" \r\n" + //
" xmlns:t=\"test\" \r\n" + //
" xmlns:vc=\"http://www.w3.org/2007/XMLSchema-versioning\" \r\n" + //
" targetNamespace=\"test\" \r\n" + //
" elementFormDefault=\"qualified\" \r\n" + //
" vc:minVersion=\"" + minVersion + "\">\r\n" + //
" \r\n" + //
" <xs:complexType name=\"testType\">\r\n" + //
" <xs:all>\r\n" + // <- error with XSD 1.0 but not with XSD 1.1
" <xs:element name=\"testEle\" minOccurs=\"1\" maxOccurs=\"unbounded\" type=\"xs:string\"/>\r\n" + //
" <xs:element name=\"testEleTwo\" type=\"xs:string\"/>\r\n" + //
" </xs:all>\r\n" + //
" </xs:complexType>\r\n" + //
" \r\n" + //
"</xs:schema>";
}

private static void testDiagnosticsFor(String xml, Diagnostic... expected) throws BadLocationException {
XMLAssert.testDiagnosticsFor(xml, null, null, "test.xsd", expected);
}
Expand Down

0 comments on commit 71caa64

Please sign in to comment.