mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-37146 Wrap every namespace descriptor of HTML tags with HTML namespace descriptor.
This change allows to contribute attributes (like 'data-*') to every element in HTML-like file; including those coming from e.g. SVG namespaces. GitOrigin-RevId: 087b606572047729843a274b89724178fdcc4845
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3e933075dc
commit
eb489aed8e
+11
-6
@@ -69,10 +69,9 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
|
||||
|
||||
@Override
|
||||
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag) {
|
||||
String name = element.getName();
|
||||
if (!myCaseSensitive) name = StringUtil.toLowerCase(name);
|
||||
String name = toLowerCaseIfNeeded(element.getName());
|
||||
|
||||
XmlElementDescriptor xmlElementDescriptor = getElementDescriptor(name, element);
|
||||
XmlElementDescriptor xmlElementDescriptor = getElementDescriptor(name, contextTag);
|
||||
if (xmlElementDescriptor == null && "html".equals(getName())) {
|
||||
XmlTag head = null;
|
||||
XmlTag body = null;
|
||||
@@ -111,7 +110,8 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
|
||||
final XmlElementDescriptor[] elementDescriptors = myDelegate.getElementsDescriptors(element);
|
||||
|
||||
for (XmlElementDescriptor elementDescriptor : elementDescriptors) {
|
||||
hashMap.put(elementDescriptor.getName(), new HtmlElementDescriptorImpl(elementDescriptor, myRelaxed, myCaseSensitive));
|
||||
hashMap.put(toLowerCaseIfNeeded(elementDescriptor.getName(element)),
|
||||
new HtmlElementDescriptorImpl(elementDescriptor, myRelaxed, myCaseSensitive));
|
||||
}
|
||||
return hashMap;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
|
||||
|
||||
@Override
|
||||
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
|
||||
String caseSensitiveAttributeName = !myCaseSensitive ? StringUtil.toLowerCase(attributeName) : attributeName;
|
||||
String caseSensitiveAttributeName = toLowerCaseIfNeeded(attributeName);
|
||||
XmlAttributeDescriptor descriptor = super.getAttributeDescriptor(caseSensitiveAttributeName, context);
|
||||
if (descriptor == null) descriptor = RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(attributeName, context);
|
||||
|
||||
@@ -159,7 +159,7 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
|
||||
|
||||
for (final XmlAttributeDescriptor attributeDescriptor : elementAttributeDescriptors) {
|
||||
hashMap.put(
|
||||
attributeDescriptor.getName(),
|
||||
toLowerCaseIfNeeded(attributeDescriptor.getName(context)),
|
||||
new HtmlAttributeDescriptorImpl(attributeDescriptor, myCaseSensitive)
|
||||
);
|
||||
}
|
||||
@@ -228,4 +228,9 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl {
|
||||
public boolean isCaseSensitive() {
|
||||
return myCaseSensitive;
|
||||
}
|
||||
|
||||
private String toLowerCaseIfNeeded(String name) {
|
||||
return isCaseSensitive() ? name : StringUtil.toLowerCase(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -340,6 +340,10 @@ public abstract class XmlTagDelegate {
|
||||
return new Result<>(null, tag, file[0] == null ? tag : file[0],
|
||||
ExternalResourceManager.getInstance());
|
||||
}
|
||||
XmlExtension extension = XmlExtension.getExtensionByElement(tag);
|
||||
if (extension != null) {
|
||||
descriptor = extension.wrapNSDescriptor(tag, descriptor);
|
||||
}
|
||||
return new Result<>(descriptor, descriptor.getDependencies(), tag);
|
||||
}, false));
|
||||
|
||||
@@ -844,8 +848,8 @@ public abstract class XmlTagDelegate {
|
||||
processChildren(element -> {
|
||||
if (element instanceof XmlAttribute
|
||||
&& ((XmlAttribute)element).isNamespaceDeclaration()) {
|
||||
result.set(Boolean.TRUE);
|
||||
return false;
|
||||
result.set(Boolean.TRUE);
|
||||
return false;
|
||||
}
|
||||
return !(element instanceof XmlToken)
|
||||
|| ((XmlToken)element).getTokenType() != XmlTokenType.XML_TAG_END;
|
||||
@@ -1076,5 +1080,4 @@ public abstract class XmlTagDelegate {
|
||||
protected TreeElement genericInsert(TreeElement child, ASTNode anchor, boolean before) {
|
||||
return addInternalSuper(child, child, anchor, before);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.html.HtmlTag;
|
||||
import com.intellij.psi.impl.source.html.dtd.HtmlNSDescriptorImpl;
|
||||
import com.intellij.psi.impl.source.xml.SchemaPrefix;
|
||||
import com.intellij.psi.impl.source.xml.TagNameReference;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
@@ -126,6 +128,14 @@ public abstract class XmlExtension {
|
||||
return element.getNSDescriptor(namespace, strict);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public XmlNSDescriptor wrapNSDescriptor(@NotNull XmlTag element, @NotNull XmlNSDescriptor descriptor) {
|
||||
if (element instanceof HtmlTag && !(descriptor instanceof HtmlNSDescriptorImpl)) {
|
||||
return new HtmlNSDescriptorImpl(descriptor);
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public XmlTag getParentTagForNamespace(XmlTag tag, XmlNSDescriptor namespace) {
|
||||
return tag.getParentTag();
|
||||
|
||||
@@ -17,8 +17,8 @@ package com.intellij.xml.impl.dtd;
|
||||
|
||||
import com.intellij.openapi.util.FieldCache;
|
||||
import com.intellij.openapi.util.SimpleFieldCache;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.xml.XmlAttributeDescriptor;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.XmlElementsGroup;
|
||||
@@ -141,8 +141,8 @@ public abstract class BaseXmlElementDescriptorImpl implements XmlElementDescript
|
||||
};
|
||||
|
||||
@Override
|
||||
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag){
|
||||
return myElementDescriptorsMapCache.get(null, this, element).get(element.getName());
|
||||
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag) {
|
||||
return myElementDescriptorsMapCache.get(null, this, contextTag).get(element.getName());
|
||||
}
|
||||
|
||||
public final XmlElementDescriptor getElementDescriptor(String name, XmlTag context){
|
||||
|
||||
Reference in New Issue
Block a user