[111108] Adding UML22Ecore converter option to sort superclasses.
diff --git a/deprecated/examples/org.eclipse.uml2.examples.ui/src/org/eclipse/uml2/examples/ui/dialogs/UML22EcoreConverterOptionsDialog.java b/deprecated/examples/org.eclipse.uml2.examples.ui/src/org/eclipse/uml2/examples/ui/dialogs/UML22EcoreConverterOptionsDialog.java
index d6f2757..37ea061 100644
--- a/deprecated/examples/org.eclipse.uml2.examples.ui/src/org/eclipse/uml2/examples/ui/dialogs/UML22EcoreConverterOptionsDialog.java
+++ b/deprecated/examples/org.eclipse.uml2.examples.ui/src/org/eclipse/uml2/examples/ui/dialogs/UML22EcoreConverterOptionsDialog.java
@@ -8,7 +8,7 @@
  * Contributors:
  *   IBM - initial API and implementation
  *
- * $Id: UML22EcoreConverterOptionsDialog.java,v 1.4 2005/05/04 20:20:10 khussey Exp $
+ * $Id: UML22EcoreConverterOptionsDialog.java,v 1.5 2005/09/29 18:06:16 khussey Exp $
  */
 package org.eclipse.uml2.examples.ui.dialogs;
 
@@ -83,5 +83,9 @@
 			UML2Util.UML22EcoreConverter.OPTION__UNION_PROPERTIES,
 			new String[]{UML2Util.OPTION__IGNORE, UML2Util.OPTION__REPORT,
 				UML2Util.OPTION__PROCESS}, UML2Util.OPTION__PROCESS);
+		createOptionArea(parent,
+			UML2Util.UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER,
+			new String[]{UML2Util.OPTION__IGNORE, UML2Util.OPTION__REPORT,
+				UML2Util.OPTION__PROCESS}, UML2Util.OPTION__PROCESS);
 	}
 }
diff --git a/deprecated/plugins/org.eclipse.uml2.ecore.importer/plugin.properties b/deprecated/plugins/org.eclipse.uml2.ecore.importer/plugin.properties
index a6ccfba..1b31fa8 100644
--- a/deprecated/plugins/org.eclipse.uml2.ecore.importer/plugin.properties
+++ b/deprecated/plugins/org.eclipse.uml2.ecore.importer/plugin.properties
@@ -53,3 +53,5 @@
 # %%% END OF TRANSLATED PROPERTIES %%%
 # The above properties have been shipped for translation.
 # ====================================================================
+
+_UI_SuperClassOrder_label = Super Class Order
diff --git a/deprecated/plugins/org.eclipse.uml2.ecore.importer/src/org/eclipse/uml2/ecore/importer/ui/UML2DetailPage.java b/deprecated/plugins/org.eclipse.uml2.ecore.importer/src/org/eclipse/uml2/ecore/importer/ui/UML2DetailPage.java
index 22fd796..fb4c0af 100644
--- a/deprecated/plugins/org.eclipse.uml2.ecore.importer/src/org/eclipse/uml2/ecore/importer/ui/UML2DetailPage.java
+++ b/deprecated/plugins/org.eclipse.uml2.ecore.importer/src/org/eclipse/uml2/ecore/importer/ui/UML2DetailPage.java
@@ -8,7 +8,7 @@
  * Contributors:
  *   IBM - initial API and implementation
  *
- * $Id: UML2DetailPage.java,v 1.5 2005/06/09 15:47:30 khussey Exp $
+ * $Id: UML2DetailPage.java,v 1.6 2005/09/29 18:06:18 khussey Exp $
  */
 package org.eclipse.uml2.ecore.importer.ui;
 
