do not process "any" in restrictions

This commit is contained in:
Dmitry Avdeev
2013-07-23 20:29:36 +04:00
parent a473300251
commit 12b08c4336
2 changed files with 27 additions and 6 deletions
@@ -646,5 +646,23 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase {
assertEquals("src", strings.get(1));
assertEquals("align", strings.get(2));
}
public void testDoNotProcessAnyInRestrictions() throws Exception {
myFixture.configureByText("foo.xsd", "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <<caret>\n" +
"</xs:schema>");
myFixture.completeBasic();
assertSameElements(myFixture.getLookupElementStrings(), "xs:annotation",
"xs:attribute",
"xs:attributeGroup",
"xs:complexType",
"xs:element",
"xs:group",
"xs:import",
"xs:include",
"xs:notation",
"xs:redefine",
"xs:simpleType");
}
}
@@ -269,7 +269,7 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
public boolean canContainTag(String localName, String namespace, XmlElement context) {
return _canContainTag(localName, namespace, myTag, context, new HashSet<XmlTag>(5),
new CurrentContextInfo(myDocumentDescriptor, myDocumentDescriptor.getDefaultNamespace()));
new CurrentContextInfo(myDocumentDescriptor, myDocumentDescriptor.getDefaultNamespace()), false);
}
static class CurrentContextInfo {
@@ -298,12 +298,14 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
}
private boolean _canContainTag(String localName, String namespace, XmlTag tag, XmlElement context, Set<XmlTag> visited,
CurrentContextInfo info) {
CurrentContextInfo info, boolean restriction) {
if (visited.contains(tag)) return false;
visited.add(tag);
if (XmlNSDescriptorImpl.equalsToSchemaName(tag, "any")) {
myHasAnyInContentModel = true;
if (!restriction) {
myHasAnyInContentModel = true;
}
if (OTHER_NAMESPACE_ATTR_VALUE.equals(tag.getAttributeValue("namespace"))) {
return namespace == null || !namespace.equals(info.expectedDefaultNs);
}
@@ -315,7 +317,7 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
if (ref != null) {
XmlTag groupTag = info.documentDescriptor.findGroup(ref);
if (groupTag != null) {
if (_canContainTag(localName, namespace, groupTag, context, visited, getContextInfo(info, ref))) return true;
if (_canContainTag(localName, namespace, groupTag, context, visited, getContextInfo(info, ref), restriction)) return true;
}
}
}
@@ -329,7 +331,8 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
if (descriptor instanceof ComplexTypeDescriptor) {
ComplexTypeDescriptor complexTypeDescriptor = (ComplexTypeDescriptor)descriptor;
if (complexTypeDescriptor._canContainTag(localName, namespace, complexTypeDescriptor.myTag, context, visited,
getContextInfo(info, base))) {
getContextInfo(info, base), restriction || XmlNSDescriptorImpl.equalsToSchemaName(tag,
RESTRICTION_TAG_NAME))) {
myHasAnyInContentModel |= complexTypeDescriptor.myHasAnyInContentModel;
return true;
}
@@ -365,7 +368,7 @@ public class ComplexTypeDescriptor extends TypeDescriptor {
}
for (XmlTag subTag : tag.getSubTags()) {
if (_canContainTag(localName, namespace, subTag, context, visited, info)) return true;
if (_canContainTag(localName, namespace, subTag, context, visited, info, restriction)) return true;
}
return false;