[345083] Adding template override point for processing of invariant operation diagnostics.
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 1d29d9f..228859f 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
@@ -106,54 +106,56 @@
protected final String TEXT_89 = "))";
protected final String TEXT_90 = NL + "\t\t// TODO: implement this method" + NL + "\t\t// -> specify the condition that violates the invariant" + NL + "\t\t// -> verify the details of the diagnostic, including severity and message" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tif (false)";
protected final String TEXT_91 = NL + "\t\t{" + NL + "\t\t\tif (";
- protected final String TEXT_92 = " != null)" + NL + "\t\t\t{" + NL + "\t\t\t\t";
- protected final String TEXT_93 = ".add" + NL + "\t\t\t\t\t(new ";
- protected final String TEXT_94 = NL + "\t\t\t\t\t\t(";
- protected final String TEXT_95 = ".ERROR," + NL + "\t\t\t\t\t\t ";
- protected final String TEXT_96 = ".DIAGNOSTIC_SOURCE," + NL + "\t\t\t\t\t\t ";
- protected final String TEXT_97 = ".";
- protected final String TEXT_98 = "," + NL + "\t\t\t\t\t\t org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString(\"_UI_GenericInvariant_diagnostic\", new Object[] { \"";
- protected final String TEXT_99 = "\", org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(";
- protected final String TEXT_100 = ", ";
- protected final String TEXT_101 = ") }),";
- protected final String TEXT_102 = NL + "\t\t\t\t\t\t new Object [] { ";
- protected final String TEXT_103 = " }));" + NL + "\t\t\t}" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\treturn true;";
- protected final String TEXT_104 = NL + "\t\tif (";
- protected final String TEXT_105 = " == null)" + NL + "\t\t{" + NL + "\t\t\t";
- protected final String TEXT_106 = ".Helper helper = EOCL_ENV.createOCLHelper();" + NL + "\t\t\thelper.setOperationContext(";
- protected final String TEXT_107 = ", ";
- protected final String TEXT_108 = ".getEAllOperations().get(";
- protected final String TEXT_109 = "));" + NL + "\t\t\ttry" + NL + "\t\t\t{" + NL + "\t\t\t\t";
- protected final String TEXT_110 = " = helper.createQuery(";
- protected final String TEXT_111 = "__EOCL_EXP);" + NL + "\t\t\t}" + NL + "\t\t\tcatch (";
- protected final String TEXT_112 = " pe)" + NL + "\t\t\t{" + NL + "\t\t\t\tthrow new UnsupportedOperationException(pe.getLocalizedMessage());" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t";
- protected final String TEXT_113 = ".Query query = EOCL_ENV.createQuery(";
- protected final String TEXT_114 = ");";
- protected final String TEXT_115 = NL + "\t\t";
- protected final String TEXT_116 = "<?, ?, ?, ?, ?>";
- protected final String TEXT_117 = " environment = query.getEvaluationEnvironment();";
- protected final String TEXT_118 = NL + "\t\tenvironment.add(\"";
- protected final String TEXT_119 = "\", ";
- protected final String TEXT_120 = ");";
- protected final String TEXT_121 = NL + "\t\t@SuppressWarnings(\"unchecked\")";
- protected final String TEXT_122 = NL + "\t\t";
- protected final String TEXT_123 = "<";
- protected final String TEXT_124 = "> result = (";
+ protected final String TEXT_92 = " != null)" + NL + "\t\t\t{";
+ protected final String TEXT_93 = NL + "\t\t\t\t";
+ protected final String TEXT_94 = ".add" + NL + "\t\t\t\t\t(new ";
+ protected final String TEXT_95 = NL + "\t\t\t\t\t\t(";
+ protected final String TEXT_96 = ".ERROR," + NL + "\t\t\t\t\t\t ";
+ protected final String TEXT_97 = ".DIAGNOSTIC_SOURCE," + NL + "\t\t\t\t\t\t ";
+ protected final String TEXT_98 = ".";
+ protected final String TEXT_99 = "," + NL + "\t\t\t\t\t\t org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString(\"_UI_GenericInvariant_diagnostic\", new Object[] { \"";
+ protected final String TEXT_100 = "\", org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(";
+ protected final String TEXT_101 = ", ";
+ protected final String TEXT_102 = ") }),";
+ protected final String TEXT_103 = NL + "\t\t\t\t\t\t new Object [] { ";
+ protected final String TEXT_104 = " }));";
+ protected final String TEXT_105 = NL + "\t\t\t}" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\treturn true;";
+ protected final String TEXT_106 = NL + "\t\tif (";
+ protected final String TEXT_107 = " == null)" + NL + "\t\t{" + NL + "\t\t\t";
+ protected final String TEXT_108 = ".Helper helper = EOCL_ENV.createOCLHelper();" + NL + "\t\t\thelper.setOperationContext(";
+ protected final String TEXT_109 = ", ";
+ protected final String TEXT_110 = ".getEAllOperations().get(";
+ protected final String TEXT_111 = "));" + NL + "\t\t\ttry" + NL + "\t\t\t{" + NL + "\t\t\t\t";
+ protected final String TEXT_112 = " = helper.createQuery(";
+ protected final String TEXT_113 = "__EOCL_EXP);" + NL + "\t\t\t}" + NL + "\t\t\tcatch (";
+ protected final String TEXT_114 = " pe)" + NL + "\t\t\t{" + NL + "\t\t\t\tthrow new UnsupportedOperationException(pe.getLocalizedMessage());" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t";
+ protected final String TEXT_115 = ".Query query = EOCL_ENV.createQuery(";
+ protected final String TEXT_116 = ");";
+ protected final String TEXT_117 = NL + "\t\t";
+ protected final String TEXT_118 = "<?, ?, ?, ?, ?>";
+ protected final String TEXT_119 = " environment = query.getEvaluationEnvironment();";
+ protected final String TEXT_120 = NL + "\t\tenvironment.add(\"";
+ protected final String TEXT_121 = "\", ";
+ protected final String TEXT_122 = ");";
+ protected final String TEXT_123 = NL + "\t\t@SuppressWarnings(\"unchecked\")";
+ protected final String TEXT_124 = NL + "\t\t";
protected final String TEXT_125 = "<";
- protected final String TEXT_126 = ">) query.evaluate(";
- protected final String TEXT_127 = ");" + NL + "\t\treturn new ";
- protected final String TEXT_128 = ".UnmodifiableEList<";
- protected final String TEXT_129 = ">(result.size(), result.toArray());";
- protected final String TEXT_130 = NL + "\t\treturn ((";
- protected final String TEXT_131 = ") query.evaluate(";
- protected final String TEXT_132 = ")).";
- protected final String TEXT_133 = "();";
- protected final String TEXT_134 = NL + "\t\treturn (";
- protected final String TEXT_135 = ") query.evaluate(";
- protected final String TEXT_136 = ");";
- protected final String TEXT_137 = NL + "\t\t// TODO: implement this method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tthrow new UnsupportedOperationException();";
- protected final String TEXT_138 = NL + "\t}" + NL;
- protected final String TEXT_139 = NL + "} // ";
+ protected final String TEXT_126 = "> result = (";
+ protected final String TEXT_127 = "<";
+ protected final String TEXT_128 = ">) query.evaluate(";
+ protected final String TEXT_129 = ");" + NL + "\t\treturn new ";
+ protected final String TEXT_130 = ".UnmodifiableEList<";
+ protected final String TEXT_131 = ">(result.size(), result.toArray());";
+ protected final String TEXT_132 = NL + "\t\treturn ((";
+ protected final String TEXT_133 = ") query.evaluate(";
+ protected final String TEXT_134 = ")).";
+ protected final String TEXT_135 = "();";
+ protected final String TEXT_136 = NL + "\t\treturn (";
+ protected final String TEXT_137 = ") query.evaluate(";
+ protected final String TEXT_138 = ");";
+ protected final String TEXT_139 = NL + "\t\t// TODO: implement this method" + NL + "\t\t// Ensure that you remove @generated or mark it @generated NOT" + NL + "\t\tthrow new UnsupportedOperationException();";
+ protected final String TEXT_140 = NL + "\t}" + NL;
+ protected final String TEXT_141 = NL + "} // ";
public String generate(Object argument)
{
@@ -172,7 +174,7 @@
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 206636, 224693
* Lutz Wrage - 242726
- * Kenn Hussey - 344908, 284810
+ * Kenn Hussey - 344908, 284810, 345083
*
* </copyright>
*/
@@ -399,29 +401,32 @@
stringBuffer.append(TEXT_91);
stringBuffer.append(diagnostics);
stringBuffer.append(TEXT_92);
- stringBuffer.append(diagnostics);
stringBuffer.append(TEXT_93);
- stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic"));
+ stringBuffer.append(diagnostics);
stringBuffer.append(TEXT_94);
- stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic"));
+ stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic"));
stringBuffer.append(TEXT_95);
- stringBuffer.append(opClass.getGenPackage().getImportedValidatorClassName());
+ stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic"));
stringBuffer.append(TEXT_96);
stringBuffer.append(opClass.getGenPackage().getImportedValidatorClassName());
stringBuffer.append(TEXT_97);
- stringBuffer.append(opClass.getOperationID(genOperation));
+ stringBuffer.append(opClass.getGenPackage().getImportedValidatorClassName());
stringBuffer.append(TEXT_98);
- stringBuffer.append(genOperation.getName());
+ stringBuffer.append(opClass.getOperationID(genOperation));
stringBuffer.append(TEXT_99);
- stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ stringBuffer.append(genOperation.getName());
stringBuffer.append(TEXT_100);
- stringBuffer.append(context);
+ stringBuffer.append(genClass.safeName(genClass.getUncapName()));
stringBuffer.append(TEXT_101);
+ stringBuffer.append(context);
+ stringBuffer.append(TEXT_102);
stringBuffer.append(genModel.getNonNLS());
stringBuffer.append(genModel.getNonNLS(2));
- stringBuffer.append(TEXT_102);
- stringBuffer.append(genClass.safeName(genClass.getUncapName()));
stringBuffer.append(TEXT_103);
+ stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ stringBuffer.append(TEXT_104);
+ //Operations/genOperation.diagnostics.override.javajetinc
+ stringBuffer.append(TEXT_105);
} 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)) {
@@ -433,86 +438,86 @@
}
}
int index = genOperation.getGenClass().getAllGenOperations().indexOf(redefinedGenOperation);
- stringBuffer.append(TEXT_104);
- stringBuffer.append(oclQry);
- stringBuffer.append(TEXT_105);
- stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ecore.OCL"));
stringBuffer.append(TEXT_106);
- stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
- stringBuffer.append(TEXT_107);
- stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
- stringBuffer.append(TEXT_108);
- stringBuffer.append(index);
- stringBuffer.append(TEXT_109);
stringBuffer.append(oclQry);
+ stringBuffer.append(TEXT_107);
+ stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ecore.OCL"));
+ stringBuffer.append(TEXT_108);
+ stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
+ stringBuffer.append(TEXT_109);
+ stringBuffer.append(genOperation.getGenClass().getQualifiedClassifierAccessor());
stringBuffer.append(TEXT_110);
+ stringBuffer.append(index);
+ stringBuffer.append(TEXT_111);
+ stringBuffer.append(oclQry);
+ stringBuffer.append(TEXT_112);
stringBuffer.append(UML2GenModelUtil.getUpperName(genOperation.getName()));
stringBuffer.append(genOperation.getGenParameters().size() == 0 ? "" : "__" + UML2GenModelUtil.getUpperName(genOperation.getParameterTypes("_", false)));
- stringBuffer.append(TEXT_111);
- stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ParserException"));
- stringBuffer.append(TEXT_112);
- stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ecore.OCL"));
stringBuffer.append(TEXT_113);
- stringBuffer.append(oclQry);
+ stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ParserException"));
stringBuffer.append(TEXT_114);
- if (!genOperation.getGenParameters().isEmpty()) {
+ stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.ecore.OCL"));
stringBuffer.append(TEXT_115);
+ stringBuffer.append(oclQry);
+ stringBuffer.append(TEXT_116);
+ if (!genOperation.getGenParameters().isEmpty()) {
+ stringBuffer.append(TEXT_117);
stringBuffer.append(genModel.getImportedName("org.eclipse.ocl.EvaluationEnvironment"));
if (genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50) {
- stringBuffer.append(TEXT_116);
- }
- stringBuffer.append(TEXT_117);
- for (GenParameter genParameter : genOperation.getGenParameters()) {
stringBuffer.append(TEXT_118);
- stringBuffer.append(genParameter.getName());
+ }
stringBuffer.append(TEXT_119);
- stringBuffer.append(genParameter.getName());
+ for (GenParameter genParameter : genOperation.getGenParameters()) {
stringBuffer.append(TEXT_120);
+ stringBuffer.append(genParameter.getName());
+ stringBuffer.append(TEXT_121);
+ stringBuffer.append(genParameter.getName());
+ stringBuffer.append(TEXT_122);
stringBuffer.append(genModel.getNonNLS());
}
}
if (genOperation.isListType()) {
if (genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50) {
- stringBuffer.append(TEXT_121);
- }
- stringBuffer.append(TEXT_122);
- stringBuffer.append(genModel.getImportedName("java.util.Collection"));
stringBuffer.append(TEXT_123);
- stringBuffer.append(genOperation.getListItemType(null));
+ }
stringBuffer.append(TEXT_124);
stringBuffer.append(genModel.getImportedName("java.util.Collection"));
stringBuffer.append(TEXT_125);
stringBuffer.append(genOperation.getListItemType(null));
stringBuffer.append(TEXT_126);
- stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ stringBuffer.append(genModel.getImportedName("java.util.Collection"));
stringBuffer.append(TEXT_127);
- stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.BasicEList"));
- stringBuffer.append(TEXT_128);
stringBuffer.append(genOperation.getListItemType(null));
+ stringBuffer.append(TEXT_128);
+ stringBuffer.append(genClass.safeName(genClass.getUncapName()));
stringBuffer.append(TEXT_129);
- } else if (genOperation.isPrimitiveType()) {
+ stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.util.BasicEList"));
stringBuffer.append(TEXT_130);
- stringBuffer.append(genOperation.getObjectType(null));
+ stringBuffer.append(genOperation.getListItemType(null));
stringBuffer.append(TEXT_131);
- stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ } else if (genOperation.isPrimitiveType()) {
stringBuffer.append(TEXT_132);
- stringBuffer.append(genOperation.getPrimitiveValueFunction());
+ stringBuffer.append(genOperation.getObjectType(null));
stringBuffer.append(TEXT_133);
- } else {
- stringBuffer.append(TEXT_134);
- stringBuffer.append(genOperation.getImportedType(null));
- stringBuffer.append(TEXT_135);
stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ stringBuffer.append(TEXT_134);
+ stringBuffer.append(genOperation.getPrimitiveValueFunction());
+ stringBuffer.append(TEXT_135);
+ } else {
stringBuffer.append(TEXT_136);
+ stringBuffer.append(genOperation.getImportedType(null));
+ stringBuffer.append(TEXT_137);
+ stringBuffer.append(genClass.safeName(genClass.getUncapName()));
+ stringBuffer.append(TEXT_138);
}
} else {
- stringBuffer.append(TEXT_137);
+ stringBuffer.append(TEXT_139);
//Operations/genOperation.todo.override.javajetinc
}
- stringBuffer.append(TEXT_138);
+ stringBuffer.append(TEXT_140);
//Operations/genOperation.override.javajetinc
}
- stringBuffer.append(TEXT_139);
+ stringBuffer.append(TEXT_141);
stringBuffer.append(UML2GenModelUtil.getOperationsClassName(genClass));
genModel.emitSortedImports();
return stringBuffer.toString();
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 5b6e00a..8a44a11 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
@@ -153,6 +153,8 @@
{
if (<%=diagnostics%> != null)
{
+<%@ include file="genOperation.diagnostics.override.javajetinc" fail="alternative" %>
+<%@ start %>
<%=diagnostics%>.add
(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
@@ -160,6 +162,7 @@
<%=opClass.getGenPackage().getImportedValidatorClassName()%>.<%=opClass.getOperationID(genOperation)%>,
<%=genModel.getImportedName("org.eclipse.emf.ecore.plugin.EcorePlugin")%>.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "<%=genOperation.getName()%>", <%=genModel.getImportedName("org.eclipse.emf.ecore.util.EObjectValidator")%>.getObjectLabel(this, <%=context%>) }),<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
new Object [] { this }));
+<%@ end %><%//genOperation.diagnostics.override.javajetinc%>
}
return false;
}
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 46e5af0..8cc869d 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.15 2011/05/09 03:27:09 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.16 2011/05/09 03:33:03 khussey Exp $" %>
<%
/**
* <copyright>
@@ -13,7 +13,7 @@
* IBM - initial API and implementation
* Kenn Hussey (Embarcadero Technologies) - 206636, 224693
* Lutz Wrage - 242726
- * Kenn Hussey - 344908, 284810
+ * Kenn Hussey - 344908, 284810, 345083
*
* </copyright>
*/
@@ -166,6 +166,8 @@
{
if (<%=diagnostics%> != null)
{
+<%@ include file="Operations/genOperation.diagnostics.override.javajetinc" fail="alternative" %>
+<%@ start %>
<%=diagnostics%>.add
(new <%=genModel.getImportedName("org.eclipse.emf.common.util.BasicDiagnostic")%>
(<%=genModel.getImportedName("org.eclipse.emf.common.util.Diagnostic")%>.ERROR,
@@ -173,6 +175,7 @@
<%=opClass.getGenPackage().getImportedValidatorClassName()%>.<%=opClass.getOperationID(genOperation)%>,
org.eclipse.emf.ecore.plugin.EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "<%=genOperation.getName()%>", org.eclipse.emf.ecore.util.EObjectValidator.getObjectLabel(<%=genClass.safeName(genClass.getUncapName())%>, <%=context%>) }),<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%>
new Object [] { <%=genClass.safeName(genClass.getUncapName())%> }));
+<%@ end %><%//Operations/genOperation.diagnostics.override.javajetinc%>
}
return false;
}