[buzilla 381826] Displaying one proposal per available Literal for a EEnum value
- also update Completion related tests
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/completion/ModelingUnitCompletionProcessor.java b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/completion/ModelingUnitCompletionProcessor.java
index 41ef47b..f0e7ae7 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/completion/ModelingUnitCompletionProcessor.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.ui/src/org/eclipse/mylyn/docs/intent/client/ui/editor/completion/ModelingUnitCompletionProcessor.java
@@ -21,6 +21,7 @@
 import org.eclipse.emf.ecore.EClass;
 import org.eclipse.emf.ecore.EClassifier;
 import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
 import org.eclipse.emf.ecore.EPackage;
 import org.eclipse.emf.ecore.EStructuralFeature;
 import org.eclipse.emf.ecore.EcorePackage;
@@ -42,6 +43,8 @@
  */
 public class ModelingUnitCompletionProcessor extends AbstractIntentCompletionProcessor {
 
+	private static final String RIGHT_PAR = ")";
+
 	private static final String DOT = ".";
 
 	private static final String NEW_LINE = "\n\t";
@@ -403,18 +406,23 @@
 				defaultAttributeValue = "Default: " + featureToConsider.getDefaultValue().toString();
 			}
 			if (featureToConsider.getEType() instanceof EEnum) {
-				defaultAttributeValue = "One of " + ((EEnum)featureToConsider.getEType()).getELiterals()
-						+ " - " + defaultAttributeValue;
+				for (EEnumLiteral literal : ((EEnum)featureToConsider.getEType()).getELiterals()) {
+					proposals.add(createTemplateProposal("'" + literal.getName() + "' value (of type "
+							+ featureToConsider.getEType().getName() + RIGHT_PAR, defaultAttributeValue
+							+ " - Set a simple value of type " + featureToConsider.getEType().getName(), '"'
+							+ literal.getName() + "\";", "icon/outline/modelingunit_value.gif"));
+				}
+			} else {
+				proposals.add(createTemplateProposal("value (of type "
+						+ featureToConsider.getEType().getName() + RIGHT_PAR, defaultAttributeValue
+						+ " - Set a simple value of type " + featureToConsider.getEType().getName(), '"'
+						+ defaultAttributeValue + "\";", "icon/outline/modelingunit_value.gif"));
 			}
-			proposals.add(createTemplateProposal("value (of type " + featureToConsider.getEType().getName()
-					+ ")", defaultAttributeValue + " - Set a simple value of type "
-					+ featureToConsider.getEType().getName(), '"' + defaultAttributeValue + "\";",
-					"icon/outline/modelingunit_value.gif"));
 		} else {
 			// Propose to create a new Element of the feature type
 			if (!isResourceContribution) {
 				proposals.add(createTemplateProposal("new Element (of type "
-						+ featureToConsider.getEType().getName() + ")", "Set this new Element as value for "
+						+ featureToConsider.getEType().getName() + RIGHT_PAR, "Set this new Element as value for "
 						+ featureToConsider.getName(), "new "
 						+ getQualifiedName(featureToConsider.getEType().getEPackage()) + DOT
 						+ featureToConsider.getEType().getName() + "{\n\t${}\n};",
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/editor/CompletionTest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/editor/CompletionTest.java
index 592978d..3fc3b33 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/editor/CompletionTest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/demo/editor/CompletionTest.java
@@ -44,7 +44,7 @@
 

 	private static final String TEMPLATE_DESC_CONTENT = "Resource Content - Add content to the Resource";

 

-	private static final String TEMPLATE_DESC_BOOL_VALUE = "value (of type EBoolean) - Set a simple value of type EBoolean";

+	private static final String TEMPLATE_DESC_BOOL_VALUE = "value (of type EBoolean) - Default: false - Set a simple value of type EBoolean";

 

 	private IntentEditor editor;

 

@@ -107,15 +107,12 @@
 		 */

 		// beginning of the modeling unit

 		proposals = getCompletionProposals(2138);

-		assertEquals(2, proposals.length);

-		assertEquals(TEMPLATE_DESC_RESOURCE, proposals[0].getDisplayString());

-		assertEquals(TEMPLATE_DESC_INST, proposals[1].getDisplayString());

+		// We should propose to create a new resource, a new entity, or contribute to an existing entity

+		assertIsExpectedProposalsForEmptyModelingUnit(proposals);

 

 		// beginning of a named modeling unit

 		proposals = getCompletionProposals(3232);

-		assertEquals(2, proposals.length);

-		assertEquals(TEMPLATE_DESC_RESOURCE, proposals[0].getDisplayString());

-		assertEquals(TEMPLATE_DESC_INST, proposals[1].getDisplayString());

+		assertIsExpectedProposalsForEmptyModelingUnit(proposals);

 

 		// resource declaration patterns

 		proposals = getCompletionProposals(3263);

@@ -143,30 +140,41 @@
 

 		// Object value

 		proposals = getCompletionProposals(3985);

-		assertEquals(2, proposals.length);

+		assertEquals(3, proposals.length);

+		// We should propose to create a new Element

 		assertEquals("new Element (of type EClassifier) - Set this new Element as value for eType",

 				proposals[0].getDisplayString());

-		assertEquals("MatchElement - http://www.eclipse.org/emf/compare/match/1.1",

+		// Use existing elements (of matching type) defined in the document

+		assertEquals("Reference to MatchElement - Set the MatchElement element as value for eType",

 				proposals[1].getDisplayString());

+		// And available Classifiers from the package registry

+		assertEquals("MatchElement - http://www.eclipse.org/emf/compare/match/1.1",

+				proposals[2].getDisplayString());

 

 		// instanciation proposals

 		proposals = getCompletionProposals(3865);

 		assertEquals(2, proposals.length);

 		assertEquals("EClass - http://www.eclipse.org/emf/2002/Ecore", proposals[0].getDisplayString());

 		assertEquals("EClassifier - http://www.eclipse.org/emf/2002/Ecore", proposals[1].getDisplayString());

-	}

 

-	// TODO integrate in main test when fixed

-	public void testUnresolvedProblems() throws BadLocationException {

-		ICompletionProposal[] proposals;

 		// features proposals further in contribution

 		proposals = getCompletionProposals(4128);

 		assertEquals(1, proposals.length);

 		assertEquals(

-				"eStructuralFeatures : EStructuralFeatures [0,*] - Set the value EClass.eStructuralFeatures",

+				"eStructuralFeatures : EStructuralFeature [0,*] - Set the value EClass.eStructuralFeatures",

 				proposals[0].getDisplayString());

 	}

 

+	private void assertIsExpectedProposalsForEmptyModelingUnit(ICompletionProposal[] proposals) {

+		assertEquals(15, proposals.length);

+		assertEquals(TEMPLATE_DESC_RESOURCE, proposals[0].getDisplayString());

+		assertEquals(TEMPLATE_DESC_INST, proposals[1].getDisplayString());

+		for (int i = 2; i < proposals.length; i++) {

+			assertTrue("We should propose to contribute to an existing element", proposals[i]

+					.getDisplayString().contains("(contribution"));

+		}

+	}

+

 	// CHECKSTYLE:ON

 

 	/**