Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorradvorak2006-06-26 13:04:28 -0400
committerradvorak2006-06-26 13:04:28 -0400
commit3bc61dbb9f1205073e10d420c626b574a91603b6 (patch)
tree912312a7c37a4f22ab17dd88bfd9888f6c50e752
parent9093b1177a22db7285ea170ba61cba9949ccb6b7 (diff)
downloadorg.eclipse.gmf-tooling-3bc61dbb9f1205073e10d420c626b574a91603b6.tar.gz
org.eclipse.gmf-tooling-3bc61dbb9f1205073e10d420c626b574a91603b6.tar.xz
org.eclipse.gmf-tooling-3bc61dbb9f1205073e10d420c626b574a91603b6.zip
#148676 Template for OCLExpressionFactory should not define environment variables as implicit
-rw-r--r--plugins/org.eclipse.gmf.codegen.lite/src-templates/org/eclipse/gmf/codegen/templates/lite/expressions/OCLExpressionFactoryGenerator.java2
-rw-r--r--plugins/org.eclipse.gmf.codegen.lite/templates/expressions/OCLExpressionFactory.javajet2
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java2
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet2
4 files changed, 4 insertions, 4 deletions
diff --git a/plugins/org.eclipse.gmf.codegen.lite/src-templates/org/eclipse/gmf/codegen/templates/lite/expressions/OCLExpressionFactoryGenerator.java b/plugins/org.eclipse.gmf.codegen.lite/src-templates/org/eclipse/gmf/codegen/templates/lite/expressions/OCLExpressionFactoryGenerator.java
index a78154ae9..312f9a82e 100644
--- a/plugins/org.eclipse.gmf.codegen.lite/src-templates/org/eclipse/gmf/codegen/templates/lite/expressions/OCLExpressionFactoryGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen.lite/src-templates/org/eclipse/gmf/codegen/templates/lite/expressions/OCLExpressionFactoryGenerator.java
@@ -25,7 +25,7 @@ public class OCLExpressionFactoryGenerator
protected final String TEXT_8 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tpublic static ";
protected final String TEXT_9 = " getExpression(String body, EClassifier context, Map environment) {\t\t" + NL + "\t\treturn new Expression(body, context, environment);" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tpublic static ";
protected final String TEXT_10 = " getExpression(String body, EClassifier context) {\t\t" + NL + "\t\treturn getExpression(body, context, Collections.EMPTY_MAP);" + NL + "\t}\t" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tprivate static class Expression extends ";
- protected final String TEXT_11 = " {" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate Query query;" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t\t" + NL + "\t\tpublic Expression(String body, EClassifier context, Map environment) {" + NL + "\t\t\tsuper(body, context, environment);" + NL + "\t\t\t" + NL + "\t\t\tIOCLHelper oclHelper = (environment.isEmpty()) ? " + NL + "\t\t\t\t\tHelperUtil.createOCLHelper() :" + NL + "\t\t\t\t\tHelperUtil.createOCLHelper(createCustomEnv(environment));" + NL + "\t\t\toclHelper.setContext(context());" + NL + "\t\t\ttry {" + NL + "\t\t\t\tOCLExpression oclExpression = oclHelper.createQuery(body);" + NL + "\t\t\t\tthis.query = QueryFactory.eINSTANCE.createQuery(oclExpression);" + NL + "\t\t\t} catch (OCLParsingException e) {" + NL + "\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t}\t\t\t" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprotected Object doEvaluate(Object context, Map env) {" + NL + "\t\t\tif (query == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\tEvaluationEnvironment evalEnv = query.getEvaluationEnvironment();" + NL + "\t\t\t// init environment" + NL + "\t\t\tfor (Iterator it = env.entrySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\tMap.Entry nextEntry = (Map.Entry) it.next();" + NL + "\t\t\t\tevalEnv.replace((String)nextEntry.getKey(), nextEntry.getValue());\t\t\t\t\t" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\ttry {" + NL + "\t\t\t\tinitExtentMap(context);" + NL + "\t\t\t\tObject result = query.evaluate(context);" + NL + "\t\t\t\treturn (result != Types.OCL_INVALID) ? result : null;" + NL + "\t\t\t} finally {\t\t\t\t" + NL + "\t\t\t\tevalEnv.clear();" + NL + "\t\t\t\tquery.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprotected Object performCast(Object value, ETypedElement targetType) {" + NL + "\t\t\tif (targetType.getEType() instanceof EEnum) {" + NL + "\t\t\t\tif(value instanceof EEnumLiteral) {" + NL + "\t\t\t\t\tEEnumLiteral literal = (EEnumLiteral)value;" + NL + "\t\t\t\t\treturn (literal.getInstance() != null) ? literal.getInstance() : literal;" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\treturn super.performCast(value, targetType);" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprivate void initExtentMap(Object context) {" + NL + "\t\t\tif(query == null || context == null) {" + NL + "\t\t\t\treturn;" + NL + "\t\t\t}" + NL + "\t\t\tfinal Query queryToInit = query;" + NL + "\t\t\tfinal Object extentContext = context;" + NL + "\t\t\t" + NL + "\t\t\tqueryToInit.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\tif(queryToInit.queryText() != null && queryToInit.queryText().indexOf(\"allInstances\") >= 0) {\t\t\t" + NL + "\t\t\t\tAbstractVisitor visitior = new AbstractVisitor() {" + NL + "\t\t\t\t\tprivate boolean usesAllInstances = false;" + NL + "\t\t\t\t\t" + NL + "\t\t\t\t\tpublic Object visitOperationCallExp(OperationCallExp oc) {" + NL + "\t\t\t\t\t\tif(!usesAllInstances) {" + NL + "\t\t\t\t\t\t\tusesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();" + NL + "\t\t\t\t\t\t\tif(usesAllInstances) {" + NL + "\t\t\t\t\t\t\t\tqueryToInit.setExtentMap(EcoreEnvironmentFactory.ECORE_INSTANCE.createExtentMap(extentContext));" + NL + "\t\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\treturn super.visitOperationCallExp(oc);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t};" + NL + "\t\t\t\tqueryToInit.getExpression().accept(visitior);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static EcoreEnvironmentFactory createCustomEnv(Map environment) {" + NL + "\t\t\tfinal Map env = environment;" + NL + "\t\t\treturn new EcoreEnvironmentFactory() {\t\t\t\t\t" + NL + "\t\t\t\tpublic Environment createClassifierContext(Object context) {" + NL + "\t\t\t\t\tEnvironment ecoreEnv = super.createClassifierContext(context);" + NL + "\t\t\t\t\tfor (Iterator it = env.keySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\t\t\tString varName = (String)it.next();" + NL + "\t\t\t\t\t\tEClassifier varType = (EClassifier)env.get(varName);" + NL + "\t\t\t\t\t\tecoreEnv.addElement(varName, createVar(varName, varType), true);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t\treturn ecoreEnv;" + NL + "\t\t\t\t}" + NL + "\t\t\t};\t\t\t\t" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static Variable createVar(String name, EClassifier type) {" + NL + "\t\t\tVariable var = ExpressionsFactory.eINSTANCE.createVariable();" + NL + "\t\t\tvar.setName(name);" + NL + "\t\t\tvar.setType(EcoreEnvironment.getOCLType(type));" + NL + "\t\t\treturn var;" + NL + "\t\t}\t\t" + NL + "\t}" + NL + "}";
+ protected final String TEXT_11 = " {" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate Query query;" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t\t" + NL + "\t\tpublic Expression(String body, EClassifier context, Map environment) {" + NL + "\t\t\tsuper(body, context, environment);" + NL + "\t\t\t" + NL + "\t\t\tIOCLHelper oclHelper = (environment.isEmpty()) ? " + NL + "\t\t\t\t\tHelperUtil.createOCLHelper() :" + NL + "\t\t\t\t\tHelperUtil.createOCLHelper(createCustomEnv(environment));" + NL + "\t\t\toclHelper.setContext(context());" + NL + "\t\t\ttry {" + NL + "\t\t\t\tOCLExpression oclExpression = oclHelper.createQuery(body);" + NL + "\t\t\t\tthis.query = QueryFactory.eINSTANCE.createQuery(oclExpression);" + NL + "\t\t\t} catch (OCLParsingException e) {" + NL + "\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t}\t\t\t" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprotected Object doEvaluate(Object context, Map env) {" + NL + "\t\t\tif (query == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\tEvaluationEnvironment evalEnv = query.getEvaluationEnvironment();" + NL + "\t\t\t// init environment" + NL + "\t\t\tfor (Iterator it = env.entrySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\tMap.Entry nextEntry = (Map.Entry) it.next();" + NL + "\t\t\t\tevalEnv.replace((String)nextEntry.getKey(), nextEntry.getValue());\t\t\t\t\t" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\ttry {" + NL + "\t\t\t\tinitExtentMap(context);" + NL + "\t\t\t\tObject result = query.evaluate(context);" + NL + "\t\t\t\treturn (result != Types.OCL_INVALID) ? result : null;" + NL + "\t\t\t} finally {\t\t\t\t" + NL + "\t\t\t\tevalEnv.clear();" + NL + "\t\t\t\tquery.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprotected Object performCast(Object value, ETypedElement targetType) {" + NL + "\t\t\tif (targetType.getEType() instanceof EEnum) {" + NL + "\t\t\t\tif(value instanceof EEnumLiteral) {" + NL + "\t\t\t\t\tEEnumLiteral literal = (EEnumLiteral)value;" + NL + "\t\t\t\t\treturn (literal.getInstance() != null) ? literal.getInstance() : literal;" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\treturn super.performCast(value, targetType);" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprivate void initExtentMap(Object context) {" + NL + "\t\t\tif(query == null || context == null) {" + NL + "\t\t\t\treturn;" + NL + "\t\t\t}" + NL + "\t\t\tfinal Query queryToInit = query;" + NL + "\t\t\tfinal Object extentContext = context;" + NL + "\t\t\t" + NL + "\t\t\tqueryToInit.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\tif(queryToInit.queryText() != null && queryToInit.queryText().indexOf(\"allInstances\") >= 0) {\t\t\t" + NL + "\t\t\t\tAbstractVisitor visitior = new AbstractVisitor() {" + NL + "\t\t\t\t\tprivate boolean usesAllInstances = false;" + NL + "\t\t\t\t\t" + NL + "\t\t\t\t\tpublic Object visitOperationCallExp(OperationCallExp oc) {" + NL + "\t\t\t\t\t\tif(!usesAllInstances) {" + NL + "\t\t\t\t\t\t\tusesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();" + NL + "\t\t\t\t\t\t\tif(usesAllInstances) {" + NL + "\t\t\t\t\t\t\t\tqueryToInit.setExtentMap(EcoreEnvironmentFactory.ECORE_INSTANCE.createExtentMap(extentContext));" + NL + "\t\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\treturn super.visitOperationCallExp(oc);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t};" + NL + "\t\t\t\tqueryToInit.getExpression().accept(visitior);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static EcoreEnvironmentFactory createCustomEnv(Map environment) {" + NL + "\t\t\tfinal Map env = environment;" + NL + "\t\t\treturn new EcoreEnvironmentFactory() {\t\t\t\t\t" + NL + "\t\t\t\tpublic Environment createClassifierContext(Object context) {" + NL + "\t\t\t\t\tEnvironment ecoreEnv = super.createClassifierContext(context);" + NL + "\t\t\t\t\tfor (Iterator it = env.keySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\t\t\tString varName = (String)it.next();" + NL + "\t\t\t\t\t\tEClassifier varType = (EClassifier)env.get(varName);" + NL + "\t\t\t\t\t\tecoreEnv.addElement(varName, createVar(varName, varType), false);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t\treturn ecoreEnv;" + NL + "\t\t\t\t}" + NL + "\t\t\t};\t\t\t\t" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static Variable createVar(String name, EClassifier type) {" + NL + "\t\t\tVariable var = ExpressionsFactory.eINSTANCE.createVariable();" + NL + "\t\t\tvar.setName(name);" + NL + "\t\t\tvar.setType(EcoreEnvironment.getOCLType(type));" + NL + "\t\t\treturn var;" + NL + "\t\t}\t\t" + NL + "\t}" + NL + "}";
protected final String TEXT_12 = NL;
public String generate(Object argument)
diff --git a/plugins/org.eclipse.gmf.codegen.lite/templates/expressions/OCLExpressionFactory.javajet b/plugins/org.eclipse.gmf.codegen.lite/templates/expressions/OCLExpressionFactory.javajet
index dfdc6a084..8c1d5bc36 100644
--- a/plugins/org.eclipse.gmf.codegen.lite/templates/expressions/OCLExpressionFactory.javajet
+++ b/plugins/org.eclipse.gmf.codegen.lite/templates/expressions/OCLExpressionFactory.javajet
@@ -168,7 +168,7 @@ public class <%=factoryClassName%> {
for (Iterator it = env.keySet().iterator(); it.hasNext();) {
String varName = (String)it.next();
EClassifier varType = (EClassifier)env.get(varName);
- ecoreEnv.addElement(varName, createVar(varName, varType), true);
+ ecoreEnv.addElement(varName, createVar(varName, varType), false);
}
return ecoreEnv;
}
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java
index c93182c71..e7eeebc1d 100644
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java
@@ -25,7 +25,7 @@ public class OCLExpressionFactoryGenerator
protected final String TEXT_8 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tpublic static ";
protected final String TEXT_9 = " getExpression(String body, EClassifier context, Map environment) {\t\t" + NL + "\t\treturn new Expression(body, context, environment);" + NL + "\t}" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tpublic static ";
protected final String TEXT_10 = " getExpression(String body, EClassifier context) {\t\t" + NL + "\t\treturn getExpression(body, context, Collections.EMPTY_MAP);" + NL + "\t}\t" + NL + "\t" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */\t" + NL + "\tprivate static class Expression extends ";
- protected final String TEXT_11 = " {" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate Query query;" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t\t" + NL + "\t\tpublic Expression(String body, EClassifier context, Map environment) {" + NL + "\t\t\tsuper(body, context, environment);" + NL + "\t\t\t" + NL + "\t\t\tIOCLHelper oclHelper = (environment.isEmpty()) ? " + NL + "\t\t\t\t\tHelperUtil.createOCLHelper() :" + NL + "\t\t\t\t\tHelperUtil.createOCLHelper(createCustomEnv(environment));" + NL + "\t\t\toclHelper.setContext(context());" + NL + "\t\t\ttry {" + NL + "\t\t\t\tOCLExpression oclExpression = oclHelper.createQuery(body);" + NL + "\t\t\t\tthis.query = QueryFactory.eINSTANCE.createQuery(oclExpression);" + NL + "\t\t\t} catch (OCLParsingException e) {" + NL + "\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t}\t\t\t" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprotected Object doEvaluate(Object context, Map env) {" + NL + "\t\t\tif (query == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\tEvaluationEnvironment evalEnv = query.getEvaluationEnvironment();" + NL + "\t\t\t// init environment" + NL + "\t\t\tfor (Iterator it = env.entrySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\tMap.Entry nextEntry = (Map.Entry) it.next();" + NL + "\t\t\t\tevalEnv.replace((String)nextEntry.getKey(), nextEntry.getValue());\t\t\t\t\t" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\ttry {" + NL + "\t\t\t\tinitExtentMap(context);" + NL + "\t\t\t\tObject result = query.evaluate(context);" + NL + "\t\t\t\treturn (result != Types.OCL_INVALID) ? result : null;" + NL + "\t\t\t} finally {\t\t\t\t" + NL + "\t\t\t\tevalEnv.clear();" + NL + "\t\t\t\tquery.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprotected Object performCast(Object value, ETypedElement targetType) {" + NL + "\t\t\tif (targetType.getEType() instanceof EEnum) {" + NL + "\t\t\t\tif(value instanceof EEnumLiteral) {" + NL + "\t\t\t\t\tEEnumLiteral literal = (EEnumLiteral)value;" + NL + "\t\t\t\t\treturn (literal.getInstance() != null) ? literal.getInstance() : literal;" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\treturn super.performCast(value, targetType);" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprivate void initExtentMap(Object context) {" + NL + "\t\t\tif(query == null || context == null) {" + NL + "\t\t\t\treturn;" + NL + "\t\t\t}" + NL + "\t\t\tfinal Query queryToInit = query;" + NL + "\t\t\tfinal Object extentContext = context;" + NL + "\t\t\t" + NL + "\t\t\tqueryToInit.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\tif(queryToInit.queryText() != null && queryToInit.queryText().indexOf(\"allInstances\") >= 0) {\t\t\t" + NL + "\t\t\t\tAbstractVisitor visitior = new AbstractVisitor() {" + NL + "\t\t\t\t\tprivate boolean usesAllInstances = false;" + NL + "\t\t\t\t\t" + NL + "\t\t\t\t\tpublic Object visitOperationCallExp(OperationCallExp oc) {" + NL + "\t\t\t\t\t\tif(!usesAllInstances) {" + NL + "\t\t\t\t\t\t\tusesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();" + NL + "\t\t\t\t\t\t\tif(usesAllInstances) {" + NL + "\t\t\t\t\t\t\t\tqueryToInit.setExtentMap(EcoreEnvironmentFactory.ECORE_INSTANCE.createExtentMap(extentContext));" + NL + "\t\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\treturn super.visitOperationCallExp(oc);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t};" + NL + "\t\t\t\tqueryToInit.getExpression().accept(visitior);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static EcoreEnvironmentFactory createCustomEnv(Map environment) {" + NL + "\t\t\tfinal Map env = environment;" + NL + "\t\t\treturn new EcoreEnvironmentFactory() {\t\t\t\t\t" + NL + "\t\t\t\tpublic Environment createClassifierContext(Object context) {" + NL + "\t\t\t\t\tEnvironment ecoreEnv = super.createClassifierContext(context);" + NL + "\t\t\t\t\tfor (Iterator it = env.keySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\t\t\tString varName = (String)it.next();" + NL + "\t\t\t\t\t\tEClassifier varType = (EClassifier)env.get(varName);" + NL + "\t\t\t\t\t\tecoreEnv.addElement(varName, createVar(varName, varType), true);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t\treturn ecoreEnv;" + NL + "\t\t\t\t}" + NL + "\t\t\t};\t\t\t\t" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static Variable createVar(String name, EClassifier type) {" + NL + "\t\t\tVariable var = ExpressionsFactory.eINSTANCE.createVariable();" + NL + "\t\t\tvar.setName(name);" + NL + "\t\t\tvar.setType(EcoreEnvironment.getOCLType(type));" + NL + "\t\t\treturn var;" + NL + "\t\t}\t\t" + NL + "\t}" + NL + "}";
+ protected final String TEXT_11 = " {" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate Query query;" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t\t" + NL + "\t\tpublic Expression(String body, EClassifier context, Map environment) {" + NL + "\t\t\tsuper(body, context, environment);" + NL + "\t\t\t" + NL + "\t\t\tIOCLHelper oclHelper = (environment.isEmpty()) ? " + NL + "\t\t\t\t\tHelperUtil.createOCLHelper() :" + NL + "\t\t\t\t\tHelperUtil.createOCLHelper(createCustomEnv(environment));" + NL + "\t\t\toclHelper.setContext(context());" + NL + "\t\t\ttry {" + NL + "\t\t\t\tOCLExpression oclExpression = oclHelper.createQuery(body);" + NL + "\t\t\t\tthis.query = QueryFactory.eINSTANCE.createQuery(oclExpression);" + NL + "\t\t\t} catch (OCLParsingException e) {" + NL + "\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t}\t\t\t" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprotected Object doEvaluate(Object context, Map env) {" + NL + "\t\t\tif (query == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\tEvaluationEnvironment evalEnv = query.getEvaluationEnvironment();" + NL + "\t\t\t// init environment" + NL + "\t\t\tfor (Iterator it = env.entrySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\tMap.Entry nextEntry = (Map.Entry) it.next();" + NL + "\t\t\t\tevalEnv.replace((String)nextEntry.getKey(), nextEntry.getValue());\t\t\t\t\t" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\ttry {" + NL + "\t\t\t\tinitExtentMap(context);" + NL + "\t\t\t\tObject result = query.evaluate(context);" + NL + "\t\t\t\treturn (result != Types.OCL_INVALID) ? result : null;" + NL + "\t\t\t} finally {\t\t\t\t" + NL + "\t\t\t\tevalEnv.clear();" + NL + "\t\t\t\tquery.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprotected Object performCast(Object value, ETypedElement targetType) {" + NL + "\t\t\tif (targetType.getEType() instanceof EEnum) {" + NL + "\t\t\t\tif(value instanceof EEnumLiteral) {" + NL + "\t\t\t\t\tEEnumLiteral literal = (EEnumLiteral)value;" + NL + "\t\t\t\t\treturn (literal.getInstance() != null) ? literal.getInstance() : literal;" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\treturn super.performCast(value, targetType);" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated" + NL + "\t\t */\t" + NL + "\t\tprivate void initExtentMap(Object context) {" + NL + "\t\t\tif(query == null || context == null) {" + NL + "\t\t\t\treturn;" + NL + "\t\t\t}" + NL + "\t\t\tfinal Query queryToInit = query;" + NL + "\t\t\tfinal Object extentContext = context;" + NL + "\t\t\t" + NL + "\t\t\tqueryToInit.setExtentMap(Collections.EMPTY_MAP);" + NL + "\t\t\tif(queryToInit.queryText() != null && queryToInit.queryText().indexOf(\"allInstances\") >= 0) {\t\t\t" + NL + "\t\t\t\tAbstractVisitor visitior = new AbstractVisitor() {" + NL + "\t\t\t\t\tprivate boolean usesAllInstances = false;" + NL + "\t\t\t\t\t" + NL + "\t\t\t\t\tpublic Object visitOperationCallExp(OperationCallExp oc) {" + NL + "\t\t\t\t\t\tif(!usesAllInstances) {" + NL + "\t\t\t\t\t\t\tusesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();" + NL + "\t\t\t\t\t\t\tif(usesAllInstances) {" + NL + "\t\t\t\t\t\t\t\tqueryToInit.setExtentMap(EcoreEnvironmentFactory.ECORE_INSTANCE.createExtentMap(extentContext));" + NL + "\t\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\t}" + NL + "\t\t\t\t\t\treturn super.visitOperationCallExp(oc);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t};" + NL + "\t\t\t\tqueryToInit.getExpression().accept(visitior);" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static EcoreEnvironmentFactory createCustomEnv(Map environment) {" + NL + "\t\t\tfinal Map env = environment;" + NL + "\t\t\treturn new EcoreEnvironmentFactory() {\t\t\t\t\t" + NL + "\t\t\t\tpublic Environment createClassifierContext(Object context) {" + NL + "\t\t\t\t\tEnvironment ecoreEnv = super.createClassifierContext(context);" + NL + "\t\t\t\t\tfor (Iterator it = env.keySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\t\t\tString varName = (String)it.next();" + NL + "\t\t\t\t\t\tEClassifier varType = (EClassifier)env.get(varName);" + NL + "\t\t\t\t\t\tecoreEnv.addElement(varName, createVar(varName, varType), false);" + NL + "\t\t\t\t\t}" + NL + "\t\t\t\t\treturn ecoreEnv;" + NL + "\t\t\t\t}" + NL + "\t\t\t};\t\t\t\t" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate static Variable createVar(String name, EClassifier type) {" + NL + "\t\t\tVariable var = ExpressionsFactory.eINSTANCE.createVariable();" + NL + "\t\t\tvar.setName(name);" + NL + "\t\t\tvar.setType(EcoreEnvironment.getOCLType(type));" + NL + "\t\t\treturn var;" + NL + "\t\t}\t\t" + NL + "\t}" + NL + "}";
protected final String TEXT_12 = NL;
public String generate(Object argument)
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet b/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet
index 9b7591e71..178eca81f 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet
+++ b/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet
@@ -168,7 +168,7 @@ public class <%=factoryClassName%> {
for (Iterator it = env.keySet().iterator(); it.hasNext();) {
String varName = (String)it.next();
EClassifier varType = (EClassifier)env.get(varName);
- ecoreEnv.addElement(varName, createVar(varName, varType), true);
+ ecoreEnv.addElement(varName, createVar(varName, varType), false);
}
return ecoreEnv;
}

Back to the top