mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more accurate html5 support by using XmlUtil.getDtdUri
This commit is contained in:
@@ -15,23 +15,14 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.html;
|
||||
|
||||
import com.intellij.javaee.ExternalResourceManagerImpl;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.impl.source.xml.XmlDocumentImpl;
|
||||
import com.intellij.psi.xml.XmlElementType;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.xml.XmlNSDescriptor;
|
||||
import com.intellij.xml.util.XmlUtil;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class HtmlDocumentImpl extends XmlDocumentImpl {
|
||||
private static final String HTML5_SCHEMA = "html5/xhtml5.xsd";
|
||||
|
||||
public HtmlDocumentImpl() {
|
||||
super(XmlElementType.HTML_DOCUMENT);
|
||||
}
|
||||
@@ -39,11 +30,4 @@ public class HtmlDocumentImpl extends XmlDocumentImpl {
|
||||
public XmlTag getRootTag() {
|
||||
return (XmlTag)findElementByTokenType(XmlElementType.HTML_TAG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XmlFile getNsDescriptorWhenEmptyDocType(XmlFile containingFile) {
|
||||
URL schemaLocation = getClass().getResource(ExternalResourceManagerImpl.STANDARD_SCHEMAS + HTML5_SCHEMA);
|
||||
String path = FileUtil.toSystemIndependentName(schemaLocation.getPath().substring(1));
|
||||
return XmlUtil.findNamespace(containingFile, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.intellij.xml.util.XmlUtil;
|
||||
import gnu.trove.TObjectIntHashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -190,7 +189,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
|
||||
return new HtmlNSDescriptorImpl(nsDescriptor);
|
||||
}
|
||||
else if (namespace != null && namespace != XmlUtil.EMPTY_URI) {
|
||||
if (doctype == null || !namespace.equals(doctype.getDtdUri())) {
|
||||
if (doctype == null || !namespace.equals(XmlUtil.getDtdUri(doctype))) {
|
||||
boolean documentIsSchemaThatDefinesNs = namespace.equals(XmlUtil.getTargetSchemaNsFromTag(getRootTag()));
|
||||
|
||||
final XmlFile xmlFile = documentIsSchemaThatDefinesNs
|
||||
@@ -240,7 +239,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
|
||||
return null;
|
||||
}
|
||||
|
||||
XmlNSDescriptor getNsDescriptorFormDocType(final XmlDoctype doctype, final XmlFile containingFile) {
|
||||
private XmlNSDescriptor getNsDescriptorFormDocType(final XmlDoctype doctype, final XmlFile containingFile) {
|
||||
XmlNSDescriptor descr = null;
|
||||
if (doctype.getMarkupDecl() != null){
|
||||
descr = (XmlNSDescriptor)doctype.getMarkupDecl().getMetaData();
|
||||
@@ -248,29 +247,20 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument {
|
||||
if (rootElementsDescriptors.length == 0) descr = null;
|
||||
}
|
||||
|
||||
XmlFile xmlFile = null;
|
||||
|
||||
final String dtdUri = doctype.getDtdUri();
|
||||
if (dtdUri == null && descr == null) {
|
||||
xmlFile = getNsDescriptorWhenEmptyDocType(containingFile);
|
||||
} else if (dtdUri != null && dtdUri.length() > 0){
|
||||
xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
|
||||
}
|
||||
|
||||
final XmlNSDescriptor descr1 = xmlFile == null ? null : (XmlNSDescriptor)xmlFile.getDocument().getMetaData();
|
||||
if (descr != null && descr1 != null){
|
||||
descr = new XmlNSDescriptorSequence(new XmlNSDescriptor[]{descr, descr1});
|
||||
}
|
||||
else if (descr1 != null) {
|
||||
descr = descr1;
|
||||
final String dtdUri = XmlUtil.getDtdUri(doctype);
|
||||
if (dtdUri != null && dtdUri.length() > 0){
|
||||
final XmlFile xmlFile = XmlUtil.findNamespace(containingFile, dtdUri);
|
||||
final XmlNSDescriptor descr1 = xmlFile == null ? null : (XmlNSDescriptor)xmlFile.getDocument().getMetaData();
|
||||
if (descr != null && descr1 != null){
|
||||
descr = new XmlNSDescriptorSequence(new XmlNSDescriptor[]{descr, descr1});
|
||||
}
|
||||
else if (descr1 != null) {
|
||||
descr = descr1;
|
||||
}
|
||||
}
|
||||
return descr;
|
||||
}
|
||||
|
||||
protected @Nullable XmlFile getNsDescriptorWhenEmptyDocType(XmlFile containingFile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
HashMap<String, CachedValue<XmlNSDescriptor>> cacheStrict = new HashMap<String, CachedValue<XmlNSDescriptor>>(
|
||||
myDefaultDescriptorsCacheStrict
|
||||
|
||||
@@ -143,7 +143,7 @@ public class XmlEntityRefImpl extends XmlElementImpl implements XmlEntityRef {
|
||||
public boolean execute(PsiElement element) {
|
||||
if (element instanceof XmlDoctype) {
|
||||
XmlDoctype xmlDoctype = (XmlDoctype)element;
|
||||
final String dtdUri = xmlDoctype.getDtdUri();
|
||||
final String dtdUri = XmlUtil.getDtdUri(xmlDoctype);
|
||||
if (dtdUri != null) {
|
||||
final XmlFile xmlFile = XmlUtil.findNamespace(XmlUtil.getContainingFile(element), dtdUri);
|
||||
if (xmlFile != null) {
|
||||
|
||||
@@ -191,12 +191,11 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag {
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
XmlDoctype docType = XmlUtil.getDocType(document);
|
||||
if (document instanceof XmlDocumentImpl && docType != null) {
|
||||
return ((XmlDocumentImpl)document).getNsDescriptorFormDocType(docType, containingFile);
|
||||
final String url = XmlUtil.getDtdUri(document);
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return document.getDefaultNSDescriptor(url, true);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.completion.CompletionUtil;
|
||||
import com.intellij.codeInsight.daemon.Validator;
|
||||
import com.intellij.javaee.ExternalResourceManager;
|
||||
import com.intellij.javaee.ExternalResourceManagerEx;
|
||||
import com.intellij.javaee.ExternalResourceManagerImpl;
|
||||
import com.intellij.javaee.UriUtil;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
@@ -35,6 +36,7 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -47,6 +49,7 @@ import com.intellij.psi.XmlElementFactory;
|
||||
import com.intellij.psi.filters.ElementFilter;
|
||||
import com.intellij.psi.filters.XmlTagFilter;
|
||||
import com.intellij.psi.filters.position.FilterPattern;
|
||||
import com.intellij.psi.impl.source.html.HtmlDocumentImpl;
|
||||
import com.intellij.psi.impl.source.xml.XmlEntityRefImpl;
|
||||
import com.intellij.psi.scope.processor.FilterElementProcessor;
|
||||
import com.intellij.psi.search.PsiElementProcessor;
|
||||
@@ -68,6 +71,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
@@ -942,16 +946,33 @@ public class XmlUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static final String HTML5_SCHEMA_LOCATION;
|
||||
|
||||
static {
|
||||
URL schemaLocation = XmlUtil.class.getResource(ExternalResourceManagerImpl.STANDARD_SCHEMAS + "html5/xhtml5.xsd");
|
||||
HTML5_SCHEMA_LOCATION = FileUtil.toSystemIndependentName(schemaLocation.getPath().substring(1));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getDtdUri(XmlDocument document) {
|
||||
XmlDoctype docType = getDocType(document);
|
||||
return docType != null ? docType.getDtdUri() : null;
|
||||
}
|
||||
|
||||
public @Nullable static XmlDoctype getDocType(XmlDocument document) {
|
||||
XmlProlog prolog = document.getProlog();
|
||||
return prolog != null ? prolog.getDoctype():null;
|
||||
if (prolog != null) {
|
||||
return getDtdUri( prolog.getDoctype() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getDtdUri(XmlDoctype doctype) {
|
||||
if (doctype != null) {
|
||||
String docType = doctype.getDtdUri();
|
||||
if (docType == null &&
|
||||
PsiTreeUtil.getParentOfType(doctype, XmlDocument.class) instanceof HtmlDocumentImpl) {
|
||||
docType = HTML5_SCHEMA_LOCATION;
|
||||
}
|
||||
return docType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void computeTag(XmlTag tag,
|
||||
|
||||
Reference in New Issue
Block a user