[194599] Handling redefined methods for OCL bodies
diff --git a/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/Class.java b/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/Class.java
index e87b94b..12a6fdf 100644
--- a/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/Class.java
+++ b/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/Class.java
@@ -1833,7 +1833,7 @@
   protected final String TEXT_1815 = " == null)" + NL + "\t\t{" + NL + "\t\t\t";
   protected final String TEXT_1816 = ".Helper helper = EOCL_ENV.createOCLHelper();" + NL + "\t\t\thelper.setOperationContext(";
   protected final String TEXT_1817 = ", ";
-  protected final String TEXT_1818 = ".getEOperations().get(";
+  protected final String TEXT_1818 = ".getEAllOperations().get(";
   protected final String TEXT_1819 = "));" + NL + "\t\t\ttry" + NL + "\t\t\t{" + NL + "\t\t\t\t";
   protected final String TEXT_1820 = " = helper.createQuery(";
   protected final String TEXT_1821 = "__EOCL_EXP);" + NL + "\t\t\t}" + NL + "\t\t\tcatch (";
@@ -7167,6 +7167,16 @@
     stringBuffer.append(TEXT_1813);
     }
     } else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";
+		GenOperation redefinedGenOperation = genOperation;
+		while (UML2GenModelUtil.isDuplicate(redefinedGenOperation)) {
+			java.util.List<GenOperation> redefinedGenOperations = UML2GenModelUtil.getRedefinedGenOperations(redefinedGenOperation);
+			if (redefinedGenOperations.size() > 0) {
+				redefinedGenOperation = redefinedGenOperations.get(0);
+			} else {
+			break;
+			}
+		}
+		int index = genOperation.getGenClass().getAllGenOperations().indexOf(redefinedGenOperation);
     stringBuffer.append(TEXT_1814);
     stringBuffer.append(oclQry);
     stringBuffer.append(TEXT_1815);
@@ -7176,7 +7186,7 @@
     stringBuffer.append(TEXT_1817);
     stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
     stringBuffer.append(TEXT_1818);
-    stringBuffer.append(genOperation.getGenClass().getGenOperations().indexOf(genOperation));
+    stringBuffer.append(index);
     stringBuffer.append(TEXT_1819);
     stringBuffer.append(oclQry);
     stringBuffer.append(TEXT_1820);
diff --git a/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/OperationsClass.java b/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/OperationsClass.java
index 7a1a71a..11caee8 100644
--- a/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/OperationsClass.java
+++ b/plugins/org.eclipse.uml2.codegen.ecore/src/org/eclipse/uml2/codegen/ecore/templates/model/OperationsClass.java
@@ -123,7 +123,7 @@
   protected final String TEXT_106 = " == null)" + NL + "\t\t{" + NL + "\t\t\t";
   protected final String TEXT_107 = ".Helper helper = EOCL_ENV.createOCLHelper();" + NL + "\t\t\thelper.setOperationContext(";
   protected final String TEXT_108 = ", ";
-  protected final String TEXT_109 = ".getEOperations().get(";
+  protected final String TEXT_109 = ".getEAllOperations().get(";
   protected final String TEXT_110 = "));" + NL + "\t\t\ttry" + NL + "\t\t\t{" + NL + "\t\t\t\t";
   protected final String TEXT_111 = " = helper.createQuery(";
   protected final String TEXT_112 = "__EOCL_EXP);" + NL + "\t\t\t}" + NL + "\t\t\tcatch (";
@@ -423,6 +423,16 @@
     stringBuffer.append(genClass.safeName(genClass.getUncapName()));
     stringBuffer.append(TEXT_104);
     } else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";
+		GenOperation redefinedGenOperation = genOperation;
+		while (UML2GenModelUtil.isDuplicate(redefinedGenOperation)) {
+			java.util.List<GenOperation> redefinedGenOperations = UML2GenModelUtil.getRedefinedGenOperations(redefinedGenOperation);
+			if (redefinedGenOperations.size() > 0) {
+				redefinedGenOperation = redefinedGenOperations.get(0);
+			} else {
+				break;
+			}
+		}
+		int index = genOperation.getGenClass().getAllGenOperations().indexOf(redefinedGenOperation);
     stringBuffer.append(TEXT_105);
     stringBuffer.append(oclQry);
     stringBuffer.append(TEXT_106);
@@ -432,7 +442,7 @@
     stringBuffer.append(TEXT_108);
     stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
     stringBuffer.append(TEXT_109);
-    stringBuffer.append(genOperation.getGenClass().getGenOperations().indexOf(genOperation));
+    stringBuffer.append(index);
     stringBuffer.append(TEXT_110);
     stringBuffer.append(oclQry);
     stringBuffer.append(TEXT_111);
