use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlElementDescriptorImpl method getNsDescriptorFrom.
@Nullable
private static XmlNSDescriptor getNsDescriptorFrom(final PsiElement elementDecl) {
final XmlFile file = XmlUtil.getContainingFile(elementDecl);
if (file == null) {
return null;
}
final XmlDocument document = file.getDocument();
assert document != null;
XmlNSDescriptor descriptor = (XmlNSDescriptor) document.getMetaData();
return descriptor == null ? document.getDefaultNSDescriptor(XmlUtil.EMPTY_URI, false) : descriptor;
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlDocumentImpl method getDefaultNSDescriptor.
@Override
public XmlNSDescriptor getDefaultNSDescriptor(final String namespace, final boolean strict) {
long curExtResourcesModCount = ExternalResourceManagerEx.getInstanceEx().getModificationCount(getProject());
if (myExtResourcesModCount != curExtResourcesModCount) {
myDefaultDescriptorsCacheNotStrict.clear();
myDefaultDescriptorsCacheStrict.clear();
myExtResourcesModCount = curExtResourcesModCount;
}
final ConcurrentMap<String, CachedValue<XmlNSDescriptor>> defaultDescriptorsCache;
if (strict) {
defaultDescriptorsCache = myDefaultDescriptorsCacheStrict;
} else {
defaultDescriptorsCache = myDefaultDescriptorsCacheNotStrict;
}
CachedValue<XmlNSDescriptor> cachedValue = defaultDescriptorsCache.get(namespace);
if (cachedValue == null) {
defaultDescriptorsCache.put(namespace, cachedValue = new PsiCachedValueImpl<>(getManager(), () -> {
final XmlNSDescriptor defaultNSDescriptorInner = getDefaultNSDescriptorInner(namespace, strict);
if (isGeneratedFromDtd(defaultNSDescriptorInner)) {
return new CachedValueProvider.Result<>(defaultNSDescriptorInner, this, ExternalResourceManager.getInstance());
}
return new CachedValueProvider.Result<>(defaultNSDescriptorInner, defaultNSDescriptorInner != null ? defaultNSDescriptorInner.getDependences() : ExternalResourceManager.getInstance());
}));
}
return cachedValue.getValue();
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class XmlCompletionContributor method addEntityRefCompletions.
private static void addEntityRefCompletions(PsiElement context, CompletionResultSet resultSet) {
XmlFile containingFile = null;
XmlFile descriptorFile = null;
final XmlTag tag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
if (tag != null) {
containingFile = (XmlFile) tag.getContainingFile();
descriptorFile = findDescriptorFile(tag, containingFile);
}
if (HtmlUtil.isHtml5Context(tag)) {
descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
} else if (tag == null) {
final XmlDocument document = PsiTreeUtil.getParentOfType(context, XmlDocument.class);
if (document != null) {
containingFile = (XmlFile) document.getContainingFile();
final FileType ft = containingFile.getFileType();
if (HtmlUtil.isHtml5Document(document)) {
descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
} else if (ft != StdFileTypes.XML) {
final String namespace = ft == StdFileTypes.XHTML || ft == StdFileTypes.JSPX ? XmlUtil.XHTML_URI : XmlUtil.HTML_URI;
final XmlNSDescriptor nsDescriptor = document.getDefaultNSDescriptor(namespace, true);
if (nsDescriptor != null) {
descriptorFile = nsDescriptor.getDescriptorFile();
}
}
}
}
if (descriptorFile != null && containingFile != null) {
final boolean acceptSystemEntities = containingFile.getFileType() == StdFileTypes.XML;
final PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof XmlEntityDecl) {
final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl) element;
if (xmlEntityDecl.isInternalReference() || acceptSystemEntities) {
final LookupElementBuilder _item = buildEntityLookupItem(xmlEntityDecl);
if (_item != null) {
resultSet.addElement(_item);
resultSet.stopHere();
}
}
}
return true;
}
};
XmlUtil.processXmlElements(descriptorFile, processor, true);
if (descriptorFile != containingFile && acceptSystemEntities) {
final XmlProlog element = containingFile.getDocument().getProlog();
if (element != null)
XmlUtil.processXmlElements(element, processor, true);
}
}
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class DtdResolveUtil method getNsDescriptor.
@Nullable
static XmlNSDescriptor getNsDescriptor(XmlElement element) {
final XmlElement parentThatProvidesMetaData = PsiTreeUtil.getParentOfType(CompletionUtilCoreImpl.getOriginalElement(element), XmlDocument.class, XmlMarkupDecl.class);
if (parentThatProvidesMetaData instanceof XmlDocument) {
final XmlDocument document = (XmlDocument) parentThatProvidesMetaData;
XmlNSDescriptor rootTagNSDescriptor = document.getRootTagNSDescriptor();
if (rootTagNSDescriptor == null)
rootTagNSDescriptor = (XmlNSDescriptor) document.getMetaData();
return rootTagNSDescriptor;
} else if (parentThatProvidesMetaData instanceof XmlMarkupDecl) {
final XmlMarkupDecl markupDecl = (XmlMarkupDecl) parentThatProvidesMetaData;
final PsiMetaData psiMetaData = markupDecl.getMetaData();
if (psiMetaData instanceof XmlNSDescriptor) {
return (XmlNSDescriptor) psiMetaData;
}
}
return null;
}
use of com.intellij.xml.XmlNSDescriptor in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getVariants.
public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
String[] tagNames = null;
switch(type) {
case GroupReference:
tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
break;
case AttributeGroupReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
break;
case AttributeReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
break;
case ElementReference:
tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
break;
case TypeReference:
tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
break;
}
final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
if (document == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final XmlTag rootTag = document.getRootTag();
String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
if (ourNamespace == null)
ourNamespace = "";
CompletionProcessor processor = new CompletionProcessor(tag, prefix);
for (String namespace : tag.knownNamespaces()) {
if (ourNamespace.equals(namespace))
continue;
final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
}
XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
return ArrayUtil.toStringArray(processor.myElements);
}
Aggregations