From b09dc5d4121c004c42f1d245a062b832d31e29fa Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 23 Aug 2016 13:31:50 +0300 Subject: [PATCH] IDEA-159262 Incorrect treating of the element in the jsp page showing the problem like unused symbol --- .../src/messages/XmlBundle.properties | 2 +- .../src/META-INF/XmlPlugin.xml | 2 +- .../HtmlExtraClosingTagInspection.java | 17 +++------ .../src/com/intellij/xml/util/XmlTagUtil.java | 36 ++++++++++--------- .../messages/XmlErrorMessages.properties | 2 +- 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/platform/platform-resources-en/src/messages/XmlBundle.properties b/platform/platform-resources-en/src/messages/XmlBundle.properties index e2ffa0ad3f5f..ea5049b78f2c 100644 --- a/platform/platform-resources-en/src/messages/XmlBundle.properties +++ b/platform/platform-resources-en/src/messages/XmlBundle.properties @@ -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 diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index c68facba71ea..2d102b5eab08 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -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"/> - diff --git a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlExtraClosingTagInspection.java b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlExtraClosingTagInspection.java index cf1a07644717..a99cea201c3d 100644 --- a/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlExtraClosingTagInspection.java +++ b/xml/xml-analysis-impl/src/com/intellij/codeInspection/htmlInspections/HtmlExtraClosingTagInspection.java @@ -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()); } } } diff --git a/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java b/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java index 27a4aa32ca2d..54912c794d7b 100644 --- a/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java +++ b/xml/xml-psi-api/src/com/intellij/xml/util/XmlTagUtil.java @@ -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; } diff --git a/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties b/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties index d148c5163dcb..1fa6c3d4a141 100644 --- a/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties +++ b/xml/xml-psi-impl/resources/messages/XmlErrorMessages.properties @@ -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