@@ -111,23 +111,26 @@
 				.getString("_UI_Options_label")); //$NON-NLS-1$
 		}
 
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_EcoreTaggedValues_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_EcoreTaggedValues_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__ECORE_TAGGED_VALUES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, processChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_DerivedFeatures_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE.getString("_UI_DerivedFeatures_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__DERIVED_FEATURES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, processChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_DuplicateFeatureInheritance_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_DuplicateFeatureInheritance_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__DUPLICATE_FEATURE_INHERITANCE,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				discardChoiceLabel, processChoiceLabel}, discardChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_DuplicateFeatures_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_DuplicateFeatures_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__DUPLICATE_FEATURES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				discardChoiceLabel, processChoiceLabel}, discardChoiceLabel);
@@ -138,31 +141,40 @@
 			UML2Util.UML22EcoreConverter.OPTION__DUPLICATE_OPERATION_INHERITANCE,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				discardChoiceLabel, processChoiceLabel}, discardChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_DuplicateOperations_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_DuplicateOperations_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__DUPLICATE_OPERATIONS,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				discardChoiceLabel, processChoiceLabel}, discardChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_RedefiningOperations_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_RedefiningOperations_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__REDEFINING_OPERATIONS,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, reportChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_RedefiningProperties_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_RedefiningProperties_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__REDEFINING_PROPERTIES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, reportChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_SubsettingProperties_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE
+				.getString("_UI_SubsettingProperties_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__SUBSETTING_PROPERTIES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, reportChoiceLabel);
-		addOptionControl(group, UML2ImporterPlugin.INSTANCE
-			.getString("_UI_UnionProperties_label"), //$NON-NLS-1$
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE.getString("_UI_UnionProperties_label"), //$NON-NLS-1$
 			UML2Util.UML22EcoreConverter.OPTION__UNION_PROPERTIES,
 			new String[]{ignoreChoiceLabel, reportChoiceLabel,
 				processChoiceLabel}, reportChoiceLabel);
+		addOptionControl(group,
+			UML2ImporterPlugin.INSTANCE.getString("_UI_SuperClassOrder_label"), //$NON-NLS-1$
+			UML2Util.UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER,
+			new String[]{ignoreChoiceLabel, reportChoiceLabel,
+				processChoiceLabel}, processChoiceLabel);
 	}
 
 	protected UML2Importer getUML2Importer() {
diff --git a/deprecated/plugins/org.eclipse.uml2/plugin.properties b/deprecated/plugins/org.eclipse.uml2/plugin.properties
index 5def185..13d4506 100644
--- a/deprecated/plugins/org.eclipse.uml2/plugin.properties
+++ b/deprecated/plugins/org.eclipse.uml2/plugin.properties
@@ -7,7 +7,7 @@
 # Contributors: 
 #   IBM - initial API and implementation
 #
-# $Id: plugin.properties,v 1.21 2005/09/12 19:41:23 khussey Exp $
+# $Id: plugin.properties,v 1.22 2005/09/29 18:06:23 khussey Exp $
 
 # NLS_MESSAGEFORMAT_VAR
 
@@ -126,3 +126,6 @@
 _UI_PackageMerger_ReportCapability_diagnostic = Element ''{0}'' merged from capability ''{1}''.
 _UI_PackageMerger_ReportImplicitFeatureRedefinition_diagnostic = Feature ''{0}'' implicitly redefines feature ''{1}''.
 _UI_PackageMerger_ReportInvalidFeatureRedefinition_diagnostic = Feature ''{0}'' invalidly redefines feature ''{1}''.
+
+_UI_UML22EcoreConverter_ProcessSuperClassOrder_diagnostic = Re-ordered the super classes of class ''{0}'' for optimal code generation.
+_UI_UML22EcoreConverter_ReportSuperClassOrder_diagnostic = The super classes of class ''{0}'' should be re-ordered for optimal code generation.
diff --git a/deprecated/plugins/org.eclipse.uml2/src/org/eclipse/uml2/util/UML2Util.java b/deprecated/plugins/org.eclipse.uml2/src/org/eclipse/uml2/util/UML2Util.java
index a150415..2719705 100644
--- a/deprecated/plugins/org.eclipse.uml2/src/org/eclipse/uml2/util/UML2Util.java
+++ b/deprecated/plugins/org.eclipse.uml2/src/org/eclipse/uml2/util/UML2Util.java
@@ -8,17 +8,19 @@
  * Contributors:
  *   IBM - initial API and implementation
  *
- * $Id: UML2Util.java,v 1.40 2005/09/28 20:50:30 khussey Exp $
+ * $Id: UML2Util.java,v 1.41 2005/09/29 18:06:23 khussey Exp $
  */
 package org.eclipse.uml2.util;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -1396,6 +1398,8 @@
 
 		public static final String OPTION__DUPLICATE_FEATURE_INHERITANCE = "DUPLICATE_FEATURE_INHERITANCE"; //$NON-NLS-1$
 
+		public static final String OPTION__SUPER_CLASS_ORDER = "SUPER_CLASS_ORDER"; //$NON-NLS-1$
+
 		private static final int DIAGNOSTIC_CODE_OFFSET = 2000;
 
 		public static final int ECORE_TAGGED_VALUE = DIAGNOSTIC_CODE_OFFSET + 1;
@@ -1418,6 +1422,8 @@
 
 		public static final int DUPLICATE_FEATURE_INHERITANCE = DIAGNOSTIC_CODE_OFFSET + 10;
 
+		public static final int SUPER_CLASS_ORDER = DIAGNOSTIC_CODE_OFFSET + 11;
+
 		protected final Map elementToEModelElementMap = new HashMap();
 
 		protected Collection packages = null;
@@ -1704,13 +1710,8 @@
 							EClass generalEClass = (EClass) generalEClassifier;
 
 							if (!specificEClass.isSuperTypeOf(generalEClass)) {
-								List eSuperTypes = specificEClass
-									.getESuperTypes();
-
-								eSuperTypes.add(generalization
-									.hasKeyword("extend") //$NON-NLS-1$
-									? 0
-									: eSuperTypes.size(), generalEClass);
+								specificEClass.getESuperTypes().add(
+									generalEClass);
 							}
 						}
 					}
