use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlDtdTest method testEntityDecl5.
public void testEntityDecl5() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<!ENTITY % boolean \"true | false\" > <!ELEMENT foo EMPTY> <!ATTLIST foo someBoolean (%boolean;) \"true\" someString CDATA #IMPLIED >");
final XmlTag tag = tag("foo");
final XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
final XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
assertEquals(2, attributes.length);
assertEquals("someBoolean", attributes[0].getName());
assertEquals("someString", attributes[1].getName());
assertTrue(attributes[0].isEnumerated());
assertEquals(2, attributes[0].getEnumeratedValues().length);
assertEquals("true", attributes[0].getEnumeratedValues()[0]);
assertEquals("false", attributes[0].getEnumeratedValues()[1]);
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlDtdTest method testElementDescriptor3.
public void testElementDescriptor3() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT principals ANY><!ATTLIST principals path CDATA #IMPLIED smtp-host CDATA #REQUIRED>" + "<!ATTLIST principals address CDATA #IMPLIED>");
final XmlTag tag = tag("principals");
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
XmlAttributeDescriptor attributeDescriptor = elementDescriptor.getAttributeDescriptor("path", tag);
assertNotNull(attributeDescriptor);
attributeDescriptor = elementDescriptor.getAttributeDescriptor("xxx", tag);
assertNull(attributeDescriptor);
attributeDescriptor = elementDescriptor.getAttributeDescriptor("smtp-host", tag);
assertNotNull(attributeDescriptor);
attributeDescriptor = elementDescriptor.getAttributeDescriptor("address", tag);
assertNotNull(attributeDescriptor);
XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
assertEquals("path", descriptors[0].getName());
assertEquals("smtp-host", descriptors[1].getName());
assertEquals("address", descriptors[2].getName());
assertEquals(3, descriptors.length);
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlDtdTest method testDocumentDescriptor1.
public void testDocumentDescriptor1() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT principals (#PCDATA)><!ELEMENT data-sources (#PCDATA)>");
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag("principals"));
assertNotNull(elementDescriptor);
elementDescriptor = NSDescriptor.getElementDescriptor(tag("data-sources"));
assertNotNull(elementDescriptor);
elementDescriptor = NSDescriptor.getElementDescriptor(tag("xxx"));
assertNull(elementDescriptor);
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlDtdTest method testElementDescriptor4.
public void testElementDescriptor4() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<!ELEMENT orion-application (ejb-module*, persistence?, namespace-access)>" + "<!ELEMENT ejb-module ANY>" + "<!ELEMENT persistence ANY>" + "<!ELEMENT namespace-access ANY>");
XmlTag documentTag = tag("orion-application");
XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl) NSDescriptor.getElementDescriptor(documentTag);
XmlElementDescriptor[] elements = elementDescriptor.getElementsDescriptors(documentTag);
assertEquals(3, elements.length);
assertEquals("ejb-module", elements[0].getName());
assertEquals("persistence", elements[1].getName());
assertEquals("namespace-access", elements[2].getName());
elements = elements[0].getElementsDescriptors(documentTag);
assertEquals(4, elements.length);
assertEquals("orion-application", elements[0].getName());
assertEquals("ejb-module", elements[1].getName());
assertEquals("persistence", elements[2].getName());
assertEquals("namespace-access", elements[3].getName());
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class URLReference method resolve.
@Override
@Nullable
public PsiElement resolve() {
myIncorrectResourceMapped = false;
final String canonicalText = getCanonicalText();
if (canonicalText.isEmpty()) {
final XmlAttribute attr = PsiTreeUtil.getParentOfType(getElement(), XmlAttribute.class);
if (attr != null && attr.isNamespaceDeclaration() && attr.getNamespacePrefix().isEmpty() || ExternalResourceManagerEx.getInstanceEx().isIgnoredResource(canonicalText)) {
// of there being no default namespace
return myElement;
}
return null;
}
if (ExternalResourceManagerEx.getInstanceEx().isIgnoredResource(canonicalText))
return myElement;
final XmlTag tag = PsiTreeUtil.getParentOfType(myElement, XmlTag.class);
if (tag != null && canonicalText.equals(tag.getAttributeValue(TARGET_NAMESPACE_ATTR_NAME)))
return tag;
final PsiFile containingFile = myElement.getContainingFile();
if (tag != null && tag.getAttributeValue("schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI) == null) {
final PsiFile file = ExternalResourceManager.getInstance().getResourceLocation(canonicalText, containingFile, tag.getAttributeValue("version"));
if (file != null)
return file;
}
if (containingFile instanceof XmlFile) {
final XmlDocument document = ((XmlFile) containingFile).getDocument();
assert document != null;
final XmlTag rootTag = document.getRootTag();
if (rootTag == null) {
return ExternalResourceManager.getInstance().getResourceLocation(canonicalText, containingFile, null);
}
final XmlNSDescriptor nsDescriptor = rootTag.getNSDescriptor(canonicalText, true);
if (nsDescriptor != null)
return nsDescriptor.getDescriptorFile();
final String url = ExternalResourceManager.getInstance().getResourceLocation(canonicalText, myElement.getProject());
if (!url.equals(canonicalText)) {
myIncorrectResourceMapped = true;
return null;
}
if (tag == rootTag && (tag.getNamespace().equals(XmlUtil.XML_SCHEMA_URI) || tag.getNamespace().equals(XmlUtil.WSDL_SCHEMA_URI))) {
for (XmlTag t : tag.getSubTags()) {
final String name = t.getLocalName();
if ("import".equals(name)) {
if (canonicalText.equals(t.getAttributeValue("namespace")))
return t;
} else if (!"include".equals(name) && !"redefine".equals(name) && !"annotation".equals(name))
break;
}
}
final PsiElement[] result = new PsiElement[1];
processWsdlSchemas(rootTag, t -> {
if (canonicalText.equals(t.getAttributeValue(TARGET_NAMESPACE_ATTR_NAME))) {
result[0] = t;
return false;
}
for (XmlTag anImport : t.findSubTags("import", t.getNamespace())) {
if (canonicalText.equals(anImport.getAttributeValue("namespace"))) {
final XmlAttribute location = anImport.getAttribute("schemaLocation");
if (location != null) {
result[0] = FileReferenceUtil.findFile(location.getValueElement());
}
}
}
return true;
});
return result[0];
}
return null;
}
Aggregations