IDEA-42074 Code completion for <beans>'s attributes should base on the attribute

This commit is contained in:
Dmitry Avdeev
2015-04-21 16:24:56 +03:00
parent 8203447b4b
commit bde6311c8c
4 changed files with 20 additions and 3 deletions
@@ -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
}
}
@@ -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();
@@ -231,6 +231,4 @@ public class DefaultXmlNamespaceHelper extends XmlNamespaceHelper {
}
return set;
}
}