Bug 530829 - Restrictive generic signatures in ECPControlHelper

Update the ECPHelper parameter types to allow more specific
kinds of set.

Change-Id: Id78f26049b2b1dbb48fa5af54129deb775466cdd
diff --git a/bundles/org.eclipse.emf.ecp.edit/src/org/eclipse/emf/ecp/internal/edit/ECPControlHelper.java b/bundles/org.eclipse.emf.ecp.edit/src/org/eclipse/emf/ecp/internal/edit/ECPControlHelper.java
index c4c43ba..4e6c1cf 100644
--- a/bundles/org.eclipse.emf.ecp.edit/src/org/eclipse/emf/ecp/internal/edit/ECPControlHelper.java
+++ b/bundles/org.eclipse.emf.ecp.edit/src/org/eclipse/emf/ecp/internal/edit/ECPControlHelper.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2011-2019 EclipseSource Muenchen GmbH and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
  *
  * Contributors:
  * Jonas - initial API and implementation
+ * Christian W. Damus - bug 530829
  ******************************************************************************/
 package org.eclipse.emf.ecp.internal.edit;
 
@@ -52,8 +53,8 @@
 	 * @param eReference the reference to be modified
 	 * @param editingDomain the editing domain to execute commands on
 	 */
-	public static void addModelElementsInReference(EObject eObject, Set<EObject> eObjects, EReference eReference,
-		EditingDomain editingDomain) {
+	public static void addModelElementsInReference(EObject eObject, Set<? extends EObject> eObjects,
+		EReference eReference, EditingDomain editingDomain) {
 
 		if (eObjects.isEmpty()) {
 			return;
@@ -76,8 +77,9 @@
 	 * @param eReference the reference
 	 * @param elements the elements to remove existing elements from
 	 */
-	@SuppressWarnings("unchecked")
-	public static void removeExistingReferences(EObject eObject, EReference eReference, Set<EObject> elements) {
+	public static void removeExistingReferences(EObject eObject, EReference eReference,
+		Set<? extends EObject> elements) {
+
 		final Set<EObject> existing = new HashSet<EObject>();
 		final Object eGet = eObject.eGet(eReference);
 		if (eGet == null) {
@@ -85,9 +87,10 @@
 		}
 		if (eReference.getUpperBound() == 1) {
 			existing.add((EObject) eGet);
-		}
-		else {
-			existing.addAll((Collection<? extends EObject>) eGet);
+		} else {
+			@SuppressWarnings("unchecked")
+			final Collection<? extends EObject> collection = (Collection<? extends EObject>) eGet;
+			existing.addAll(collection);
 		}
 		elements.removeAll(existing);
 
diff --git a/bundles/org.eclipse.emf.ecp.ui.view.swt/src/org/eclipse/emf/ecp/ui/view/swt/reference/ReferenceStrategy.java b/bundles/org.eclipse.emf.ecp.ui.view.swt/src/org/eclipse/emf/ecp/ui/view/swt/reference/ReferenceStrategy.java
index 5dc7793..4230cd4 100644
--- a/bundles/org.eclipse.emf.ecp.ui.view.swt/src/org/eclipse/emf/ecp/ui/view/swt/reference/ReferenceStrategy.java
+++ b/bundles/org.eclipse.emf.ecp.ui.view.swt/src/org/eclipse/emf/ecp/ui/view/swt/reference/ReferenceStrategy.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2018 Christian W. Damus and others.
+ * Copyright (c) 2018, 2019 Christian W. Damus and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -38,11 +38,7 @@
 		public boolean addElementsToReference(EObject owner, EReference reference, Set<? extends EObject> objects) {
 			final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(owner);
 
-			// The ECPControlHelper generic signature is wrong. It should be an upper bound,
-			// but because this utility never actually adds to the set, this cast is safe
-			@SuppressWarnings("unchecked")
-			final Set<EObject> objectsToAdd = (Set<EObject>) objects;
-			ECPControlHelper.addModelElementsInReference(owner, objectsToAdd, reference, domain);
+			ECPControlHelper.addModelElementsInReference(owner, objects, reference, domain);
 
 			return true;
 		}