use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method resolveInner.
private PsiElement resolveInner() {
final XmlTag tag = PsiTreeUtil.getContextOfType(myElement, XmlTag.class, false);
if (tag == null)
return PsiUtilCore.NULL_PSI_ELEMENT;
String canonicalText = getCanonicalText();
boolean[] redefined = new boolean[1];
XmlNSDescriptorImpl nsDescriptor = getDescriptor(tag, canonicalText, redefined);
if (myType != null && nsDescriptor != null && nsDescriptor.getTag() != null) {
switch(myType) {
case GroupReference:
return nsDescriptor.findGroup(canonicalText);
case AttributeGroupReference:
return nsDescriptor.findAttributeGroup(canonicalText);
case ElementReference:
{
XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), getNamespace(tag, canonicalText), new HashSet<>(), true);
return descriptor != null ? descriptor.getDeclaration() : PsiUtilCore.NULL_PSI_ELEMENT;
}
case AttributeReference:
{
//final String prefixByQualifiedName = XmlUtil.findPrefixByQualifiedName(canonicalText);
final String localNameByQualifiedName = XmlUtil.findLocalNameByQualifiedName(canonicalText);
XmlAttributeDescriptor descriptor = nsDescriptor.getAttribute(localNameByQualifiedName, getNamespace(tag, canonicalText), tag);
if (descriptor != null)
return descriptor.getDeclaration();
return PsiUtilCore.NULL_PSI_ELEMENT;
}
case TypeReference:
{
TypeDescriptor typeDescriptor = redefined[0] ? nsDescriptor.findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), "") : nsDescriptor.getTypeDescriptor(canonicalText, tag);
if (typeDescriptor instanceof ComplexTypeDescriptor) {
return typeDescriptor.getDeclaration();
} else if (typeDescriptor != null) {
return myElement;
}
}
}
}
return PsiUtilCore.NULL_PSI_ELEMENT;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class HtmlElementDescriptorImpl method collectAttributeDescriptorsMap.
// Read-only calculation
@Override
protected HashMap<String, XmlAttributeDescriptor> collectAttributeDescriptorsMap(final XmlTag context) {
final HashMap<String, XmlAttributeDescriptor> hashMap = new HashMap<>();
XmlAttributeDescriptor[] elementAttributeDescriptors = myDelegate.getAttributesDescriptors(context);
for (final XmlAttributeDescriptor attributeDescriptor : elementAttributeDescriptors) {
hashMap.put(attributeDescriptor.getName(), new HtmlAttributeDescriptorImpl(attributeDescriptor, myCaseSensitive));
}
return hashMap;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlInsightTest method testAttributeDescriptor2.
public void testAttributeDescriptor2() throws Exception {
XmlFile file = createFile("<root><a c='' a=''></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
assertEquals("c", attributes[0].getName());
assertTrue(attributes[0].isRequired());
assertEquals("a", attributes[1].getName());
assertTrue(attributes[1].isRequired());
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlInsightTest method testAttributeDescriptor1.
public void testAttributeDescriptor1() throws Exception {
XmlFile file = createFile("<root><a attr1=''></a><a attr2='' attr1=''></a></root>");
XmlNSDescriptor descriptor = createDescriptor(file);
XmlTag rootTag = file.getDocument().getRootTag();
XmlElementDescriptor element = descriptor.getElementDescriptor(rootTag);
element = element.getElementsDescriptors(rootTag)[0];
XmlAttributeDescriptor[] attributes = element.getAttributesDescriptors(rootTag);
assertEquals("attr1", attributes[0].getName());
assertTrue(attributes[0].isRequired());
assertEquals("attr2", attributes[1].getName());
assertTrue(!attributes[1].isRequired());
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlSchemaTest method testElementDescriptor10.
public void testElementDescriptor10() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<xsd:element name=\"purchaseOrder\" type=\"PurchaseOrderType\"/>" + "<xsd:complexType name=\"PurchaseOrderType\">" + " <xsd:attributeGroup ref=\"ddd:bookAttributes\"/>" + "</xsd:complexType>" + "<xsd:attributeGroup name=\"bookAttributes\">" + " <xsd:attribute name=\"isbn\" type=\"xs:string\" use=\"required\"/>" + " <xsd:attribute name=\"available\" type=\"xs:string\"/>" + "</xsd:attributeGroup>" + "</xsd:schema>");
final XmlTag tag = XmlTestUtil.tag("purchaseOrder", getProject());
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
assertEquals(2, attributes.length);
assertEquals("isbn", attributes[0].getName());
assertEquals("available", attributes[1].getName());
assertEquals("isbn", elementDescriptor.getAttributeDescriptor("isbn", tag).getName());
assertNull(elementDescriptor.getAttributeDescriptor("xxx", tag));
}
Aggregations