use of com.intellij.xml.XmlAttributeDescriptor 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.XmlAttributeDescriptor 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.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlElementDescriptorImpl method collectAttributeDescriptors.
// Read-only calculation
@Override
protected final XmlAttributeDescriptor[] collectAttributeDescriptors(final XmlTag context) {
final List<XmlAttributeDescriptor> result = new SmartList<>();
for (XmlAttlistDecl attlistDecl : findAttlistDeclarations(getName())) {
for (XmlAttributeDecl attributeDecl : attlistDecl.getAttributeDecls()) {
final PsiMetaData psiMetaData = attributeDecl.getMetaData();
assert psiMetaData instanceof XmlAttributeDescriptor;
result.add((XmlAttributeDescriptor) psiMetaData);
}
}
return result.toArray(new XmlAttributeDescriptor[result.size()]);
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlAttributeDescriptorImpl method shouldBeQualified.
private boolean shouldBeQualified(String targetNs, XmlTag contextTag) {
boolean attributeShouldBeQualified = false;
String contextNs = contextTag.getNamespace();
if (!contextNs.equals(targetNs)) {
final XmlElementDescriptor xmlElementDescriptor = contextTag.getDescriptor();
if (xmlElementDescriptor instanceof XmlElementDescriptorImpl) {
final XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl) xmlElementDescriptor;
final TypeDescriptor type = elementDescriptor.getType();
if (type instanceof ComplexTypeDescriptor) {
final ComplexTypeDescriptor typeDescriptor = (ComplexTypeDescriptor) type;
if (myReferenceName != null) {
return myReferenceName.indexOf(':') != 0;
}
XmlAttributeDescriptor[] attributes = ((ComplexTypeDescriptor) type).getAttributes(contextTag);
if (ArrayUtil.contains(this, attributes)) {
return false;
}
attributeShouldBeQualified = typeDescriptor.canContainAttribute(targetNs, null) != ComplexTypeDescriptor.CanContainAttributeType.CanNotContain;
}
if (!attributeShouldBeQualified && contextNs.length() == 0 && targetNs.length() > 0) {
attributeShouldBeQualified = !targetNs.equals(elementDescriptor.getNamespace());
}
}
}
return attributeShouldBeQualified;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlAttributeImpl method getDescriptor.
@Override
@Nullable
public XmlAttributeDescriptor getDescriptor() {
final PsiElement parentElement = getParent();
// e.g. XmlDecl or PI
if (parentElement == null)
return null;
final XmlTag tag = (XmlTag) parentElement;
final XmlElementDescriptor descr = tag.getDescriptor();
if (descr == null)
return null;
final XmlAttributeDescriptor attributeDescr = descr.getAttributeDescriptor(this);
return attributeDescr == null ? descr.getAttributeDescriptor(getName(), tag) : attributeDescr;
}
Aggregations