From a4a4db0dfd13092a95b8aaf12f5118d5b0af6022 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 25 Sep 2018 15:47:40 +0300 Subject: [PATCH] IDEA-151043 code completion sometimes does not suggest enumeration values when used with extension or union union with enum types supported --- .../completion/XmlCompletionTest.java | 6 +- .../testData/completion/enumerations.xml | 4 + .../testData/completion/enumerations.xsd | 113 ++++++++++++++++++ .../src/com/intellij/xml/util/XmlUtil.java | 9 ++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 xml/tests/testData/completion/enumerations.xml create mode 100644 xml/tests/testData/completion/enumerations.xsd diff --git a/xml/tests/src/com/intellij/codeInsight/completion/XmlCompletionTest.java b/xml/tests/src/com/intellij/codeInsight/completion/XmlCompletionTest.java index 7b1f86700f18..56faa6dbe374 100644 --- a/xml/tests/src/com/intellij/codeInsight/completion/XmlCompletionTest.java +++ b/xml/tests/src/com/intellij/codeInsight/completion/XmlCompletionTest.java @@ -798,10 +798,14 @@ public class XmlCompletionTest extends LightCodeInsightFixtureTestCase { assertSameElements(variants, "int", "integer", "invisibleType"); } + public void testEnumeratedTypeUnion() { + List variants = myFixture.getCompletionVariants("enumerations.xml", "enumerations.xsd"); + assertSameElements(variants, "A", "B"); + } + private HtmlCodeStyleSettings getHtmlSettings() { return CodeStyle.getSettings(myFixture.getProject()) .getCustomSettings(HtmlCodeStyleSettings.class); } - } diff --git a/xml/tests/testData/completion/enumerations.xml b/xml/tests/testData/completion/enumerations.xml new file mode 100644 index 000000000000..0c5fcb47afd3 --- /dev/null +++ b/xml/tests/testData/completion/enumerations.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/xml/tests/testData/completion/enumerations.xsd b/xml/tests/testData/completion/enumerations.xsd new file mode 100644 index 000000000000..97724cb28425 --- /dev/null +++ b/xml/tests/testData/completion/enumerations.xsd @@ -0,0 +1,113 @@ + + + + + + Example enumerations: +
    +
  1. + enumeration: + a simple (disallows annotations), closed (is not extensible) enumeration +
  2. +
  3. + enumerationWithAttributes: + a complex (allows annotations), closed (is not extensible) enumeration +
  4. +
  5. + openEnumeration: + a simple (disallows annotations), open (is extensible) enumeration +
  6. +
  7. + openEnumerationWithAttributes: + a complex (allows annotations), open (is extensible) enumeration +
  8. +
+
+
+
+ + + + + + + + + + + + a simple (disallows annotations), closed (is not extensible) enumeration + + + + + + + + + + + a complex (allows annotations), closed (is not extensible) enumeration + + + + + + + + + + + + a reusable group of attributes for extending simple enumerations to make complex enumerations + + + + + + + + + a simple (disallows annotations), open (is extensible) enumeration + + + + + + + + a simple (disallows annotations), open (is extensible) enumeration + + + + + + + a simple (disallows annotations), closed (is not extensible) enumeration + + + + + + + + + + + + + a complex (allows annotations), open (is extensible) enumeration + + + + + + + + +
\ No newline at end of file diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java index 39a4d794a9c6..a8f5960a354e 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlUtil.java @@ -917,6 +917,15 @@ public class XmlUtil { else if (localName.equals("union")) { exhaustiveEnum = false; processEnumerationValues(tag, tagProcessor); + XmlAttribute attribute = tag.getAttribute("memberTypes"); + if (attribute != null && attribute.getValueElement() != null) { + for (PsiReference reference : attribute.getValueElement().getReferences()) { + PsiElement resolve = reference.resolve(); + if (resolve instanceof XmlTag) { + processEnumerationValues((XmlTag)resolve, tagProcessor); + } + } + } } else if (localName.equals("extension")) { XmlTag base = XmlSchemaTagsProcessor.resolveTagReference(tag.getAttribute("base"));