@@ -3742,6 +3743,122 @@
 			}
 		}
 
+		protected void processSuperClassOrder(Map options,
+				DiagnosticChain diagnostics, Map context) {
+
+			Comparator eClassComparator = new Comparator() {
+
+				public int compare(Object object, Object otherObject) {
+					EClass eClass = (EClass) object;
+					EClass otherEClass = (EClass) otherObject;
+
+					int eAllStructuralFeaturesSize = eClass
+						.getEAllStructuralFeatures().size();
+					int otherEAllStructuralFeaturesSize = otherEClass
+						.getEAllStructuralFeatures().size();
+
+					return eAllStructuralFeaturesSize < otherEAllStructuralFeaturesSize
+						? 1
+						: (otherEAllStructuralFeaturesSize < eAllStructuralFeaturesSize
+							? -1
+							: eClass.getName().compareTo(otherEClass.getName()));
+				}
+			};
+
+			for (Iterator entries = elementToEModelElementMap.entrySet()
+				.iterator(); entries.hasNext();) {
+				Map.Entry entry = (Map.Entry) entries.next();
+				Object key = entry.getKey();
+				Object value = entry.getValue();
+
+				if (key instanceof Classifier && value instanceof EClass) {
+					EClass eClass = (EClass) value;
+					EList eSuperTypes = eClass.getESuperTypes();
+
+					List extendSuperClasses = new ArrayList();
+					List unspecifiedSuperClasses = new ArrayList();
+					List mixinSuperClasses = new ArrayList();
+
+					for (Iterator generalizations = ((Classifier) key)
+						.getGeneralizations().iterator(); generalizations
+						.hasNext();) {
+						Generalization generalization = (Generalization) generalizations
+							.next();
+						Classifier general = generalization.getGeneral();
+
+						if (null != general) {
+							EModelElement eModelElement = (EModelElement) elementToEModelElementMap
+								.get(general);
+
+							if (eSuperTypes.contains(eModelElement)) {
+
+								if (generalization.hasKeyword("extend")) { //$NON-NLS-1$
+									extendSuperClasses.add(eModelElement);
+								} else if (generalization.hasKeyword("mixin")) { //$NON-NLS-1$
+									mixinSuperClasses.add(eModelElement);
+								} else {
+									unspecifiedSuperClasses.add(eModelElement);
+								}
+							}
+						}
+
+					}
+
+					Collections.sort(extendSuperClasses, eClassComparator);
+					Collections.sort(unspecifiedSuperClasses, eClassComparator);
+					Collections.sort(mixinSuperClasses, eClassComparator);
+
+					List superClasses = new UniqueEList(extendSuperClasses);
+					superClasses.addAll(unspecifiedSuperClasses);
+					superClasses.addAll(mixinSuperClasses);
+
+					if (!superClasses.equals(eSuperTypes)) {
+
+						if (OPTION__PROCESS.equals(options
+							.get(OPTION__SUPER_CLASS_ORDER))) {
+
+							if (null != diagnostics) {
+								diagnostics
+									.add(new BasicDiagnostic(
+										Diagnostic.INFO,
+										UML2Validator.DIAGNOSTIC_SOURCE,
+										SUPER_CLASS_ORDER,
+										UML2Plugin.INSTANCE
+											.getString(
+												"_UI_UML22EcoreConverter_ProcessSuperClassOrder_diagnostic", //$NON-NLS-1$
+												getMessageSubstitutions(
+													context, eClass)),
+										new Object[]{eClass}));
+							}
+
+							for (ListIterator li = superClasses.listIterator(); li
+								.hasNext();) {
+								Object superClass = li.next();
+								eSuperTypes
+									.move(li.previousIndex(), superClass);
+							}
+
+						}
+						if (OPTION__REPORT.equals(options
+							.get(OPTION__SUPER_CLASS_ORDER))
+							&& null != diagnostics) {
+
+							diagnostics
+								.add(new BasicDiagnostic(
+									Diagnostic.WARNING,
+									UML2Validator.DIAGNOSTIC_SOURCE,
+									SUPER_CLASS_ORDER,
+									UML2Plugin.INSTANCE
+										.getString(
+											"_UI_UML22EcoreConverter_ReportSuperClassOrder_diagnostic", //$NON-NLS-1$
+											getMessageSubstitutions(context,
+												eClass)), new Object[]{eClass}));
+						}
+					}
+				}
+			}
+		}
+
 		protected void processOptions(Map options, DiagnosticChain diagnostics,
 				Map context) {
 
@@ -3800,6 +3917,10 @@
 				processDuplicateFeatureInheritance(options, diagnostics,
 					context);
 			}
+
+			if (!OPTION__IGNORE.equals(options.get(OPTION__SUPER_CLASS_ORDER))) {
+				processSuperClassOrder(options, diagnostics, context);
+			}
 		}
 
 		/*
@@ -6132,6 +6253,11 @@
 				OPTION__IGNORE);
 		}
 
+		if (!options.containsKey(UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER)) {
+			options.put(UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER,
+				OPTION__IGNORE);
+		}
+
 		return convertToEcore(package_, options, null, null);
 	}
 
@@ -6205,6 +6331,11 @@
 				OPTION__REPORT);
 		}
 
+		if (!options.containsKey(UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER)) {
+			options.put(UML22EcoreConverter.OPTION__SUPER_CLASS_ORDER,
+				OPTION__REPORT);
+		}
+
 		return new UML22EcoreConverter().convert(Collections
 			.singleton(package_), options, diagnostics, context);
 	}