From c2ad3ae4f8dfdde22fe9057ac806682cf6285c22 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 26 May 2014 19:25:44 +0400 Subject: [PATCH] IDEA-119640 Problem with goto declaration of XML attribute defined in XSD --- .../daemon/XmlHighlightingTest.java | 38 +++++++++++++------ .../xml/AnyAttributeNavigation/library.xsd | 12 ++++++ .../xml/AnyAttributeNavigation/test.xml | 4 ++ .../xml/AnyAttributeNavigation/test.xsd | 15 ++++++++ .../impl/schema/XmlElementDescriptorImpl.java | 5 +++ 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 xml/tests/testData/xml/AnyAttributeNavigation/library.xsd create mode 100644 xml/tests/testData/xml/AnyAttributeNavigation/test.xml create mode 100644 xml/tests/testData/xml/AnyAttributeNavigation/test.xsd diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java index 774eb1a450eb..7b9cc1404d02 100644 --- a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java +++ b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java @@ -1437,7 +1437,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { ExternalResourceManagerExImpl.registerResourceTemporarily(url, location, getTestRootDisposable()); configureByFiles(null, getVirtualFile(getFullRelativeTestName()), getVirtualFile(BASE_PATH + location)); - doDoTest(true,false); + doDoTest(true, false); } @@ -1528,7 +1528,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { public void testEncoding() throws Exception { doTest(true); } public void testSchemaImportHighlightingAndResolve() throws Exception { - doTestWithLocations(new String[][] { {"http://www.springframework.org/schema/beans", "ComplexSchemaValidation11.xsd"} },"xsd"); + doTestWithLocations(new String[][]{{"http://www.springframework.org/schema/beans", "ComplexSchemaValidation11.xsd"}}, "xsd"); } public void testDocBookV5() throws Exception { @@ -1731,7 +1731,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { {"http://extended", testName + ".xsd"}, {"http://simple", testName + "_2.xsd"} }; - doTestWithLocations(urls,"xml"); + doTestWithLocations(urls, "xml"); } public void testComplexRedefine6() throws Exception { @@ -1839,7 +1839,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { Collection infos = doDoTest(true, false); findAndInvokeIntentionAction(infos, "Change Root Tag Name to xxx", myEditor, myFile); - checkResultByFile(BASE_PATH + testName+"_after.xml"); + checkResultByFile(BASE_PATH + testName + "_after.xml"); } public void testUnqualifiedAttributePsi() throws Exception { @@ -1847,7 +1847,8 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { final List attrs = new ArrayList(2); myFile.acceptChildren(new XmlRecursiveElementVisitor() { - @Override public void visitXmlAttribute(final XmlAttribute attribute) { + @Override + public void visitXmlAttribute(final XmlAttribute attribute) { if (!attribute.isNamespaceDeclaration()) attrs.add(attribute); } }); @@ -1876,7 +1877,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { final String testName = getTestName(false); doTest( - new VirtualFile[] { + new VirtualFile[]{ getVirtualFile(BASE_PATH + testName + ".xml"), getVirtualFile(BASE_PATH + testName + ".xsd") }, @@ -1921,7 +1922,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { } public void testProblemWithImportedNsReference() throws Exception { - doTestWithLocations(null,"xsd"); + doTestWithLocations(null, "xsd"); } public void testBadXmlns() throws Exception { @@ -1930,7 +1931,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { } public void testProblemWithMemberTypes() throws Exception { - doTestWithLocations(null,"xsd"); + doTestWithLocations(null, "xsd"); } public void testDtdHighlighting() throws Exception { @@ -1948,7 +1949,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { final String testName = getTestName(false); doTest( - new VirtualFile[] { + new VirtualFile[]{ getVirtualFile(BASE_PATH + testName + ".xml"), getVirtualFile(BASE_PATH + testName + ".xsd") }, @@ -1978,13 +1979,13 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { public void testMappedSchemaLocation() throws Exception { doTestWithLocations(new String[][]{ - { "schemas/Forms.xsd", "Forms.xsd"} + {"schemas/Forms.xsd", "Forms.xsd"} }, "xml"); } public void testMuleConfigValidation() throws Exception { doSchemaTestWithManyFilesFromSeparateDir( - new String[][] { + new String[][]{ {"http://www.springframework.org/schema/tool", "spring-tool-2.5.xsd"}, {"http://www.springframework.org/schema/beans/spring-beans-2.5.xsd", "spring-beans-2.5.xsd"}, {"http://www.mulesource.org/schema/mule/core/2.2/mule.xsd", "mule.xsd"}, @@ -2034,6 +2035,21 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { ); } + public void testAnyAttributeNavigation() throws Exception { + doTest( + new VirtualFile[] { + getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xml"), + getVirtualFile(BASE_PATH + "AnyAttributeNavigation/test.xsd"), + getVirtualFile(BASE_PATH + "AnyAttributeNavigation/library.xsd") + }, + true, + false + ); + PsiReference at = getFile().findReferenceAt(getEditor().getCaretModel().getOffset()); + PsiElement resolve = at.resolve(); + assertTrue(resolve instanceof XmlTag); + } + @Override protected void setUp() throws Exception { super.setUp(); diff --git a/xml/tests/testData/xml/AnyAttributeNavigation/library.xsd b/xml/tests/testData/xml/AnyAttributeNavigation/library.xsd new file mode 100644 index 000000000000..22cf74a1e059 --- /dev/null +++ b/xml/tests/testData/xml/AnyAttributeNavigation/library.xsd @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/xml/tests/testData/xml/AnyAttributeNavigation/test.xml b/xml/tests/testData/xml/AnyAttributeNavigation/test.xml new file mode 100644 index 000000000000..a2f034714cfe --- /dev/null +++ b/xml/tests/testData/xml/AnyAttributeNavigation/test.xml @@ -0,0 +1,4 @@ + +z="baz"/> \ No newline at end of file diff --git a/xml/tests/testData/xml/AnyAttributeNavigation/test.xsd b/xml/tests/testData/xml/AnyAttributeNavigation/test.xsd new file mode 100644 index 000000000000..bb9e9824cf51 --- /dev/null +++ b/xml/tests/testData/xml/AnyAttributeNavigation/test.xsd @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java index b5f346142f78..083512a77b10 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/impl/schema/XmlElementDescriptorImpl.java @@ -377,6 +377,11 @@ public class XmlElementDescriptorImpl extends XsdEnumerationDescriptor final ComplexTypeDescriptor.CanContainAttributeType containAttributeType = descriptor.canContainAttribute(namespace, qName); if (containAttributeType != ComplexTypeDescriptor.CanContainAttributeType.CanNotContain) { + for (XmlAttributeDescriptor attributeDescriptor : descriptors) { + if (attributeDescriptor.getName().equals(attributeName)) { + return attributeDescriptor; + } + } return new AnyXmlAttributeDescriptor(attributeName, containAttributeType); } }