diff --git a/plugins/org.eclipse.uml2.codegen.ecore/templates/model/Class/genOperation.override.javajetinc b/plugins/org.eclipse.uml2.codegen.ecore/templates/model/Class/genOperation.override.javajetinc
index a0eb394..3b05814 100644
--- a/plugins/org.eclipse.uml2.codegen.ecore/templates/model/Class/genOperation.override.javajetinc
+++ b/plugins/org.eclipse.uml2.codegen.ecore/templates/model/Class/genOperation.override.javajetinc
@@ -144,11 +144,21 @@
         <%}%>
 		return <%=UML2GenModelUtil.getImportedOperationsClassName(opClass)%>.<%=genOperation.getName()%>(this<%if (genOperation.getGenParameters().size() > 0) {%>, <%=genOperation.getParameterNames(", ")%><%}%>);
       <%}%>
-    <%} else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";%>
+    <%} else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";
+		GenOperation redefinedGenOperation = genOperation;
+		while (UML2GenModelUtil.isDuplicate(redefinedGenOperation)) {
+			java.util.List<GenOperation> redefinedGenOperations = UML2GenModelUtil.getRedefinedGenOperations(redefinedGenOperation);
+			if (redefinedGenOperations.size() > 0) {
+				redefinedGenOperation = redefinedGenOperations.get(0);
+			} else {
+			break;
+			}
+		}
+		int index = genOperation.getGenClass().getAllGenOperations().indexOf(redefinedGenOperation);%>
 		if (<%=oclQry%> == null)
 		{
 			<%=genModel.getImportedName("org.eclipse.ocl.ecore.OCL")%>.Helper helper = EOCL_ENV.createOCLHelper();
-			helper.setOperationContext(<%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>, <%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>.getEOperations().get(<%=genOperation.getGenClass().getGenOperations().indexOf(genOperation)%>));
+			helper.setOperationContext(<%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>, <%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>.getEAllOperations().get(<%=index%>));
 			try
 			{
 				<%=oclQry%> = helper.createQuery(<%=UML2GenModelUtil.getUpperName(genOperation.getName())%><%=genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))%>__EOCL_EXP);
diff --git a/plugins/org.eclipse.uml2.codegen.ecore/templates/model/OperationsClass.javajet b/plugins/org.eclipse.uml2.codegen.ecore/templates/model/OperationsClass.javajet
index 61a2219..6c9f1f1 100644
--- a/plugins/org.eclipse.uml2.codegen.ecore/templates/model/OperationsClass.javajet
+++ b/plugins/org.eclipse.uml2.codegen.ecore/templates/model/OperationsClass.javajet
@@ -1,4 +1,4 @@
-<%@ jet package="org.eclipse.uml2.codegen.ecore.templates.model" imports="org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.uml2.codegen.ecore.genmodel.util.UML2GenModelUtil" class="OperationsClass" version="$Id: OperationsClass.javajet,v 1.8 2007/05/10 14:24:21 khussey Exp $" %>
+<%@ jet package="org.eclipse.uml2.codegen.ecore.templates.model" imports="org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.uml2.codegen.ecore.genmodel.util.UML2GenModelUtil" class="OperationsClass" version="$Id: OperationsClass.javajet,v 1.8.2.1 2007/08/20 15:48:34 jbruck Exp $" %>
 <%
 /**
  * <copyright>
@@ -176,11 +176,21 @@
 			return false;
 		}
 		return true;
-    <%} else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";%>
+    <%} else if (UML2GenModelUtil.hasOCLBody(genOperation)) { String oclQry = UML2GenModelUtil.getUpperName(genOperation.getName()) + (genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))) + "__EOCL_QRY";
+		GenOperation redefinedGenOperation = genOperation;
+		while (UML2GenModelUtil.isDuplicate(redefinedGenOperation)) {
+			java.util.List<GenOperation> redefinedGenOperations = UML2GenModelUtil.getRedefinedGenOperations(redefinedGenOperation);
+			if (redefinedGenOperations.size() > 0) {
+				redefinedGenOperation = redefinedGenOperations.get(0);
+			} else {
+				break;
+			}
+		}
+		int index = genOperation.getGenClass().getAllGenOperations().indexOf(redefinedGenOperation);%>
 		if (<%=oclQry%> == null)
 		{
 			<%=genModel.getImportedName("org.eclipse.ocl.ecore.OCL")%>.Helper helper = EOCL_ENV.createOCLHelper();
-			helper.setOperationContext(<%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>, <%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>.getEOperations().get(<%=genOperation.getGenClass().getGenOperations().indexOf(genOperation)%>));
+			helper.setOperationContext(<%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>, <%=genOperation.getGenClass().getQualifiedClassifierAccessor()%>.getEAllOperations().get(<%=index%>));
 			try
 			{
 				<%=oclQry%> = helper.createQuery(<%=UML2GenModelUtil.getUpperName(genOperation.getName())%><%=genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false))%>__EOCL_EXP);