use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class RelaxedHtmlFromRngNSDescriptor method getElementDescriptor.
@Override
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);
if (LOG.isDebugEnabled()) {
LOG.debug("Descriptor from rng for tag " + tag.getName() + " is " + (elementDescriptor != null ? elementDescriptor.getClass().getCanonicalName() : "NULL"));
}
String namespace;
if (elementDescriptor == null && !((namespace = tag.getNamespace()).equals(XmlUtil.XHTML_URI))) {
return new AnyXmlElementDescriptor(null, XmlUtil.HTML_URI.equals(namespace) ? this : tag.getNSDescriptor(tag.getNamespace(), true));
}
return elementDescriptor;
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class TagNameVariantCollector method couldContainDescriptor.
static boolean couldContainDescriptor(final XmlTag parentTag, final XmlElementDescriptor parentDescriptor, final XmlElementDescriptor childDescriptor, String childNamespace, boolean strict) {
if (XmlUtil.nsFromTemplateFramework(childNamespace))
return true;
if (parentTag == null)
return true;
if (parentDescriptor == null)
return false;
final XmlTag childTag = parentTag.createChildTag(childDescriptor.getName(), childNamespace, null, false);
childTag.putUserData(XmlElement.INCLUDING_ELEMENT, parentTag);
XmlElementDescriptor descriptor = parentDescriptor.getElementDescriptor(childTag, parentTag);
return descriptor != null && (!strict || !(descriptor instanceof AnyXmlElementDescriptor));
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlTagImpl method computeElementDescriptor.
@Nullable
protected XmlElementDescriptor computeElementDescriptor() {
for (XmlElementDescriptorProvider provider : Extensions.getExtensions(XmlElementDescriptorProvider.EP_NAME)) {
XmlElementDescriptor elementDescriptor = provider.getDescriptor(this);
if (elementDescriptor != null) {
return elementDescriptor;
}
}
final String namespace = getNamespace();
if (XmlUtil.EMPTY_URI.equals(namespace)) {
//nonqualified items
final XmlTag parent = getParentTag();
if (parent != null) {
final XmlElementDescriptor descriptor = parent.getDescriptor();
if (descriptor != null) {
XmlElementDescriptor fromParent = descriptor.getElementDescriptor(this, parent);
if (fromParent != null && !(fromParent instanceof AnyXmlElementDescriptor)) {
return fromParent;
}
}
}
}
XmlElementDescriptor elementDescriptor = null;
final XmlNSDescriptor nsDescriptor = getNSDescriptor(namespace, false);
if (LOG.isDebugEnabled()) {
LOG.debug("Descriptor for namespace " + namespace + " is " + (nsDescriptor != null ? nsDescriptor.getClass().getCanonicalName() : "NULL"));
}
if (nsDescriptor != null) {
if (!DumbService.getInstance(getProject()).isDumb() || DumbService.isDumbAware(nsDescriptor)) {
elementDescriptor = nsDescriptor.getElementDescriptor(this);
}
}
if (elementDescriptor == null) {
return XmlUtil.findXmlDescriptorByType(this);
}
return elementDescriptor;
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class XmlEntityRefImpl method doResolveEntity.
private static CachedValueProvider.Result<XmlEntityDecl> doResolveEntity(final PsiElement targetElement, final String entityName, final PsiFile contextFile) {
return RecursionManager.doPreventingRecursion(targetElement, true, new Computable<CachedValueProvider.Result<XmlEntityDecl>>() {
@Override
public CachedValueProvider.Result<XmlEntityDecl> compute() {
final List<PsiElement> deps = new ArrayList<>();
final XmlEntityDecl[] result = { null };
PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof XmlDoctype) {
XmlDoctype xmlDoctype = (XmlDoctype) element;
final String dtdUri = getDtdForEntity(xmlDoctype);
if (dtdUri != null) {
XmlFile file = XmlUtil.getContainingFile(element);
if (file == null)
return true;
final XmlFile xmlFile = XmlUtil.findNamespace(file, dtdUri);
if (xmlFile != null) {
if (xmlFile != targetElement) {
deps.add(xmlFile);
if (!XmlUtil.processXmlElements(xmlFile, this, true))
return false;
}
}
}
final XmlMarkupDecl markupDecl = xmlDoctype.getMarkupDecl();
if (markupDecl != null) {
if (!XmlUtil.processXmlElements(markupDecl, this, true))
return false;
}
} else if (element instanceof XmlEntityDecl) {
XmlEntityDecl entityDecl = (XmlEntityDecl) element;
final String declName = entityDecl.getName();
if (StringUtil.equals(declName, entityName)) {
result[0] = entityDecl;
return false;
}
}
return true;
}
};
FileViewProvider provider = targetElement.getContainingFile().getViewProvider();
deps.add(provider.getPsi(provider.getBaseLanguage()));
boolean notfound = PsiTreeUtil.processElements(targetElement, processor);
if (notfound) {
if (contextFile != targetElement && contextFile != null && contextFile.isValid()) {
notfound = PsiTreeUtil.processElements(contextFile, processor);
}
}
if (// no dtd ref at all
notfound && targetElement instanceof XmlFile && deps.size() == 1 && ((XmlFile) targetElement).getFileType() != DTDFileType.INSTANCE) {
XmlDocument document = ((XmlFile) targetElement).getDocument();
final XmlTag rootTag = document != null ? document.getRootTag() : null;
XmlFile descriptorFile = null;
if (HtmlUtil.isHtml5Document(document)) {
descriptorFile = XmlUtil.findXmlFile((XmlFile) targetElement, Html5SchemaProvider.getCharsDtdLocation());
} else if (rootTag != null && document.getUserData(DISABLE_ENTITY_EXPAND) == null) {
final XmlElementDescriptor descriptor = rootTag.getDescriptor();
if (descriptor != null && !(descriptor instanceof AnyXmlElementDescriptor)) {
PsiElement element = descriptor.getDeclaration();
final PsiFile containingFile = element != null ? element.getContainingFile() : null;
descriptorFile = containingFile instanceof XmlFile ? (XmlFile) containingFile : null;
}
}
if (descriptorFile != null && !descriptorFile.getName().equals(((XmlFile) targetElement).getName() + ".dtd")) {
deps.add(descriptorFile);
XmlUtil.processXmlElements(descriptorFile, processor, true);
}
}
return new CachedValueProvider.Result<>(result[0], ArrayUtil.toObjectArray(deps));
}
});
}
use of com.intellij.xml.impl.schema.AnyXmlElementDescriptor in project intellij-community by JetBrains.
the class ExtendedTagInsertHandler method isNamespaceBound.
protected boolean isNamespaceBound(PsiElement psiElement) {
PsiElement parent = psiElement.getParent();
if (!(parent instanceof XmlTag))
return false;
final XmlTag tag = (XmlTag) parent;
final XmlElementDescriptor tagDescriptor = tag.getDescriptor();
final String tagNamespace = tag.getNamespace();
assert myNamespace != null;
return tagDescriptor != null && !(tagDescriptor instanceof AnyXmlElementDescriptor) && myNamespace.equals(tagNamespace);
}
Aggregations