mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
HtmlUtil.isScriptTag
This commit is contained in:
@@ -25,7 +25,11 @@ import com.intellij.psi.filters.getters.HtmlAttributeValueGetter;
|
||||
import com.intellij.psi.filters.getters.XmlAttributeValueGetter;
|
||||
import com.intellij.psi.filters.position.XmlTokenTypeFilter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.psi.xml.XmlToken;
|
||||
import com.intellij.psi.xml.XmlTokenType;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
@@ -36,7 +40,6 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
private boolean myCaseInsensitive;
|
||||
private static final @NonNls String JAVASCRIPT_LANGUAGE_ID = "JavaScript";
|
||||
private static final @NonNls String STYLE_TAG = "style";
|
||||
private static final @NonNls String SCRIPT_TAG = "script";
|
||||
|
||||
public HtmlCompletionData() {
|
||||
this(true);
|
||||
@@ -46,6 +49,7 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
myCaseInsensitive = _caseInsensitive;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElementFilter createXmlEntityCompletionFilter() {
|
||||
if (isCaseInsensitive()) {
|
||||
return new AndFilter(
|
||||
@@ -77,12 +81,15 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
myCaseInsensitive = caseInsensitive;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XmlAttributeValueGetter getAttributeValueGetter() {
|
||||
return new HtmlAttributeValueGetter(!isCaseInsensitive());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElementFilter createTagCompletionFilter() {
|
||||
return new ElementFilter() {
|
||||
@Override
|
||||
public boolean isAcceptable(Object element, PsiElement context) {
|
||||
String name = ((XmlTag)context).getName();
|
||||
|
||||
@@ -92,7 +99,7 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
}
|
||||
|
||||
if (equalNames(name, STYLE_TAG) ||
|
||||
equalNames(name,SCRIPT_TAG)) {
|
||||
equalNames(name, HtmlUtil.SCRIPT_TAG_NAME)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,33 +107,40 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClassAcceptable(Class hintClass) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElementFilter createAttributeCompletionFilter() {
|
||||
return new ElementFilter() {
|
||||
@Override
|
||||
public boolean isAcceptable(Object element, PsiElement context) {
|
||||
if (isStyleAttributeContext(context)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClassAcceptable(Class hintClass) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ElementFilter createAttributeValueCompletionFilter() {
|
||||
return new ElementFilter() {
|
||||
@Override
|
||||
public boolean isAcceptable(Object element, PsiElement context) {
|
||||
if (isStyleAttributeContext(context)) return false;
|
||||
if ( isScriptContext((PsiElement)element) ) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClassAcceptable(Class hintClass) {
|
||||
return true;
|
||||
}
|
||||
@@ -151,11 +165,13 @@ public class HtmlCompletionData extends XmlCompletionData {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerVariant(CompletionVariant variant) {
|
||||
super.registerVariant(variant);
|
||||
if (isCaseInsensitive()) variant.setCaseInsensitive(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findPrefix(PsiElement insertedElement, int offset) {
|
||||
String prefix = super.findPrefix(insertedElement, offset);
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.html.HtmlTag;
|
||||
import com.intellij.psi.impl.source.xml.TagNameVariantCollector;
|
||||
import com.intellij.psi.impl.source.xml.XmlDocumentImpl;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -34,6 +33,7 @@ import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.psi.xml.XmlText;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.XmlNSDescriptor;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class XmlMover extends LineMover {
|
||||
@@ -62,11 +62,7 @@ class XmlMover extends LineMover {
|
||||
if (checkInjections(movedEndElement, movedStartElement)) return false;
|
||||
|
||||
XmlTag nearestTag = PsiTreeUtil.getParentOfType(movedStartElement, XmlTag.class);
|
||||
if (nearestTag != null &&
|
||||
( "script".equals(nearestTag.getLocalName()) ||
|
||||
(nearestTag instanceof HtmlTag && "script".equalsIgnoreCase(nearestTag.getLocalName()))
|
||||
)
|
||||
) {
|
||||
if (nearestTag != null && HtmlUtil.isScriptTag(nearestTag)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -69,7 +70,7 @@ class HtmlTagTreeElement extends PsiTreeElementBase<XmlTag> implements LocationP
|
||||
return null;
|
||||
}
|
||||
|
||||
if (tag.getName().equalsIgnoreCase("img") || tag.getName().equalsIgnoreCase("script")) {
|
||||
if (tag.getName().equalsIgnoreCase("img") || HtmlUtil.isScriptTag(tag)) {
|
||||
return getPathDescription(tag.getAttributeValue("src"));
|
||||
}
|
||||
else if (tag.getName().equalsIgnoreCase("link")) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class HtmlScriptLanguageInjector implements MultiHostInjector {
|
||||
return;
|
||||
}
|
||||
XmlTag scriptTag = ((XmlText)host).getParentTag();
|
||||
if (scriptTag == null || !"script".equalsIgnoreCase(scriptTag.getLocalName())) {
|
||||
if (scriptTag == null || !HtmlUtil.isScriptTag(scriptTag)) {
|
||||
return;
|
||||
}
|
||||
String mimeType = scriptTag.getAttributeValue("type");
|
||||
|
||||
@@ -44,8 +44,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class CheckEmptyTagInspection extends XmlSuppressableInspectionTool {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.xml.util.CheckEmptyTagInspection");
|
||||
@NonNls private static final String SCRIPT_TAG_NAME = "script";
|
||||
@NonNls private static final Set<String> ourTagsWithEmptyEndsNotAllowed = new THashSet<String>(Arrays.asList(SCRIPT_TAG_NAME, "div", "iframe"));
|
||||
@NonNls private static final Set<String> ourTagsWithEmptyEndsNotAllowed = new THashSet<String>(Arrays.asList(HtmlUtil.SCRIPT_TAG_NAME, "div", "iframe"));
|
||||
|
||||
@Override
|
||||
public boolean isEnabledByDefault() {
|
||||
|
||||
+2
-4
@@ -41,8 +41,6 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
|
||||
protected static final String AMP_ENTITY_REFERENCE = "&";
|
||||
@NonNls
|
||||
protected static final String LT_ENTITY_REFERENCE = "<";
|
||||
@NonNls
|
||||
private static final String SCRIPT_TAG_NAME = "script";
|
||||
private Lexer myXmlLexer;
|
||||
|
||||
@Override
|
||||
@@ -57,8 +55,8 @@ public class CheckValidXmlInScriptBodyInspectionBase extends XmlSuppressableInsp
|
||||
@Override public void visitXmlTag(final XmlTag tag) {
|
||||
if (HtmlUtil.isHtmlTag(tag)) return;
|
||||
|
||||
if (SCRIPT_TAG_NAME.equals(tag.getName()) ||
|
||||
tag instanceof HtmlTag && SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
|
||||
if (HtmlUtil.SCRIPT_TAG_NAME.equals(tag.getName()) ||
|
||||
tag instanceof HtmlTag && HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
|
||||
final PsiFile psiFile = tag.getContainingFile();
|
||||
final FileType fileType = psiFile.getFileType();
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.xml.*;
|
||||
import com.intellij.xml.XmlElementDescriptor;
|
||||
import com.intellij.xml.util.HtmlPsiUtil;
|
||||
import com.intellij.xml.util.HtmlUtil;
|
||||
import com.intellij.xml.util.XmlPsiUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -41,7 +41,6 @@ import java.util.List;
|
||||
public class ScriptSupportUtil {
|
||||
private static final Key<CachedValue<XmlTag[]>> CachedScriptTagsKey = Key.create("script tags");
|
||||
private static final ThreadLocal<String> ProcessingDeclarationsFlag = new ThreadLocal<String>();
|
||||
@NonNls private static final String SCRIPT_TAG = "script";
|
||||
|
||||
private ScriptSupportUtil() {
|
||||
}
|
||||
@@ -66,13 +65,14 @@ public class ScriptSupportUtil {
|
||||
|
||||
if (document != null) {
|
||||
PsiElementProcessor psiElementProcessor = new PsiElementProcessor() {
|
||||
@Override
|
||||
public boolean execute(@NotNull final PsiElement element) {
|
||||
if (element instanceof XmlTag) {
|
||||
final XmlTag tag = (XmlTag)element;
|
||||
|
||||
if (SCRIPT_TAG.equalsIgnoreCase(tag.getName())) {
|
||||
if (HtmlUtil.SCRIPT_TAG_NAME.equalsIgnoreCase(tag.getName())) {
|
||||
final XmlElementDescriptor descriptor = tag.getDescriptor();
|
||||
if (descriptor != null && SCRIPT_TAG.equals(descriptor.getName())) {
|
||||
if (descriptor != null && HtmlUtil.SCRIPT_TAG_NAME.equals(descriptor.getName())) {
|
||||
scriptTags.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ public class HtmlUtil {
|
||||
@NonNls private static final String CHARSET_PREFIX = CHARSET+"=";
|
||||
@NonNls private static final String HTML5_DATA_ATTR_PREFIX = "data-";
|
||||
|
||||
public static final String SCRIPT_TAG_NAME = "script";
|
||||
|
||||
public static final String[] CONTENT_TYPES =
|
||||
{"application/activemessage", "application/andrew-inset", "application/applefile", "application/atomicmail", "application/dca-rft",
|
||||
"application/dec-dx", "application/mac-binhex40"
|
||||
@@ -488,7 +490,7 @@ public class HtmlUtil {
|
||||
public void endTag(final CharSequence localName, final String namespace, final int startoffset, final int endoffset) {
|
||||
@NonNls final String name = localName.toString().toLowerCase();
|
||||
if ("meta".equals(name) && (metHttpEquiv || metHttml5Charset) && contentAttributeValue != null) {
|
||||
String charsetName = null;
|
||||
String charsetName;
|
||||
if (metHttpEquiv) {
|
||||
int start = contentAttributeValue.indexOf(CHARSET_PREFIX);
|
||||
if (start == -1) return;
|
||||
@@ -607,7 +609,7 @@ public class HtmlUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isScriptTag(@NotNull HtmlTag tag) {
|
||||
return tag.getName().equalsIgnoreCase("script");
|
||||
public static boolean isScriptTag(@NotNull XmlTag tag) {
|
||||
return tag.getLocalName().equalsIgnoreCase(SCRIPT_TAG_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user