Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for null elementOptionality entry for code action cvc_complex_type_2_4_b #1281

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ public boolean isOptional(String childElementName) {
}
}
}
return elementOptionality.get(childElementName);
Boolean isOptional = elementOptionality.get(childElementName);
Copy link
Contributor

@angelozerr angelozerr Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be better to write (not tested):

return elementOptionality.getOrDefault(childElementName, false);

return (isOptional != null) ? isOptional : false;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,36 @@ public void cvc_complex_type_2_4_bCodeAction_Only_Required_Ordered() throws Exce
"\t<e></e>")));
}

@Test
public void cvc_complex_type_2_4_bCodeAction_Complex_Children() throws Exception {
String xml = "<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
"xsi:noNamespaceSchemaLocation=\"src/test/resources/xsd/order_complex_children.xsd\"></root>";
Diagnostic d = d(0, 1, 0, 5, XMLSchemaErrorCode.cvc_complex_type_2_4_b);
testDiagnosticsFor(xml, d);
testCodeActionsFor(xml, d, ca(d, te(1, 82, 1, 82, //
"\r\n" + //
"\t<a>\r\n" + //
"\t\t<root>\r\n\t\t\r\n" + //
"\t\t\t<b>\r\n" + //
"\t\t\t</b>\r\n\t\t\r\n" + //
"\t\t\t<c>\r\n" + //
"\t\t\t</c>\r\n\t\t\r\n" + //
"\t\t\t<d age=\"\">\r\n" + //
"\t\t\t\t<d1></d1>\r\n" + //
"\t\t\t</d>\r\n\t\t\r\n" + //
"\t\t\t<e></e>\r\n" + //
"\t\t</root>\r\n" + //
"\t</a>\n")),
ca(d, te(1, 82, 1, 82, //
"\r\n" + //
"\t<a>\r\n" + //
"\t\t<root>\r\n\t\t\r\n" + //
"\t\t\t<d age=\"\"></d>\r\n\t\t\r\n" + //
"\t\t\t<e></e>\r\n" + //
"\t\t</root>\r\n" + //
"\t</a>\n")));
}

@Test
public void cvc_attribute_3() throws Exception {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + //
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="a" minOccurs="1" maxOccurs="1" />
<xs:element name="b" minOccurs="0" maxOccurs="1" />
<xs:element name="c" minOccurs="0" maxOccurs="1" />
<xs:element name="d" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="d1" minOccurs="0" maxOccurs="unbounded" type="xs:string" />
</xs:sequence>
<xs:attribute name="status" type="xs:string" />
<xs:attribute name="age" use="required" type="xs:int" />
</xs:complexType>
</xs:element>
<xs:element name="e" minOccurs="1" maxOccurs="1" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>