IDEA-42074 Code completion for <beans>'s attributes should base on the attribute appcode/142.1365
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 21 Apr 2015 13:23:36 +0000 (16:23 +0300)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 21 Apr 2015 13:24:56 +0000 (16:24 +0300)
xml/tests/src/com/intellij/codeInsight/completion/XmlCompletionTest.java
xml/xml-psi-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/URLReference.java
xml/xml-psi-impl/src/com/intellij/xml/DefaultXmlNamespaceHelper.java [moved from xml/impl/src/com/intellij/xml/DefaultXmlNamespaceHelper.java with 99% similarity]
xml/xml-psi-impl/src/com/intellij/xml/XmlNamespaceHelper.java [moved from xml/impl/src/com/intellij/xml/XmlNamespaceHelper.java with 100% similarity]

index 68df40c149421141e11788d3ed3b77e2dd3922c6..fdc3ab745b866a5570543a835586fc2ff3be9306 100644 (file)
@@ -719,5 +719,15 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase {
                                      "http://www.w3.org/2001/XMLSchema ", "http://www.w3.org/2001/XMLSchema-instance ");
     myFixture.testCompletionVariants("SchemaLocation2.xml", "http://www.w3.org/2001/XMLSchema.xsd");
   }
+
+  public void testNamespaceCompletion() throws Exception {
+    myFixture.configureByText("foo.xml", "<schema xmlns=\"<caret>\"/>");
+    myFixture.completeBasic();
+    assertSameElements(myFixture.getLookupElementStrings(), "http://www.w3.org/2001/XMLSchema");
+
+    myFixture.configureByText("unknown.xml", "<unknown_tag_name xmlns=\"<caret>\"/>");
+    myFixture.completeBasic();
+    assertTrue(myFixture.getLookupElementStrings().size() > 3); // all standard schemas actually
+  }
 }
 
index 3ae8bc8d24dd6e9f1f70db10b89d790308b6094d..54424e6847bf1cc70cc84737daf42c011122a623 100644 (file)
@@ -33,6 +33,7 @@ import com.intellij.util.ArrayUtil;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.Processor;
 import com.intellij.xml.XmlNSDescriptor;
+import com.intellij.xml.XmlNamespaceHelper;
 import com.intellij.xml.XmlSchemaProvider;
 import com.intellij.xml.util.XmlUtil;
 import org.jetbrains.annotations.NonNls;
@@ -206,6 +207,14 @@ public class URLReference implements PsiReference, EmptyResolveMessageProvider {
   @NotNull
   public Object[] getVariants() {
     final XmlFile file = (XmlFile)myElement.getContainingFile();
+    PsiElement parent = myElement.getParent();
+    if (parent instanceof XmlAttribute && "xmlns".equals(((XmlAttribute)parent).getName())) {
+      XmlNamespaceHelper helper = XmlNamespaceHelper.getHelper(file);
+      Set<String> strings = helper.guessUnboundNamespaces(parent.getParent(), file);
+      if (!strings.isEmpty()) {
+        return strings.toArray();
+      }
+    }
     Set<String> list = new HashSet<String>();
     for (XmlSchemaProvider provider : Extensions.getExtensions(XmlSchemaProvider.EP_NAME)) {
       if (provider.isAvailable(file)) {
@@ -215,7 +224,7 @@ public class URLReference implements PsiReference, EmptyResolveMessageProvider {
     if (!list.isEmpty()) {
       return ArrayUtil.toObjectArray(list);
     }
-    String[] resourceUrls = ExternalResourceManager.getInstance().getResourceUrls(null, true);
+    Object[] resourceUrls = ExternalResourceManagerEx.getInstanceEx().getUrlsByNamespace(myElement.getProject()).keySet().toArray();
     final XmlDocument document = file.getDocument();
     assert document != null;
     XmlTag rootTag = document.getRootTag();
similarity index 99%
rename from xml/impl/src/com/intellij/xml/DefaultXmlNamespaceHelper.java
rename to xml/xml-psi-impl/src/com/intellij/xml/DefaultXmlNamespaceHelper.java
index e351c7bfa309cc25a17e98d0ecc187786c7819df..7eb86750d2d66dbc9c52f9d42f7f016c8095ce28 100644 (file)
@@ -231,6 +231,4 @@ public class DefaultXmlNamespaceHelper extends XmlNamespaceHelper {
     }
     return set;
   }
-
-
 }