mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
HTML: extract common 'unknown element inspection'
This commit is contained in:
@@ -66,7 +66,9 @@ class AttributeFinder extends RecursionSaveWalker {
|
||||
|
||||
if (depth == 1 && (myQname == null || p.getName().contains(myQname))) {
|
||||
myLastAttr = p;
|
||||
myAttributes.put(p, Pair.create(new LinkedHashMap<String, String>(), optional > 0));
|
||||
if (!myAttributes.containsKey(p)) {
|
||||
myAttributes.put(p, Pair.create(new LinkedHashMap<String, String>(), optional > 0));
|
||||
}
|
||||
return super.onAttribute(p);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -93,4 +93,8 @@ public class RngHtml5CompletionTest extends HighlightingTestBase {
|
||||
public void testHtml5_17() throws Throwable {
|
||||
doTestCompletion("html5_17");
|
||||
}
|
||||
|
||||
public void testHtml5_overwritten_attributes() throws Throwable {
|
||||
myTestFixture.testCompletionTyping("html5_overwritten_attributes.xml", "a\n", "html5_overwritten_attributes_after.xml");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<input autofocus="<caret>"/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,8 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<input autofocus="autofocus<caret>"/>
|
||||
</body>
|
||||
</html>
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.intellij.codeInspection.htmlInspections;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.JDOMExternalizableStringList;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlChildRole;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
abstract public class HtmlUnknownElementInspection extends HtmlLocalInspectionTool implements XmlEntitiesInspection {
|
||||
public boolean myCustomValuesEnabled = true;
|
||||
public JDOMExternalizableStringList myValues;
|
||||
|
||||
public HtmlUnknownElementInspection(@NotNull String defaultValues) {
|
||||
myValues = reparseProperties(defaultValues);
|
||||
}
|
||||
|
||||
protected static JDOMExternalizableStringList reparseProperties(@NotNull final String properties) {
|
||||
final JDOMExternalizableStringList result = new JDOMExternalizableStringList();
|
||||
|
||||
final StringTokenizer tokenizer = new StringTokenizer(properties, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
result.add(tokenizer.nextToken().toLowerCase().trim());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static void registerProblemOnAttributeName(@NotNull XmlAttribute attribute,
|
||||
String message, @NotNull ProblemsHolder holder,
|
||||
LocalQuickFix... quickfixes) {
|
||||
final ASTNode node = attribute.getNode();
|
||||
assert node != null;
|
||||
final ASTNode nameNode = XmlChildRole.ATTRIBUTE_NAME_FINDER.findChild(node);
|
||||
if (nameNode != null) {
|
||||
final PsiElement nameElement = nameNode.getPsi();
|
||||
if (nameElement.getTextLength() > 0) {
|
||||
holder.registerProblem(nameElement, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickfixes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isCustomValue(@NotNull final String value) {
|
||||
return myValues.contains(value.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntry(@NotNull final String text) {
|
||||
final String s = text.trim().toLowerCase();
|
||||
if (!isCustomValue(s)) {
|
||||
myValues.add(s);
|
||||
}
|
||||
|
||||
if (!isCustomValuesEnabled()) {
|
||||
myCustomValuesEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCustomValuesEnabled() {
|
||||
return myCustomValuesEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAdditionalEntries() {
|
||||
return StringUtil.join(myValues, ",");
|
||||
}
|
||||
|
||||
public void enableCustomValues(boolean customValuesEnabled) {
|
||||
myCustomValuesEnabled = customValuesEnabled;
|
||||
}
|
||||
|
||||
public void updateAdditionalEntries(@NotNull final String values) {
|
||||
myValues = reparseProperties(values);
|
||||
}
|
||||
|
||||
protected abstract String getCheckboxTitle();
|
||||
|
||||
@NotNull
|
||||
protected abstract String getPanelTitle();
|
||||
|
||||
@NotNull
|
||||
protected abstract Logger getLogger();
|
||||
}
|
||||
Reference in New Issue
Block a user