diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java
index 3da301a23b8a..7a6752a79b04 100644
--- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java
+++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java
@@ -46,9 +46,10 @@ import java.util.List;
public class AddXsiSchemaLocationForExtResourceAction extends BaseExtResourceAction {
@NonNls private static final String XMLNS_XSI_ATTR_NAME = "xmlns:xsi";
@NonNls private static final String XSI_SCHEMA_LOCATION_ATTR_NAME = "xsi:schemaLocation";
+ public static final String KEY = "add.xsi.schema.location.for.external.resource";
protected String getQuickFixKeyId() {
- return "add.xsi.schema.location.for.external.resource";
+ return KEY;
}
protected void doInvoke(@NotNull final PsiFile file, final int offset, @NotNull final String uri, final Editor editor) throws IncorrectOperationException {
@@ -92,6 +93,7 @@ public class AddXsiSchemaLocationForExtResourceAction extends BaseExtResourceAct
CodeStyleManager.getInstance(file.getProject()).reformat(tag);
+ @SuppressWarnings("ConstantConditions")
final TextRange range = tag.getAttribute(XSI_SCHEMA_LOCATION_ATTR_NAME).getValueElement().getTextRange();
final TextRange textRange = new TextRange(range.getEndOffset() - offset - 1, range.getEndOffset() - 1);
editor.getCaretModel().moveToOffset(textRange.getStartOffset());
@@ -105,8 +107,10 @@ public class AddXsiSchemaLocationForExtResourceAction extends BaseExtResourceAct
XmlAttributeValue value = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class);
if (value == null) return false;
XmlAttribute attribute = PsiTreeUtil.getParentOfType(value, XmlAttribute.class);
- if (attribute == null || !"xmlns".equals(attribute.getLocalName())) return false;
- setText(XmlBundle.message(getQuickFixKeyId()));
- return true;
+ if (attribute != null && attribute.isNamespaceDeclaration()) {
+ setText(XmlBundle.message(getQuickFixKeyId()));
+ return true;
+ }
+ return false;
}
}
\ No newline at end of file
diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java
index 5e9dfb510802..20d00f35fa9e 100644
--- a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java
+++ b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor;
import com.intellij.codeInsight.daemon.impl.analysis.XmlUnboundNsPrefixInspection;
+import com.intellij.codeInsight.daemon.impl.quickfix.AddXsiSchemaLocationForExtResourceAction;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.htmlInspections.HtmlUnknownTagInspection;
@@ -1193,10 +1194,11 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase {
public void testSpecifyXsiSchemaLocationQuickFix() throws Exception {
configureByFile(BASE_PATH + "web-app_2_4.xsd");
final String testName = getTestName(false);
- final String actionName = XmlBundle.message("add.xsi.schema.location.for.external.resource");
+ final String actionName = XmlBundle.message(AddXsiSchemaLocationForExtResourceAction.KEY);
doTestWithQuickFix(BASE_PATH + testName, actionName, true);
doTestWithQuickFix(BASE_PATH + testName + "2", actionName, true);
doTestWithQuickFix(BASE_PATH + testName + "3", actionName, true);
+ doTestWithQuickFix(BASE_PATH + testName + "4", actionName, true);
}
public void testHighlightingWithConditionalSectionsInDtd() throws Exception {
diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4.xml
new file mode 100644
index 000000000000..7b4ece84b539
--- /dev/null
+++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4_after.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4_after.xml
new file mode 100644
index 000000000000..79532bd321f0
--- /dev/null
+++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix4_after.xml
@@ -0,0 +1,3 @@
+
+
\ No newline at end of file