enabling "add xsi location" intention for prefixed namespaces

This commit is contained in:
Dmitry Avdeev
2012-07-16 13:10:08 +04:00
parent 44443a8a17
commit 7d490d537c
4 changed files with 16 additions and 5 deletions
@@ -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;
}
}
@@ -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 {
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:web-app xmlns:x="http://java.sun.co<caret>m/xml/ns/j2ee" version="2.4"/>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:web-app xmlns:x="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"/>