use of org.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor 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.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor in project intellij-community by JetBrains.
the class ValidateAction method actionPerformedImpl.
private boolean actionPerformedImpl(AnActionEvent e) {
final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
if (file == null) {
return false;
}
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return false;
}
final RngElementDescriptor descriptor = getRootDescriptor(file);
if (descriptor == null)
return false;
final PsiElement element = descriptor.getDeclaration();
final XmlFile xmlFile = PsiTreeUtil.getParentOfType(element, XmlFile.class);
if (xmlFile == null)
return false;
final VirtualFile instanceFile = file.getVirtualFile();
final VirtualFile schemaFile = xmlFile.getVirtualFile();
if (instanceFile == null || schemaFile == null) {
return true;
}
doRun(project, instanceFile, schemaFile);
return true;
}
Aggregations