IDEA-208504 First xi:include tag in *Plugin.xml file is highlighted as error

do not highlight problem with "xpointer" scheme not supported by Xerces
This commit is contained in:
Dmitry Avdeev
2019-03-19 14:23:17 +03:00
parent f35aa56c1e
commit 9cc668e939
2 changed files with 29 additions and 3 deletions
@@ -8,9 +8,25 @@ import com.intellij.xml.util.CheckXmlFileWithXercesValidatorInspection;
public class XmlSimpleHighlightingTest extends LightPlatformCodeInsightFixtureTestCase {
public void testCannotFindDeclaration() {
checkValidation("<idea-plugin xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n" +
"</idea-plugin>");
}
public void testUnsupportedIncludeScheme() {
checkValidation("<idea-plugin xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n" +
" <xi:include href=\"extensionPoints.xml\" xpointer=\"xpointer(/extensionPoints/*)\"/>\n" +
"</idea-plugin>");
}
public void testSupportedIncludeScheme() {
checkValidation("<idea-plugin xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n" +
" <<error descr=\"An 'include' failed, and no 'fallback' element was found.\">xi:include</error> href=\"extensionPoints.xml\" xpointer=\"element(/1111)\"/>\n" +
"</idea-plugin>");
}
private void checkValidation(String text) {
myFixture.enableInspections(CheckXmlFileWithXercesValidatorInspection.class);
myFixture.configureByText(XmlFileType.INSTANCE, "<idea-plugin xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n" +
"</idea-plugin>");
myFixture.configureByText(XmlFileType.INSTANCE, text);
myFixture.testHighlighting();
}
}
@@ -127,6 +127,8 @@ public class ExternalDocumentValidator {
};
myHandler.setErrorReporter(new ErrorReporter(myHandler) {
int unsupportedSchemeAt = -1;
@Override
public boolean isStopOnUndeclaredResource() {
return true;
@@ -159,7 +161,7 @@ public class ExternalDocumentValidator {
if (elementText.equals("</")) {
currentElement = currentElement.getNextSibling();
}
else if (elementText.equals(">") || elementText.equals("=")) {
else if (elementText.equals(">") || elementText.equals("/>") || elementText.equals("=")) {
currentElement = currentElement.getPrevSibling();
}
@@ -180,7 +182,15 @@ public class ExternalDocumentValidator {
// "Cannot find the declaration of element" is not helpful without schema
return;
}
} else if ("SchemeUnsupported".equals(messageId)) {
unsupportedSchemeAt = offset;
return;
} else if (unsupportedSchemeAt == offset &&
("An 'include' failed, and no 'fallback' element was found.".equals(localizedMessage) ||
(e.getLocalizedMessage().startsWith("Include operation failed, reverting to fallback.")))) {
return;
}
if (localizedMessage.startsWith(CANNOT_FIND_DECLARATION_ERROR_PREFIX) ||
localizedMessage.startsWith(ELEMENT_ERROR_PREFIX) ||
localizedMessage.startsWith(ROOT_ELEMENT_ERROR_PREFIX) ||