use of org.kohsuke.rngom.digested.DElementPattern 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 org.kohsuke.rngom.digested.DElementPattern in project intellij-community by JetBrains.
the class RngNsDescriptor method findDescriptor.
private XmlElementDescriptor findDescriptor(final QName qName, List<DElementPattern> list) {
int max = -1;
DElementPattern maxPattern = null;
for (DElementPattern pattern : list) {
final NameClass nameClass = pattern.getName();
if (nameClass.contains(qName)) {
final int spec = nameClass.containsSpecificity(qName);
if (spec > max) {
maxPattern = pattern;
max = spec;
}
}
}
final List<DElementPattern> patterns = ContainerUtil.findAll(list, pattern -> {
final NameClass nameClass = pattern.getName();
return nameClass.contains(qName);
});
if (maxPattern != null) {
if (patterns.size() > 1) {
return initDescriptor(new CompositeDescriptor(this, maxPattern, patterns));
} else {
return initDescriptor(new RngElementDescriptor(this, maxPattern));
}
} else {
return null;
}
}
use of org.kohsuke.rngom.digested.DElementPattern in project intellij-community by JetBrains.
the class RngNsDescriptor method findRootDescriptorInner.
private XmlElementDescriptor findRootDescriptorInner(XmlTag tag) {
final List<DElementPattern> allNamedPatterns = ContainerUtil.findAll(ChildElementFinder.find(-1, myPattern), NamedPatternFilter.INSTANCE);
XmlElementDescriptor descriptor = findDescriptor(tag, allNamedPatterns);
return descriptor != null ? descriptor : findDescriptor(tag, ChildElementFinder.find(myPattern));
}
use of org.kohsuke.rngom.digested.DElementPattern in project intellij-community by JetBrains.
the class CompositeDescriptor method collectAttributeDescriptors.
@Override
protected XmlAttributeDescriptor[] collectAttributeDescriptors(@Nullable XmlTag context) {
final QName qName = null;
final DPattern[] patterns;
if (qName == null) {
patterns = myPatterns;
} else {
final List<DElementPattern> p = ContainerUtil.findAll(myPatterns, pattern -> pattern.getName().contains(qName));
patterns = p.toArray(new DPattern[p.size()]);
}
return computeAttributeDescriptors(AttributeFinder.find(patterns));
}
use of org.kohsuke.rngom.digested.DElementPattern in project intellij-community by JetBrains.
the class CompositeDescriptor method findElementDescriptor.
@Override
protected XmlElementDescriptor findElementDescriptor(XmlTag childTag) {
final List<DElementPattern> patterns = new ArrayList<>();
for (DElementPattern pattern : myPatterns) {
patterns.addAll(ChildElementFinder.find(2, pattern));
}
// TODO: filter out impossible variants:
/*
while this needs both variants of <choice>-children
<element><choice><caret>
this does not, because <choice> inside <choice> is unambiguous:
<element><choice><data type="string" /><choice><caret>
*/
final XmlElementDescriptor d = myNsDescriptor.findDescriptor(childTag, patterns);
if (d != null) {
return d;
}
return NULL;
}
Aggregations