use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlSchemaTest method testElementDescriptor4.
public void testElementDescriptor4() 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:attribute name=\"orderDate\" type=\"xsd:date\"/>" + " <xsd:attribute name=\"name\" type=\"xsd:string\"/>" + "</xsd:complexType>" + "</xsd:schema>");
final XmlTag tag = XmlTestUtil.tag("purchaseOrder", getProject());
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
XmlAttributeDescriptor[] attributes = elementDescriptor.getAttributesDescriptors(tag);
assertEquals(2, attributes.length);
assertEquals("orderDate", attributes[0].getName());
assertEquals("name", attributes[1].getName());
assertEquals("name", elementDescriptor.getAttributeDescriptor("name", tag).getName());
assertNull(elementDescriptor.getAttributeDescriptor("xxx", tag));
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class XmlSchemaTest method testElementDescriptor14.
public void testElementDescriptor14() throws Exception {
XmlNSDescriptor NSDescriptor = createDescriptor("<xsd:schema targetNamespace=\"http://www.deansoft.com/AddressBook\" xmlns:ab=\"http://www.deansoft.com/AddressBook\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + "<xsd:element name=\"purchaseOrder\">" + "<xsd:complexType name=\"PurchaseOrderType\">" + " <xsd:sequence>" + " <xsd:element ref=\"shipTo\"/>" + " </xsd:sequence>" + "</xsd:complexType>" + "</xsd:element>" + "<xsd:element name=\"shipTo\" abstract=\"true\">" + " <xsd:complexType name=\"USAddress\">" + " <xsd:attribute name=\"orderDate\" type=\"xsd:date\"/>" + " <xsd:element name=\"items\" type=\"Items\"/>" + " </xsd:complexType>" + "</xsd:element>" + "<xsd:element name=\"name\" substitutionGroup=\"ab:shipTo\"/>" + "</xsd:schema>");
XmlTag tag = XmlTestUtil.tag("purchaseOrder", "http://www.deansoft.com/AddressBook", getProject());
XmlElementDescriptor elementDescriptor = NSDescriptor.getElementDescriptor(tag);
final XmlElementDescriptor[] elements = elementDescriptor.getElementsDescriptors(tag);
assertEquals(1, elements.length);
assertEquals("name", elements[0].getName());
XmlAttributeDescriptor[] attrs = elements[0].getAttributesDescriptors(tag);
assertEquals(1, attrs.length);
assertEquals("orderDate", attrs[0].getName());
XmlElementDescriptor[] element0Descriptors = elements[0].getElementsDescriptors(tag.findFirstSubTag(elements[0].getName()));
assertEquals(1, element0Descriptors.length);
assertEquals("items", element0Descriptors[0].getName());
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class RngDocumentationProvider method generateDoc.
@Override
@Nullable
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
final XmlElement c = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class, XmlAttribute.class);
if (c != null && c.getManager() == null) {
LOG.warn("Invalid context element passed to generateDoc()", new Throwable("<stack trace>"));
return null;
}
if (c instanceof XmlTag) {
final XmlTag xmlElement = (XmlTag) c;
final XmlElementDescriptor descriptor = xmlElement.getDescriptor();
if (descriptor instanceof CompositeDescriptor) {
final StringBuilder sb = new StringBuilder();
final CompositeDescriptor d = (CompositeDescriptor) descriptor;
final DElementPattern[] patterns = d.getElementPatterns();
final THashSet<PsiElement> elements = ContainerUtil.newIdentityTroveSet();
for (DElementPattern pattern : patterns) {
final PsiElement psiElement = d.getDeclaration(pattern.getLocation());
if (psiElement instanceof XmlTag && elements.add(psiElement)) {
if (sb.length() > 0) {
sb.append("<hr>");
}
sb.append(getDocumentationFromTag((XmlTag) psiElement, xmlElement.getLocalName(), "Element"));
}
}
return makeDocumentation(sb);
} else if (descriptor instanceof RngElementDescriptor) {
final RngElementDescriptor d = (RngElementDescriptor) descriptor;
final PsiElement declaration = d.getDeclaration();
if (declaration instanceof XmlTag) {
return makeDocumentation(getDocumentationFromTag((XmlTag) declaration, xmlElement.getLocalName(), "Element"));
}
}
} else if (c instanceof XmlAttribute) {
final XmlAttribute attribute = (XmlAttribute) c;
final XmlAttributeDescriptor descriptor = attribute.getDescriptor();
if (descriptor instanceof RngXmlAttributeDescriptor) {
final RngXmlAttributeDescriptor d = (RngXmlAttributeDescriptor) descriptor;
final StringBuilder sb = new StringBuilder();
final Collection<PsiElement> declaration = ContainerUtil.newIdentityTroveSet(d.getDeclarations());
for (PsiElement psiElement : declaration) {
if (psiElement instanceof XmlTag) {
if (sb.length() > 0) {
sb.append("<hr>");
}
sb.append(getDocumentationFromTag((XmlTag) psiElement, d.getName(), "Attribute"));
}
}
return makeDocumentation(sb);
}
} else if (element instanceof XmlTag) {
return makeDocumentation(getDocumentationFromTag((XmlTag) element, ((XmlTag) element).getLocalName(), "Element"));
}
return null;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-community by JetBrains.
the class HtmlDocumentationProvider method createNavigationElementHTML.
public PsiElement createNavigationElementHTML(PsiManager psiManager, String text, PsiElement context) {
String key = text.toLowerCase(Locale.US);
final HtmlTagDescriptor descriptor = HtmlDescriptorsTable.getTagDescriptor(key);
if (descriptor != null && !isAttributeContext(context)) {
try {
final XmlTag tagFromText = XmlElementFactory.getInstance(psiManager.getProject()).createTagFromText("<" + key + " xmlns=\"" + XmlUtil.XHTML_URI + "\"/>");
final XmlElementDescriptor tagDescriptor = tagFromText.getDescriptor();
return tagDescriptor != null ? tagDescriptor.getDeclaration() : null;
} catch (IncorrectOperationException ignore) {
}
} else {
XmlTag tagContext = findTagContext(context);
HtmlAttributeDescriptor myAttributeDescriptor = getDescriptor(key, tagContext);
if (myAttributeDescriptor != null && tagContext != null) {
XmlElementDescriptor tagDescriptor = tagContext.getDescriptor();
XmlAttributeDescriptor attributeDescriptor = tagDescriptor != null ? tagDescriptor.getAttributeDescriptor(text, tagContext) : null;
return (attributeDescriptor != null) ? attributeDescriptor.getDeclaration() : null;
}
}
return null;
}
use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.
the class PropertyTestCase method getDescriptor.
@Nullable
protected XmlAttributeDescriptor getDescriptor(@NotNull NlComponent component, @NotNull String attributeName) {
XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(component.getTag());
assertThat(elementDescriptor).isNotNull();
XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(component.getTag());
for (XmlAttributeDescriptor descriptor : descriptors) {
if (descriptor.getName().equals(attributeName)) {
return descriptor;
}
}
return null;
}
Aggregations