use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class HtmlFileTreeElement method getChildrenBase.
@Override
@NotNull
public Collection<StructureViewTreeElement> getChildrenBase() {
if (isHtml5SectionsMode()) {
// Html5SectionsNodeProvider will return its structure
return Collections.emptyList();
}
final XmlFile xmlFile = getElement();
final XmlDocument document = xmlFile == null ? null : xmlFile.getDocument();
if (document == null) {
return Collections.emptyList();
}
final List<XmlTag> rootTags = new SmartList<>();
document.processElements(new FilterElementProcessor(XmlTagFilter.INSTANCE, rootTags), document);
if (rootTags.isEmpty()) {
return Collections.emptyList();
} else if (rootTags.size() == 1) {
final XmlTag rootTag = rootTags.get(0);
if ("html".equalsIgnoreCase(rootTag.getLocalName())) {
final XmlTag[] subTags = rootTag.getSubTags();
if (subTags.length == 1 && ("head".equalsIgnoreCase(subTags[0].getLocalName()) || "body".equalsIgnoreCase(subTags[0].getLocalName()))) {
return new HtmlTagTreeElement(subTags[0]).getChildrenBase();
}
return new HtmlTagTreeElement(rootTag).getChildrenBase();
}
return Collections.<StructureViewTreeElement>singletonList(new HtmlTagTreeElement(rootTag));
} else {
final Collection<StructureViewTreeElement> result = new ArrayList<>(rootTags.size());
for (XmlTag tag : rootTags) {
result.add(new HtmlTagTreeElement(tag));
}
return result;
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class InclusionProvider method computeInclusion.
@Nullable
private static PsiElement[] computeInclusion(final XmlTag xincludeTag) {
final XmlFile included = XmlIncludeHandler.resolveXIncludeFile(xincludeTag);
final XmlDocument document = included != null ? included.getDocument() : null;
final XmlTag rootTag = document != null ? document.getRootTag() : null;
if (rootTag != null) {
final String xpointer = xincludeTag.getAttributeValue("xpointer", XmlPsiUtil.XINCLUDE_URI);
final XmlTag[] includeTag = extractXpointer(rootTag, xpointer);
PsiElement[] result = new PsiElement[includeTag.length];
for (int i = 0; i < includeTag.length; i++) {
result[i] = new IncludedXmlTag(includeTag[i], xincludeTag.getParentTag());
}
return result;
}
return null;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getElementDescriptor.
@Nullable
public XmlElementDescriptor getElementDescriptor(String localName, String namespace, Set<XmlNSDescriptorImpl> visited, boolean reference) {
if (visited.contains(this))
return null;
final QNameKey pair = new QNameKey(namespace, localName);
final CachedValue<XmlElementDescriptor> descriptor = myDescriptorsMap.get(pair);
if (descriptor != null) {
final XmlElementDescriptor value = descriptor.getValue();
if (value == null || value.getDeclaration().isValid())
return value;
}
final XmlTag rootTag = myTag;
if (rootTag == null)
return null;
XmlTag[] tags = rootTag.getSubTags();
visited.add(this);
LOG.assertTrue(rootTag.isValid());
for (final XmlTag tag : tags) {
if (equalsToSchemaName(tag, ELEMENT_TAG_NAME)) {
String name = tag.getAttributeValue("name");
if (name != null) {
if (checkElementNameEquivalence(localName, namespace, name, tag)) {
final CachedValue<XmlElementDescriptor> cachedValue = CachedValuesManager.getManager(tag.getProject()).createCachedValue(() -> {
final String name1 = tag.getAttributeValue("name");
if (name1 != null && !name1.equals(pair.second)) {
myDescriptorsMap.remove(pair);
return new CachedValueProvider.Result<>(null, PsiModificationTracker.MODIFICATION_COUNT);
}
final XmlElementDescriptor xmlElementDescriptor = createElementDescriptor(tag);
return new CachedValueProvider.Result<>(xmlElementDescriptor, xmlElementDescriptor.getDependences());
}, false);
myDescriptorsMap.put(pair, cachedValue);
return cachedValue.getValue();
}
}
} else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (reference && equalsToSchemaName(tag, IMPORT_TAG_NAME) && (namespace.equals(tag.getAttributeValue("namespace")) || namespace.length() == 0 && tag.getAttributeValue("namespace") == null))) {
final String schemaLocation = tag.getAttributeValue("schemaLocation");
if (schemaLocation != null) {
final XmlFile xmlFile = XmlUtil.findNamespace(rootTag.getContainingFile(), schemaLocation);
if (xmlFile != null) {
final XmlDocument includedDocument = xmlFile.getDocument();
if (includedDocument != null) {
final PsiMetaData data = includedDocument.getMetaData();
if (data instanceof XmlNSDescriptorImpl) {
final XmlElementDescriptor elementDescriptor = ((XmlNSDescriptorImpl) data).getElementDescriptor(localName, namespace, visited, reference);
if (elementDescriptor != null) {
return elementDescriptor;
}
}
}
}
}
} else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
if (nsDescriptor != null) {
final XmlElementDescriptor xmlElementDescriptor = nsDescriptor.getElementDescriptor(localName, namespace, visited, reference);
if (xmlElementDescriptor instanceof XmlElementDescriptorImpl) {
return new RedefinedElementDescriptor((XmlElementDescriptorImpl) xmlElementDescriptor, this);
}
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method getRedefinedElementDescriptor.
public static XmlNSDescriptorImpl getRedefinedElementDescriptor(final XmlTag parentTag) {
XmlFile file = getRedefinedElementDescriptorFile(parentTag);
if (file != null) {
final XmlDocument document = file.getDocument();
final PsiMetaData metaData = document != null ? document.getMetaData() : null;
if (metaData instanceof XmlNSDescriptorImpl)
return (XmlNSDescriptorImpl) metaData;
}
return null;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method findSpecialTag.
@Nullable
private static XmlTag findSpecialTag(@NonNls String name, @NonNls String specialName, XmlTag rootTag, XmlNSDescriptorImpl descriptor, HashSet<XmlTag> visited) {
XmlNSDescriptorImpl nsDescriptor = getNSDescriptorToSearchIn(rootTag, name, descriptor);
if (nsDescriptor != descriptor) {
final XmlDocument document = nsDescriptor.getDescriptorFile() != null ? nsDescriptor.getDescriptorFile().getDocument() : null;
if (document == null)
return null;
return findSpecialTag(XmlUtil.findLocalNameByQualifiedName(name), specialName, document.getRootTag(), nsDescriptor, visited);
}
if (visited == null)
visited = new HashSet<>(1);
else if (visited.contains(rootTag))
return null;
visited.add(rootTag);
XmlTag[] tags = rootTag.getSubTags();
return findSpecialTagIn(tags, specialName, name, rootTag, descriptor, visited);
}
Aggregations