[180744] template expansion support
https://bugs.eclipse.org/bugs/show_bug.cgi?id=180744

Expose useful merge options in the Expand Template... action and fix capabilities trace for classifiers with multiple bindings.
diff --git a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/TemplateExpanderOptionsDialog.java b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/TemplateExpanderOptionsDialog.java
index c9576c9..2d4adab 100644
--- a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/TemplateExpanderOptionsDialog.java
+++ b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/dialogs/TemplateExpanderOptionsDialog.java
@@ -44,6 +44,21 @@
 			UMLUtil.TemplateExpander.OPTION__MISSING_PARAMETER_SUBSTITUTIONS,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel},
 			reportChoiceLabel);
+
+		createOptionArea(
+			parent,
+			UMLEditorPlugin.INSTANCE
+				.getString("_UI_RedundantGeneralizations_label"), //$NON-NLS-1$
+			UMLUtil.PackageMerger.OPTION__REDUNDANT_GENERALIZATIONS,
+			new String[]{ignoreChoiceLabel, reportChoiceLabel,
+				discardChoiceLabel}, discardChoiceLabel);
+
+		createOptionArea(
+			parent,
+			UMLEditorPlugin.INSTANCE.getString("_UI_Capabilities_label"), //$NON-NLS-1$
+			UMLUtil.PackageMerger.OPTION__CAPABILITIES, new String[]{
+				ignoreChoiceLabel, reportChoiceLabel, processChoiceLabel},
+			processChoiceLabel);
 	}
 
 }
diff --git a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
index 4138b6b..02dd950 100644
--- a/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
+++ b/plugins/org.eclipse.uml2.uml/src/org/eclipse/uml2/uml/util/UMLUtil.java
@@ -2884,6 +2884,9 @@
 							Classifier intermediate = (Classifier) EcoreUtil
 								.create(object.eClass());
 
+							// add the intermediate result to the model
+							addAnonymousGeneral(intermediate, object);
+
 							// have to use a distinct template-expander for each
 							// because multiple bindings to the same template
 							// are allowed and an EcoreUtil.Copier can only copy
@@ -2892,9 +2895,6 @@
 								new TemplateExpander()
 									.expand(binding, intermediate, options,
 										diagnostics, context));
-
-							// add the intermediate result to the model
-							addAnonymousGeneral(intermediate, object);
 						}
 
 						return resultingToMergedEObjectMap;
diff --git a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug180744Test.java b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug180744Test.java
index d20878c..4b57be2 100644
--- a/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug180744Test.java
+++ b/tests/org.eclipse.uml2.uml.tests/src/org/eclipse/uml2/uml/bug/tests/Bug180744Test.java
@@ -31,6 +31,7 @@
 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
 import org.eclipse.uml2.common.util.UML2Util;
 import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.AttributeOwner;
 import org.eclipse.uml2.uml.Class;
 import org.eclipse.uml2.uml.Classifier;
 import org.eclipse.uml2.uml.Element;
@@ -280,6 +281,20 @@
 		assertCapabilityTrace(listOfBars, collection, remove);
 	}
 
+	public void testMergeCapabilityTracesClassifierMultipleBindings() {
+		Class bagListOfFooBars = expand(getClass("BagListOfFooBars"));
+		Class general1 = (Class) bagListOfFooBars.getNestedClassifiers().get(0);
+		Class general2 = (Class) bagListOfFooBars.getNestedClassifiers().get(1);
+		Class collection = getClass("Collection");
+
+		// the traces are in the expanded template that owns the nested
+		// anonymous superclasses
+		Operation remove = getOperation(general1, "remove");
+		assertCapabilityTrace(bagListOfFooBars, collection, remove);
+		Property kind = getProperty(general2, "kind");
+		assertCapabilityTrace(bagListOfFooBars, collection, kind);
+	}
+
 	//
 	// Test framework
 	//
@@ -330,6 +345,10 @@
 			URI.createURI(url.toExternalForm()), UMLPackage.Literals.PACKAGE);
 	}
 
+	Property getProperty(AttributeOwner owner, String name) {
+		return owner.getOwnedAttribute(name, null);
+	}
+
 	Operation getOperation(OperationOwner owner, String name) {
 		return owner.getOwnedOperation(name, null, null);
 	}