IDEA-159262 Incorrect treating of the <link> element in the jsp page

showing the problem like unused symbol
This commit is contained in:
Dmitry Avdeev
2016-08-23 13:33:48 +03:00
parent 5de3184fb3
commit b09dc5d412
5 changed files with 27 additions and 32 deletions
@@ -66,7 +66,7 @@ html.inspections.unknown.anchor=Anchor reference problems
html.annotators.non.existent.internet.resource=Cannot find resource "{0}"
#HtmlExtraClosingTagInspection
html.inspection.extra.closing.tag=Extra closing tag for empty element
html.inspection.extra.closing.tag=Redundant closing tag for HTML element
xml.inspection.wrong.closing.tag=Wrong closing XML/xHTML tag
xml.inspection.wrong.root.element=Wrong root element
@@ -450,7 +450,7 @@
bundle="messages.InspectionsBundle" key="inspection.required.attributes.display.name"
groupBundle="messages.XmlBundle" groupKey="html.inspections.group.name"
implementationClass="com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection"/>
<localInspection language="XML" shortName="HtmlExtraClosingTag" enabledByDefault="true" level="ERROR"
<localInspection language="XML" shortName="HtmlExtraClosingTag" enabledByDefault="true" level="WARNING"
bundle="messages.XmlBundle" key="html.inspection.extra.closing.tag"
groupBundle="messages.XmlBundle" groupKey="html.inspections.group.name"
implementationClass="com.intellij.codeInspection.htmlInspections.HtmlExtraClosingTagInspection"/>
@@ -16,13 +16,12 @@
package com.intellij.codeInspection.htmlInspections;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInsight.daemon.XmlErrorMessages;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.html.HtmlTag;
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlToken;
import com.intellij.xml.XmlBundle;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlTagUtil;
@@ -49,19 +48,13 @@ public class HtmlExtraClosingTagInspection extends HtmlLocalInspectionTool {
return "HtmlExtraClosingTag";
}
@Override
@NotNull
public HighlightDisplayLevel getDefaultLevel() {
return HighlightDisplayLevel.ERROR;
}
@Override
protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
final XmlToken endTagName = XmlTagUtil.getEndTagNameElement(tag);
final TextRange range = XmlTagUtil.getEndTagRange(tag);
if (endTagName != null && tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag.getName())) {
holder.registerProblem(endTagName, XmlErrorMessages.message("extra.closing.tag.for.empty.element"),
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, new RemoveExtraClosingTagIntentionAction());
if (range != null && tag instanceof HtmlTag && HtmlUtil.isSingleHtmlTag(tag.getName())) {
holder.registerProblem(tag, XmlErrorMessages.message("extra.closing.tag.for.empty.element"),
ProblemHighlightType.LIKE_UNUSED_SYMBOL, range.shiftRight(-tag.getTextRange().getStartOffset()), new RemoveExtraClosingTagIntentionAction());
}
}
}
@@ -156,7 +156,7 @@ public class XmlTagUtil extends XmlTagUtilBase {
@Nullable
public static TextRange getStartTagRange(@NotNull XmlTag tag) {
XmlToken tagName = getStartTagNameElement(tag);
return getTag(tagName, XmlTokenType.XML_START_TAG_START);
return getTagRange(tagName, XmlTokenType.XML_START_TAG_START);
}
@@ -164,27 +164,29 @@ public class XmlTagUtil extends XmlTagUtilBase {
public static TextRange getEndTagRange(@NotNull XmlTag tag) {
XmlToken tagName = getEndTagNameElement(tag);
return getTag(tagName, XmlTokenType.XML_END_TAG_START);
return getTagRange(tagName, XmlTokenType.XML_END_TAG_START);
}
private static TextRange getTag(XmlToken tagName, IElementType tagStart) {
if (tagName != null) {
PsiElement s = tagName.getPrevSibling();
@Nullable
private static TextRange getTagRange(@Nullable XmlToken tagName, IElementType tagStart) {
if (tagName == null) {
return null;
}
PsiElement s = tagName.getPrevSibling();
while (s != null && s.getNode().getElementType() != tagStart) {
s = s.getPrevSibling();
}
while (s != null && s.getNode().getElementType() != tagStart) {
s = s.getPrevSibling();
}
PsiElement f = tagName.getNextSibling();
PsiElement f = tagName.getNextSibling();
while (f != null &&
!(f.getNode().getElementType() == XmlTokenType.XML_TAG_END ||
f.getNode().getElementType() == XmlTokenType.XML_EMPTY_ELEMENT_END)) {
f = f.getNextSibling();
}
if (s != null && f != null) {
return new TextRange(s.getTextRange().getStartOffset(), f.getTextRange().getEndOffset());
}
while (f != null &&
!(f.getNode().getElementType() == XmlTokenType.XML_TAG_END ||
f.getNode().getElementType() == XmlTokenType.XML_EMPTY_ELEMENT_END)) {
f = f.getNextSibling();
}
if (s != null && f != null) {
return new TextRange(s.getTextRange().getStartOffset(), f.getTextRange().getEndOffset());
}
return null;
}
@@ -4,7 +4,7 @@ unescaped.ampersand=Unescaped \\&
escape.ampersand.quickfix=Escape ampersand
rename.start.tag.name.intention=Rename start tag ''{0}'' to ''{1}''
rename.end.tag.name.intention=Rename end tag ''{0}'' to ''{1}''
extra.closing.tag.for.empty.element=Extra closing tag for empty element
extra.closing.tag.for.empty.element=Closing tag is redundant
wrong.closing.tag.name=Wrong closing tag name
tag.has.wrong.closing.tag.name=Start tag has wrong closing tag
element.is.not.allowed.here=Element {0} is not allowed here