Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2007-09-14 14:23:24 -0400
committerdstadnik2007-09-14 14:23:24 -0400
commit9f9de8ffbe506a32015de870deeb76287d7ff10e (patch)
tree67f1d478c7bead68599cbc138bc58832209cebcd
parent9309bdcd81dc15824657746669426cc250767d1e (diff)
downloadorg.eclipse.gmf-tooling-9f9de8ffbe506a32015de870deeb76287d7ff10e.tar.gz
org.eclipse.gmf-tooling-9f9de8ffbe506a32015de870deeb76287d7ff10e.tar.xz
org.eclipse.gmf-tooling-9f9de8ffbe506a32015de870deeb76287d7ff10e.zip
get rid of jet
-rw-r--r--plugins/org.eclipse.gmf.codegen/.classpath1
-rw-r--r--plugins/org.eclipse.gmf.codegen/.jetproperties4
-rw-r--r--plugins/org.eclipse.gmf.codegen/.project6
-rw-r--r--plugins/org.eclipse.gmf.codegen/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.gmf.codegen/build.properties6
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java95
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/RegexpExpressionFactoryGenerator.java81
-rw-r--r--plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java21
-rw-r--r--plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java22
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/common.skeleton109
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/copyright4java.jetinc8
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet204
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/RegexpExpressionFactory.javajet95
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/getExpression.jetinc49
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/initEnv.jetinc26
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/expressions/javaExpressionOperation.jetinc40
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt159
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt74
18 files changed, 245 insertions, 756 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/.classpath b/plugins/org.eclipse.gmf.codegen/.classpath
index 3a2626353..472ee29b1 100644
--- a/plugins/org.eclipse.gmf.codegen/.classpath
+++ b/plugins/org.eclipse.gmf.codegen/.classpath
@@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src-templates"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/plugins/org.eclipse.gmf.codegen/.jetproperties b/plugins/org.eclipse.gmf.codegen/.jetproperties
deleted file mode 100644
index f0dd09e85..000000000
--- a/plugins/org.eclipse.gmf.codegen/.jetproperties
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<jet-settings>
- <template-container>templates</template-container> <source-container>src-templates</source-container>
-</jet-settings>
diff --git a/plugins/org.eclipse.gmf.codegen/.project b/plugins/org.eclipse.gmf.codegen/.project
index e2fd63584..f37c7417f 100644
--- a/plugins/org.eclipse.gmf.codegen/.project
+++ b/plugins/org.eclipse.gmf.codegen/.project
@@ -6,11 +6,6 @@
</projects>
<buildSpec>
<buildCommand>
- <name>org.eclipse.emf.codegen.JETBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
@@ -32,7 +27,6 @@
</buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.emf.codegen.jet.IJETNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
diff --git a/plugins/org.eclipse.gmf.codegen/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmf.codegen/META-INF/MANIFEST.MF
index ae96dabe2..4326d1e18 100644
--- a/plugins/org.eclipse.gmf.codegen/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.gmf.codegen/META-INF/MANIFEST.MF
@@ -8,7 +8,6 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.gmf.codegen.gmfgen,
org.eclipse.gmf.codegen.gmfgen.impl;x-friends:="org.eclipse.gmf.codegen.lite",
org.eclipse.gmf.codegen.gmfgen.util,
- org.eclipse.gmf.codegen.templates.expressions;x-friends:="org.eclipse.gmf.codegen.lite",
org.eclipse.gmf.codegen.util,
org.eclipse.gmf.internal.codegen.util;x-friends:="org.eclipse.gmf.bridge.ui,org.eclipse.gmf.codegen.ui,org.eclipse.gmf.tests"
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
diff --git a/plugins/org.eclipse.gmf.codegen/build.properties b/plugins/org.eclipse.gmf.codegen/build.properties
index c6f9ad9b3..aeb055ce2 100644
--- a/plugins/org.eclipse.gmf.codegen/build.properties
+++ b/plugins/org.eclipse.gmf.codegen/build.properties
@@ -16,9 +16,5 @@ bin.includes = plugin.xml,\
templates/,\
about.html
jars.compile.order = .
-
-
output.. = bin/
-
-source.. = src/,\
- src-templates/
+source.. = src/
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
deleted file mode 100644
index bad8e0d44..000000000
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/OCLExpressionFactoryGenerator.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package org.eclipse.gmf.codegen.templates.expressions;
-
-import org.eclipse.gmf.codegen.gmfgen.*;
-import org.eclipse.gmf.common.codegen.*;
-
-public class OCLExpressionFactoryGenerator
-{
- protected static String nl;
- public static synchronized OCLExpressionFactoryGenerator create(String lineSeparator)
- {
- nl = lineSeparator;
- OCLExpressionFactoryGenerator result = new OCLExpressionFactoryGenerator();
- nl = null;
- return result;
- }
-
- public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "/*" + NL + " * ";
- protected final String TEXT_2 = NL + " */";
- protected final String TEXT_3 = NL;
- protected final String TEXT_4 = NL;
- protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated " + NL + " */" + NL + "public class ";
- protected final String TEXT_6 = " {" + NL + "" + NL + "\t";
- protected final String TEXT_7 = NL + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */" + NL + "\tprivate ";
- 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 WeakReference queryRef;" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */\t\t" + NL + "\t\tprivate final OCL oclInstance;" + NL + "" + 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);" + NL + "\t\t\toclInstance = OCL.newInstance();" + NL + "\t\t\tinitCustomEnv(oclInstance.getEnvironment(), environment);" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */" + NL + "\t\tprotected Query getQuery() {" + NL + "\t\t\tQuery oclQuery = null;" + NL + "\t\t\tif(this.queryRef != null) {" + NL + "\t\t\t\toclQuery = (Query)this.queryRef.get();" + NL + "\t\t\t}" + NL + "\t\t\tif(oclQuery == null) {" + NL + "\t\t\t\tOCLHelper oclHelper = oclInstance.createOCLHelper();" + NL + "\t\t\t\toclHelper.setContext(context());" + NL + "\t\t\t\ttry {" + NL + "\t\t\t\t\tOCLExpression oclExpression = oclHelper.createQuery(body());" + NL + "\t\t\t\t\toclQuery = oclInstance.createQuery(oclExpression);" + NL + "\t\t\t\t\tthis.queryRef = new WeakReference(oclQuery);" + NL + "\t\t\t\t\tsetStatus(IStatus.OK, null, null);" + NL + "\t\t\t\t} catch (ParserException e) {" + NL + "\t\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\treturn oclQuery;\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\tQuery oclQuery = getQuery();\t\t\t\t\t" + NL + "\t\t\tif (oclQuery == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\tEvaluationEnvironment evalEnv = oclQuery.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 = oclQuery.evaluate(context);" + NL + "\t\t\t\treturn (result != oclInstance.getEnvironment().getOCLStandardLibrary().getOclInvalid()) ? result : null;" + NL + "\t\t\t} finally {\t\t\t\t" + NL + "\t\t\t\tevalEnv.clear();" + NL + "\t\t\t\toclQuery.getExtentMap().clear();" + 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 (!getStatus().isOK() || context == null) {" + NL + "\t\t\t\treturn;" + NL + "\t\t\t}" + NL + "\t\t\tfinal Query queryToInit = getQuery();" + NL + "\t\t\tfinal Object extentContext = context;" + NL + "\t\t\t" + NL + "\t\t\tqueryToInit.getExtentMap().clear();" + NL + "\t\t\tif (queryToInit.queryText() != null && queryToInit.queryText().indexOf(PredefinedType.ALL_INSTANCES_NAME) >= 0) {" + 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.getExtentMap().putAll(oclInstance.getEvaluationEnvironment().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 void initCustomEnv(Environment ecoreEnv, Map environment) {" + NL + "\t\t\tfor (Iterator it = environment.keySet().iterator(); it.hasNext();) {" + NL + "\t\t\t\t\t\tString varName = (String)it.next();" + NL + "\t\t\t\tEClassifier varType = (EClassifier) environment.get(varName);" + NL + "\t\t\t\tecoreEnv.addElement(varName, createVar(ecoreEnv, varName, varType), false);" + NL + "\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(Environment ecoreEnv, String name, EClassifier type) {" + NL + "\t\t\tVariable var = EcoreFactory.eINSTANCE.createVariable(); // or ecoreEnv.getOCLFactory().createVariable()?" + NL + "\t\t\tvar.setName(name);" + NL + "\t\t\tvar.setType(ecoreEnv.getUMLReflection().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)
- {
- final StringBuffer stringBuffer = new StringBuffer();
-
-final GenExpressionInterpreter genInterpreter = (GenExpressionInterpreter) ((Object[]) argument)[0];
-final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
-final GenDiagram genDiagram = genInterpreter.getContainer().getEditorGen().getDiagram();
-final String factoryClassName = genInterpreter.getClassName();
-final String abstractExpressionClass = genInterpreter.getContainer().getAbstractExpressionQualifiedClassName();
-
-
-String copyrightText = genDiagram.getEditorGen().getCopyrightText();
-if (copyrightText != null && copyrightText.trim().length() > 0) {
-
- stringBuffer.append(TEXT_1);
- stringBuffer.append(copyrightText.replaceAll("\n", "\n * "));
- stringBuffer.append(TEXT_2);
- }
- importManager.emitPackageStatement(stringBuffer);
- stringBuffer.append(TEXT_3);
- importManager.markImportLocation(stringBuffer);
- stringBuffer.append(TEXT_4);
-
-importManager.registerInnerClass("Expression");
-importManager.addImport("java.util.Collections");
-importManager.addImport("java.util.Iterator");
-importManager.addImport("java.util.Map");
-importManager.addImport("java.lang.ref.WeakReference");
-importManager.addImport("org.eclipse.core.runtime.IStatus");
-importManager.addImport("org.eclipse.emf.ecore.EClassifier");
-importManager.addImport("org.eclipse.emf.ecore.EEnum");
-importManager.addImport("org.eclipse.emf.ecore.EEnumLiteral");
-importManager.addImport("org.eclipse.emf.ecore.ETypedElement");
-
-importManager.addImport("org.eclipse.ocl.Environment");
-importManager.addImport("org.eclipse.ocl.EvaluationEnvironment");
-importManager.addImport("org.eclipse.ocl.ParserException");
-importManager.addImport("org.eclipse.ocl.Query");
-importManager.addImport("org.eclipse.ocl.ecore.EcoreFactory");
-importManager.addImport("org.eclipse.ocl.ecore.OCL");
-importManager.addImport("org.eclipse.ocl.expressions.OCLExpression");
-importManager.addImport("org.eclipse.ocl.expressions.OperationCallExp");
-importManager.addImport("org.eclipse.ocl.expressions.Variable");
-importManager.addImport("org.eclipse.ocl.helper.OCLHelper");
-importManager.addImport("org.eclipse.ocl.utilities.AbstractVisitor");
-importManager.addImport("org.eclipse.ocl.utilities.PredefinedType");
-
-
- stringBuffer.append(TEXT_5);
- stringBuffer.append(factoryClassName);
- stringBuffer.append(TEXT_6);
- stringBuffer.append(TEXT_7);
- stringBuffer.append(factoryClassName);
- stringBuffer.append(TEXT_8);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_9);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_10);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_11);
- importManager.emitSortedImports();
- stringBuffer.append(TEXT_12);
- return stringBuffer.toString();
- }
-}
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/RegexpExpressionFactoryGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/RegexpExpressionFactoryGenerator.java
deleted file mode 100644
index 4a176cfa2..000000000
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/expressions/RegexpExpressionFactoryGenerator.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.eclipse.gmf.codegen.templates.expressions;
-
-import org.eclipse.gmf.codegen.gmfgen.*;
-import org.eclipse.gmf.common.codegen.*;
-
-public class RegexpExpressionFactoryGenerator
-{
- protected static String nl;
- public static synchronized RegexpExpressionFactoryGenerator create(String lineSeparator)
- {
- nl = lineSeparator;
- RegexpExpressionFactoryGenerator result = new RegexpExpressionFactoryGenerator();
- nl = null;
- return result;
- }
-
- public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = "/*" + NL + " * ";
- protected final String TEXT_2 = NL + " */";
- protected final String TEXT_3 = NL;
- protected final String TEXT_4 = NL + NL + "/**" + NL + " * @generated " + NL + " */" + NL + "public class ";
- protected final String TEXT_5 = " {" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */" + NL + "\tprivate ";
- protected final String TEXT_6 = "() {" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */" + NL + "\tpublic static ";
- protected final String TEXT_7 = " getExpression(String body," + NL + "\t\t\tEClassifier context, Map environment) {" + NL + "\t\treturn new Expression(body, context, environment);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */" + NL + "\tpublic static ";
- protected final String TEXT_8 = " getExpression(String body," + NL + "\t\t\tEClassifier context) {" + NL + "\t\treturn getExpression(body, context, Collections.EMPTY_MAP);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated " + NL + "\t */" + NL + "\tprivate static class Expression extends ";
- protected final String TEXT_9 = " {" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */" + NL + "\t\tprivate final Pattern pattern;" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */" + NL + "\t\tpublic Expression(String body, EClassifier context, Map environment) {" + NL + "\t\t\tsuper(body, context);" + NL + "\t\t\tPattern p;" + NL + "\t\t\ttry {" + NL + "\t\t\t\tp = Pattern.compile(body);" + NL + "\t\t\t} catch (PatternSyntaxException e) {" + NL + "\t\t\t\tsetStatus(IStatus.ERROR, e.getMessage(), e);" + NL + "\t\t\t\tp = null;" + NL + "\t\t\t}" + NL + "\t\t\tthis.pattern = p;" + NL + "\t\t}" + NL + "" + NL + "\t\t/**" + NL + "\t\t * @generated " + NL + "\t\t */" + NL + "\t\tprotected Object doEvaluate(Object contextInstance, Map env) {" + NL + "\t\t\tif (pattern == null) {" + NL + "\t\t\t\treturn null;" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\tif(context() instanceof EDataType) {" + NL + "\t\t\t\tcontextInstance = EcoreUtil.convertToString((EDataType)context(), contextInstance);" + NL + "\t\t\t}" + NL + "\t\t\t" + NL + "\t\t\tMatcher matcher = this.pattern.matcher(String.valueOf(contextInstance));" + NL + "\t\t\treturn Boolean.valueOf(";
- protected final String TEXT_10 = "matcher.matches());" + NL + "\t\t}" + NL + "\t}" + NL + "}";
- protected final String TEXT_11 = NL;
-
- public String generate(Object argument)
- {
- final StringBuffer stringBuffer = new StringBuffer();
-
-final GenExpressionInterpreter genInterpreter = (GenExpressionInterpreter) ((Object[]) argument)[0];
-final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
-final GenDiagram genDiagram = genInterpreter.getContainer().getEditorGen().getDiagram();
-final String factoryClassName = genInterpreter.getClassName();
-final String abstractExpressionClass = genInterpreter.getContainer().getAbstractExpressionQualifiedClassName();
-final boolean isNegationRegexp = !GenLanguage.REGEXP_LITERAL.equals(genInterpreter.getLanguage());
-
-
-String copyrightText = genDiagram.getEditorGen().getCopyrightText();
-if (copyrightText != null && copyrightText.trim().length() > 0) {
-
- stringBuffer.append(TEXT_1);
- stringBuffer.append(copyrightText.replaceAll("\n", "\n * "));
- stringBuffer.append(TEXT_2);
- }
- importManager.emitPackageStatement(stringBuffer);
- stringBuffer.append(TEXT_3);
- importManager.markImportLocation(stringBuffer);
-importManager.registerInnerClass("Expression");
-
-importManager.addImport("java.util.Collections");
-importManager.addImport("java.util.Map");
-importManager.addImport("java.util.regex.Matcher");
-importManager.addImport("java.util.regex.Pattern");
-importManager.addImport("java.util.regex.PatternSyntaxException");
-importManager.addImport("org.eclipse.core.runtime.IStatus");
-importManager.addImport("org.eclipse.emf.ecore.EClassifier");
-importManager.addImport("org.eclipse.emf.ecore.EDataType");
-importManager.addImport("org.eclipse.emf.ecore.util.EcoreUtil");
-
- stringBuffer.append(TEXT_4);
- stringBuffer.append(factoryClassName);
- stringBuffer.append(TEXT_5);
- stringBuffer.append(factoryClassName);
- stringBuffer.append(TEXT_6);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_7);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_8);
- stringBuffer.append(importManager.getImportedName(abstractExpressionClass));
- stringBuffer.append(TEXT_9);
- stringBuffer.append(isNegationRegexp ? "!" : "");
- stringBuffer.append(TEXT_10);
- importManager.emitSortedImports();
- stringBuffer.append(TEXT_11);
- return stringBuffer.toString();
- }
-}
diff --git a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java
index b5064c1c6..1ac3bac53 100644
--- a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java
+++ b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java
@@ -25,8 +25,6 @@ import org.eclipse.emf.codegen.merge.java.JMerger;
import org.eclipse.emf.codegen.util.CodeGenUtil;
import org.eclipse.emf.common.CommonPlugin;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.gmf.codegen.templates.expressions.OCLExpressionFactoryGenerator;
-import org.eclipse.gmf.codegen.templates.expressions.RegexpExpressionFactoryGenerator;
import org.eclipse.gmf.common.UnexpectedBehaviourException;
import org.eclipse.gmf.internal.codegen.dispatch.CachingEmitterFactory;
import org.eclipse.gmf.internal.codegen.dispatch.EmitterFactory;
@@ -46,8 +44,6 @@ import org.eclipse.gmf.internal.xpand.util.BundleResourceManager;
import org.osgi.framework.Bundle;
/**
- * Provides JET templates.
- *
* @author artem
*/
public class CodegenEmitters {
@@ -64,7 +60,6 @@ public class CodegenEmitters {
}
public CodegenEmitters(boolean usePrecompiled, String templateDirectory, String[] variables, StaticTemplateRegistry registry) {
- initRegistry(registry);
final URL baseURL = getTemplatesBundle().getEntry("/templates/"); //$NON-NLS-1$
final URL dynamicURL = usePrecompiled ? null : getDynamicTemplatesURL(templateDirectory);
@@ -95,18 +90,6 @@ public class CodegenEmitters {
return null;
}
- private static void initRegistry(StaticTemplateRegistry tr) {
- put(tr, "/expressions/OCLExpressionFactory.javajet", OCLExpressionFactoryGenerator.class); //$NON-NLS-1$
- put(tr, "/expressions/RegexpExpressionFactory.javajet", RegexpExpressionFactoryGenerator.class); //$NON-NLS-1$
- }
-
- /**
- * @see #retrieve(Class)
- */
- protected static void put(StaticTemplateRegistry tr, String path, Class<?> precompiledTemplate) {
- tr.put(precompiledTemplate, path, precompiledTemplate);
- }
-
/**
* depends on {@link #put(StaticTemplateRegistry, String, Class) } impl - class object of
* precompiled template serves as a key
@@ -429,11 +412,11 @@ public class CodegenEmitters {
}
public TextEmitter getOCLExpressionFactoryEmitter() throws UnexpectedBehaviourException {
- return retrieve(OCLExpressionFactoryGenerator.class);
+ return getPrimaryEmitter("xpt::expressions::OCLExpressionFactory"); //$NON-NLS-1$
}
public TextEmitter getRegexpExpressionFactoryEmitter() throws UnexpectedBehaviourException {
- return retrieve(RegexpExpressionFactoryGenerator.class);
+ return getPrimaryEmitter("xpt::expressions::RegexpExpressionFactory"); //$NON-NLS-1$
}
// property sheet
diff --git a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java
index e4cf11ad2..2ad569193 100644
--- a/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java
+++ b/plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java
@@ -842,35 +842,31 @@ public class Generator extends GeneratorBase implements Runnable {
}
// expressions
-
+
private void generateExpressionProviders() throws UnexpectedBehaviourException, InterruptedException {
GenExpressionProviderContainer providerContainer = myEditorGen.getExpressionProviders();
doGenerateJavaClass(myEmitters.getAbstractExpressionEmitter(), providerContainer.getAbstractExpressionQualifiedClassName(), myDiagram);
-
for (GenExpressionProviderBase nextProvider : providerContainer.getProviders()) {
- if(nextProvider instanceof GenExpressionInterpreter) {
+ if (nextProvider instanceof GenExpressionInterpreter) {
TextEmitter providerEmitter = null;
- if(GenLanguage.OCL_LITERAL.equals(nextProvider.getLanguage())) {
+ if (GenLanguage.OCL_LITERAL.equals(nextProvider.getLanguage())) {
providerEmitter = myEmitters.getOCLExpressionFactoryEmitter();
- } else if(GenLanguage.REGEXP_LITERAL.equals(nextProvider.getLanguage()) || GenLanguage.NREGEXP_LITERAL.equals(nextProvider.getLanguage())) {
+ } else if (GenLanguage.REGEXP_LITERAL.equals(nextProvider.getLanguage())
+ || GenLanguage.NREGEXP_LITERAL.equals(nextProvider.getLanguage())) {
providerEmitter = myEmitters.getRegexpExpressionFactoryEmitter();
}
GenExpressionInterpreter interpreter = (GenExpressionInterpreter) nextProvider;
- if(providerEmitter != null) {
- internalGenerateJavaClass(
- providerEmitter,
- providerContainer.getExpressionsPackageName(),
- interpreter.getClassName(),
- interpreter);
+ if (providerEmitter != null) {
+ doGenerateJavaClass(providerEmitter, interpreter.getQualifiedClassName(), interpreter);
}
}
}
}
-
+
private void generateShortcutIcon() throws UnexpectedBehaviourException, InterruptedException {
doGenerateBinaryFile(myEmitters.getShortcutImageEmitter(), new Path("icons/shortcut.gif"), null); //$NON-NLS-1$
}
-
+
private void generateGroupIcon(Path groupIconPath) throws InterruptedException, UnexpectedBehaviourException {
doGenerateBinaryFile(myEmitters.getGroupIconEmitter(), groupIconPath, null);
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/common.skeleton b/plugins/org.eclipse.gmf.codegen/templates/common.skeleton
deleted file mode 100644
index e89731b31..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/common.skeleton
+++ /dev/null
@@ -1,109 +0,0 @@
-public class CLASS {
-
- protected final String getFeatureValueGetter(String containerName, GenFeature feature, boolean isContainerEObject, ImportAssistant importManager) {
- StringBuffer result = new StringBuffer();
- if (feature.getGenClass().isExternalInterface()) {
-// Using EMF reflective method to access feature value
- result.append("((");
- if (feature.isListType()) {
- result.append(importManager.getImportedName("java.util.Collection"));
- } else {
- if (feature.getTypeGenClass() != null) {
- result.append(importManager.getImportedName(feature.getTypeGenClass().getQualifiedInterfaceName()));
- } else {
- // EDataType
- result.append(importManager.getImportedName(feature.getTypeGenClassifier().getEcoreClassifier().getInstanceClassName()));
- }
-
- }
- result.append(")");
- if (!isContainerEObject) {
-// Casting container to EObject - ExternalIntarfce could be not an instance of EObject
- result.append("((");
- result.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
- result.append(")");
- }
- result.append(containerName);
- if (!isContainerEObject) {
- result.append(")");
- }
- result.append(".eGet(");
- result.append(importManager.getImportedName(feature.getGenPackage().getQualifiedPackageInterfaceName()));
- result.append(".eINSTANCE.get");
- result.append(feature.getFeatureAccessorName());
- result.append("()))");
- } else {
- if (isContainerEObject) {
-// Casting container to the typed interface
- result.append("((");
- result.append(importManager.getImportedName(feature.getGenClass().getQualifiedInterfaceName()));
- result.append(")");
- }
- result.append(containerName);
- if (isContainerEObject) {
- result.append(")");
- }
- result.append(".");
- result.append(feature.getGetAccessor());
- result.append("()");
- }
- return result.toString();
- }
-
- protected final String getFeatureValueSetterPrefix(String containerName, GenFeature feature, boolean isContainerEObject, ImportAssistant importManager) {
- StringBuffer result = new StringBuffer();
- if (feature.getGenClass().isExternalInterface()) {
-// Using EMF reflective method to access feature value
- if (!isContainerEObject) {
-// Casting container to EObject - ExternalIntarfce could be not an instance of EObject
- result.append("((");
- result.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
- result.append(")");
- }
- result.append(containerName);
- if (!isContainerEObject) {
- result.append(")");
- }
- result.append(".eSet(");
- result.append(importManager.getImportedName(feature.getGenPackage().getQualifiedPackageInterfaceName()));
- result.append(".eINSTANCE.get");
- result.append(feature.getFeatureAccessorName());
- result.append("(), ");
- } else {
- if (isContainerEObject) {
-// Casting container to the typed interface
- result.append("((");
- result.append(importManager.getImportedName(feature.getGenClass().getQualifiedInterfaceName()));
- result.append(")");
- }
- result.append(containerName);
- if (isContainerEObject) {
- result.append(")");
- }
- if (feature.isListType()) {
- result.append(".");
- result.append(feature.getGetAccessor());
- result.append("().add(");
- } else {
- result.append(".set");
- result.append(feature.getAccessorName());
- result.append("(");
- }
- }
- return result.toString();
- }
-
- protected final String getMetaClassAccessor(GenClass genClass, ImportAssistant importManager) {
- StringBuffer buf = new StringBuffer();
- buf.append(importManager.getImportedName(genClass.getGenPackage().getQualifiedPackageInterfaceName()))
- .append(".eINSTANCE.get") //$NON-NLS-1$
- .append(genClass.getName())
- .append("()"); //$NON-NLS-1$
- return buf.toString();
- }
-
- public String generate(Object argument) {
- return "";
- }
-
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/copyright4java.jetinc b/plugins/org.eclipse.gmf.codegen/templates/copyright4java.jetinc
deleted file mode 100644
index 563ce7baa..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/copyright4java.jetinc
+++ /dev/null
@@ -1,8 +0,0 @@
-<%
-String copyrightText = genDiagram.getEditorGen().getCopyrightText();
-if (copyrightText != null && copyrightText.trim().length() > 0) {
-%>
-/*
- * <%=copyrightText.replaceAll("\n", "\n * ")%>
- */
-<%}%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet b/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet
deleted file mode 100644
index 690fc2c35..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/OCLExpressionFactory.javajet
+++ /dev/null
@@ -1,204 +0,0 @@
-<%@ jet package="org.eclipse.gmf.codegen.templates.expressions" class="OCLExpressionFactoryGenerator"
- imports="org.eclipse.gmf.codegen.gmfgen.* org.eclipse.gmf.common.codegen.*"%>
-<%
-final GenExpressionInterpreter genInterpreter = (GenExpressionInterpreter) ((Object[]) argument)[0];
-final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
-final GenDiagram genDiagram = genInterpreter.getContainer().getEditorGen().getDiagram();
-final String factoryClassName = genInterpreter.getClassName();
-final String abstractExpressionClass = genInterpreter.getContainer().getAbstractExpressionQualifiedClassName();
-%>
-<%@ include file="../copyright4java.jetinc"%>
-<%importManager.emitPackageStatement(stringBuffer);%>
-
-<%importManager.markImportLocation(stringBuffer);%>
-
-<%
-importManager.registerInnerClass("Expression");
-importManager.addImport("java.util.Collections");
-importManager.addImport("java.util.Iterator");
-importManager.addImport("java.util.Map");
-importManager.addImport("java.lang.ref.WeakReference");
-importManager.addImport("org.eclipse.core.runtime.IStatus");
-importManager.addImport("org.eclipse.emf.ecore.EClassifier");
-importManager.addImport("org.eclipse.emf.ecore.EEnum");
-importManager.addImport("org.eclipse.emf.ecore.EEnumLiteral");
-importManager.addImport("org.eclipse.emf.ecore.ETypedElement");
-
-importManager.addImport("org.eclipse.ocl.Environment");
-importManager.addImport("org.eclipse.ocl.EvaluationEnvironment");
-importManager.addImport("org.eclipse.ocl.ParserException");
-importManager.addImport("org.eclipse.ocl.Query");
-importManager.addImport("org.eclipse.ocl.ecore.EcoreFactory");
-importManager.addImport("org.eclipse.ocl.ecore.OCL");
-importManager.addImport("org.eclipse.ocl.expressions.OCLExpression");
-importManager.addImport("org.eclipse.ocl.expressions.OperationCallExp");
-importManager.addImport("org.eclipse.ocl.expressions.Variable");
-importManager.addImport("org.eclipse.ocl.helper.OCLHelper");
-importManager.addImport("org.eclipse.ocl.utilities.AbstractVisitor");
-importManager.addImport("org.eclipse.ocl.utilities.PredefinedType");
-
-%>
-
-/**
- * @generated
- */
-public class <%=factoryClassName%> {
-
- <%@ include file="OCLExpressionFactory_additions.jetinc" fail="silent"%>
-
- /**
- * @generated
- */
- private <%=factoryClassName%>() {
- }
-
- /**
- * @generated
- */
- public static <%=importManager.getImportedName(abstractExpressionClass)%> getExpression(String body, EClassifier context, Map environment) {
- return new Expression(body, context, environment);
- }
-
- /**
- * @generated
- */
- public static <%=importManager.getImportedName(abstractExpressionClass)%> getExpression(String body, EClassifier context) {
- return getExpression(body, context, Collections.EMPTY_MAP);
- }
-
- /**
- * @generated
- */
- private static class Expression extends <%=importManager.getImportedName(abstractExpressionClass)%> {
- /**
- * @generated
- */
- private WeakReference queryRef;
-
- /**
- * @generated
- */
- private final OCL oclInstance;
-
- /**
- * @generated
- */
- public Expression(String body, EClassifier context, Map environment) {
- super(body, context);
- oclInstance = OCL.newInstance();
- initCustomEnv(oclInstance.getEnvironment(), environment);
- }
-
- /**
- * @generated
- */
- protected Query getQuery() {
- Query oclQuery = null;
- if(this.queryRef != null) {
- oclQuery = (Query)this.queryRef.get();
- }
- if(oclQuery == null) {
- OCLHelper oclHelper = oclInstance.createOCLHelper();
- oclHelper.setContext(context());
- try {
- OCLExpression oclExpression = oclHelper.createQuery(body());
- oclQuery = oclInstance.createQuery(oclExpression);
- this.queryRef = new WeakReference(oclQuery);
- setStatus(IStatus.OK, null, null);
- } catch (ParserException e) {
- setStatus(IStatus.ERROR, e.getMessage(), e);
- }
- }
- return oclQuery;
- }
-
- /**
- * @generated
- */
- protected Object doEvaluate(Object context, Map env) {
- Query oclQuery = getQuery();
- if (oclQuery == null) {
- return null;
- }
- EvaluationEnvironment evalEnv = oclQuery.getEvaluationEnvironment();
- // init environment
- for (Iterator it = env.entrySet().iterator(); it.hasNext();) {
- Map.Entry nextEntry = (Map.Entry) it.next();
- evalEnv.replace((String)nextEntry.getKey(), nextEntry.getValue());
- }
-
- try {
- initExtentMap(context);
- Object result = oclQuery.evaluate(context);
- return (result != oclInstance.getEnvironment().getOCLStandardLibrary().getOclInvalid()) ? result : null;
- } finally {
- evalEnv.clear();
- oclQuery.getExtentMap().clear();
- }
- }
-
- /**
- * @generated
- */
- protected Object performCast(Object value, ETypedElement targetType) {
- if (targetType.getEType() instanceof EEnum) {
- if(value instanceof EEnumLiteral) {
- EEnumLiteral literal = (EEnumLiteral)value;
- return (literal.getInstance() != null) ? literal.getInstance() : literal;
- }
- }
- return super.performCast(value, targetType);
- }
-
- /**
- * @generated
- */
- private void initExtentMap(Object context) {
- if (!getStatus().isOK() || context == null) {
- return;
- }
- final Query queryToInit = getQuery();
- final Object extentContext = context;
-
- queryToInit.getExtentMap().clear();
- if (queryToInit.queryText() != null && queryToInit.queryText().indexOf(PredefinedType.ALL_INSTANCES_NAME) >= 0) {
- AbstractVisitor visitior = new AbstractVisitor() {
- private boolean usesAllInstances = false;
-
- public Object visitOperationCallExp(OperationCallExp oc) {
- if(!usesAllInstances) {
- usesAllInstances = PredefinedType.ALL_INSTANCES == oc.getOperationCode();
- if(usesAllInstances) {
- queryToInit.getExtentMap().putAll(oclInstance.getEvaluationEnvironment().createExtentMap(extentContext));
- }
- }
- return super.visitOperationCallExp(oc);
- }
- };
- queryToInit.getExpression().accept(visitior);
- }
- }
-
- /**
- * @generated
- */
- private static void initCustomEnv(Environment ecoreEnv, Map environment) {
- for (Iterator it = environment.keySet().iterator(); it.hasNext();) {
- String varName = (String)it.next();
- EClassifier varType = (EClassifier) environment.get(varName);
- ecoreEnv.addElement(varName, createVar(ecoreEnv, varName, varType), false);
- }
- }
-
- /**
- * @generated
- */
- private static Variable createVar(Environment ecoreEnv, String name, EClassifier type) {
- Variable var = EcoreFactory.eINSTANCE.createVariable(); // or ecoreEnv.getOCLFactory().createVariable()?
- var.setName(name);
- var.setType(ecoreEnv.getUMLReflection().getOCLType(type));
- return var;
- }
- }
-}
-<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/RegexpExpressionFactory.javajet b/plugins/org.eclipse.gmf.codegen/templates/expressions/RegexpExpressionFactory.javajet
deleted file mode 100644
index 136518052..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/RegexpExpressionFactory.javajet
+++ /dev/null
@@ -1,95 +0,0 @@
-<%@ jet package="org.eclipse.gmf.codegen.templates.expressions" class="RegexpExpressionFactoryGenerator"
- imports="org.eclipse.gmf.codegen.gmfgen.* org.eclipse.gmf.common.codegen.*"%>
-<%
-final GenExpressionInterpreter genInterpreter = (GenExpressionInterpreter) ((Object[]) argument)[0];
-final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
-final GenDiagram genDiagram = genInterpreter.getContainer().getEditorGen().getDiagram();
-final String factoryClassName = genInterpreter.getClassName();
-final String abstractExpressionClass = genInterpreter.getContainer().getAbstractExpressionQualifiedClassName();
-final boolean isNegationRegexp = !GenLanguage.REGEXP_LITERAL.equals(genInterpreter.getLanguage());
-%>
-<%@ include file="../copyright4java.jetinc"%>
-<%importManager.emitPackageStatement(stringBuffer);%>
-
-<%importManager.markImportLocation(stringBuffer);
-importManager.registerInnerClass("Expression");
-
-importManager.addImport("java.util.Collections");
-importManager.addImport("java.util.Map");
-importManager.addImport("java.util.regex.Matcher");
-importManager.addImport("java.util.regex.Pattern");
-importManager.addImport("java.util.regex.PatternSyntaxException");
-importManager.addImport("org.eclipse.core.runtime.IStatus");
-importManager.addImport("org.eclipse.emf.ecore.EClassifier");
-importManager.addImport("org.eclipse.emf.ecore.EDataType");
-importManager.addImport("org.eclipse.emf.ecore.util.EcoreUtil");
-%>
-
-/**
- * @generated
- */
-public class <%=factoryClassName%> {
- /**
- * @generated
- */
- private <%=factoryClassName%>() {
- }
-
- /**
- * @generated
- */
- public static <%=importManager.getImportedName(abstractExpressionClass)%> getExpression(String body,
- EClassifier context, Map environment) {
- return new Expression(body, context, environment);
- }
-
- /**
- * @generated
- */
- public static <%=importManager.getImportedName(abstractExpressionClass)%> getExpression(String body,
- EClassifier context) {
- return getExpression(body, context, Collections.EMPTY_MAP);
- }
-
- /**
- * @generated
- */
- private static class Expression extends <%=importManager.getImportedName(abstractExpressionClass)%> {
- /**
- * @generated
- */
- private final Pattern pattern;
-
- /**
- * @generated
- */
- public Expression(String body, EClassifier context, Map environment) {
- super(body, context);
- Pattern p;
- try {
- p = Pattern.compile(body);
- } catch (PatternSyntaxException e) {
- setStatus(IStatus.ERROR, e.getMessage(), e);
- p = null;
- }
- this.pattern = p;
- }
-
- /**
- * @generated
- */
- protected Object doEvaluate(Object contextInstance, Map env) {
- if (pattern == null) {
- return null;
- }
-
- if(context() instanceof EDataType) {
- contextInstance = EcoreUtil.convertToString((EDataType)context(), contextInstance);
- }
-
- Matcher matcher = this.pattern.matcher(String.valueOf(contextInstance));
- return Boolean.valueOf(<%=isNegationRegexp ? "!" : ""%>matcher.matches());
- }
- }
-}
-<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/getExpression.jetinc b/plugins/org.eclipse.gmf.codegen/templates/expressions/getExpression.jetinc
deleted file mode 100644
index e9096fea0..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/getExpression.jetinc
+++ /dev/null
@@ -1,49 +0,0 @@
-<%
-{ /*begin the scope*/
-/*
-ValueExpression __genValueExpression;
-GenClassifier __genExprContext
-java.util.Map __exprEnvVariables
-String __outEnvVarName;
-String __javaOperationContainer;
-*/
- org.eclipse.gmf.codegen.gmfgen.GenExpressionProviderBase __genExprProvider = (genDiagram.getEditorGen().getExpressionProviders() != null) ? genDiagram.getEditorGen().getExpressionProviders().getProvider(__genValueExpression) : null;
- String __ctxEClassifierAccess = importManager.getImportedName(__genExprContext.getGenPackage().getQualifiedPackageInterfaceName()) + ".eINSTANCE.get" + __genExprContext.getClassifierAccessorName()+"()";
- String __importedAbstractClass = __genExprProvider != null ? importManager.getImportedName(__genExprProvider.getContainer().getAbstractExpressionQualifiedClassName()) : null;
-
- if(__genExprProvider == null || __importedAbstractClass == null) {
-%>null<%
- } else if(__genExprProvider instanceof org.eclipse.gmf.codegen.gmfgen.GenExpressionInterpreter) {
- org.eclipse.gmf.codegen.gmfgen.GenExpressionInterpreter interpreter = (org.eclipse.gmf.codegen.gmfgen.GenExpressionInterpreter)__genExprProvider;
- String __expressionAccessor = interpreter.getExpressionAccessor(__genValueExpression);
- String providerImportedClass = importManager.getImportedName(interpreter.getQualifiedClassName());
- if(!__exprEnvVariables.isEmpty()) {
-%><%=providerImportedClass%>.<%=__expressionAccessor%>(<%=__genValueExpression.getBodyString()%>, //$NON-NLS-1$
- <%=__ctxEClassifierAccess%>, <%=__outEnvVarName%>)<%
- } else {
-%><%=providerImportedClass%>.<%=__expressionAccessor%>(<%=__genValueExpression.getBodyString()%>, //$NON-NLS-1$
- <%=__ctxEClassifierAccess%>)<%
- }
- } else if(__genExprProvider instanceof org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider) { /*inlined java expression adapter*/
- String evalCtxQualifiedName = __genExprProvider.getQualifiedInstanceClassName(__genExprContext);
- String __exprJavaOperName = ((org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider)__genExprProvider).getOperationName(__genValueExpression);
-
-%>new <%=__importedAbstractClass%>(<%=__ctxEClassifierAccess%>) {
- protected Object doEvaluate(Object context, <%=importManager.getImportedName("java.util.Map")%> env) {
- <%=importManager.getImportedName(evalCtxQualifiedName)%> self = (<%=importManager.getImportedName(evalCtxQualifiedName)%>)context;
-<%
- for(java.util.Iterator envVarIt = __exprEnvVariables.keySet().iterator(); envVarIt.hasNext();) {
- String nextVariableName = (String)envVarIt.next();
- org.eclipse.emf.codegen.ecore.genmodel.GenClassifier nextVariableType = (org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)__exprEnvVariables.get(nextVariableName);
- String qualifiedTypeName = __genExprProvider.getQualifiedInstanceClassName(nextVariableType);
-%>
- <%=importManager.getImportedName(qualifiedTypeName)%> <%=nextVariableName%> = (<%=importManager.getImportedName(qualifiedTypeName)%>)env.get("<%=nextVariableName%>"); //$NON-NLS-1$
-<% } %>
- return <%
- if(__javaOperationContainer != null && __javaOperationContainer.length() > 0) { %><%=__javaOperationContainer%>.<%
- } %><%=__exprJavaOperName%>(self<%
- for(java.util.Iterator envVarIt = __exprEnvVariables.keySet().iterator(); envVarIt.hasNext();){%>, <%=(String)envVarIt.next()%><%}%>);
- }
-}
-<%}%>
-<%} /*end of scope*/%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/initEnv.jetinc b/plugins/org.eclipse.gmf.codegen/templates/expressions/initEnv.jetinc
deleted file mode 100644
index 1e1e716d6..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/initEnv.jetinc
+++ /dev/null
@@ -1,26 +0,0 @@
-<%
-{ /*begin the scope*/
-/*
-java.util.Map __exprEnvVariables;
-String __outEnvVarName;
-ValueExpression __genValueExpression;
-*/
-if(!__exprEnvVariables.isEmpty() && genDiagram.getEditorGen().getExpressionProviders() != null &&
- genDiagram.getEditorGen().getExpressionProviders().getProvider(__genValueExpression)
- instanceof org.eclipse.gmf.codegen.gmfgen.GenExpressionInterpreter) {
-%>
-<%=importManager.getImportedName("java.util.Map")%> <%=__outEnvVarName%> = new <%=importManager.getImportedName("java.util.HashMap")%>(3);
-<%
- for(java.util.Iterator envVarIt = __exprEnvVariables.keySet().iterator(); envVarIt.hasNext();) {
- String nextVariableName = (String)envVarIt.next();
- org.eclipse.emf.codegen.ecore.genmodel.GenClassifier nextVariableType = (org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)__exprEnvVariables.get(nextVariableName);
- String varTypeEClassifierAccess = nextVariableType.getGenPackage().getQualifiedPackageInterfaceName() + ".eINSTANCE.get" + nextVariableType.getClassifierAccessorName()+"()";
-
-%><%=__outEnvVarName%>.put("<%=nextVariableName%>", <%=varTypeEClassifierAccess%>); //$NON-NLS-1$
-<%
- }
-}
-%>
-<%
-} /*end the scope*/
-%> \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/expressions/javaExpressionOperation.jetinc b/plugins/org.eclipse.gmf.codegen/templates/expressions/javaExpressionOperation.jetinc
deleted file mode 100644
index 667ec744f..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/expressions/javaExpressionOperation.jetinc
+++ /dev/null
@@ -1,40 +0,0 @@
-<%
-/*
-ValueExpression __genValueExpression
-java.util.Map __exprEnvVariables
-GenClassifier __genExprContext
-GenClassifier || String/qualifiedClassName/__genExprResultType
-*/
-org.eclipse.gmf.codegen.gmfgen.GenExpressionProviderBase __genExprProvider = (genDiagram.getEditorGen().getExpressionProviders() != null) ? genDiagram.getEditorGen().getExpressionProviders().getProvider(__genValueExpression) : null;
-if(__genExprProvider instanceof org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider) {
- String __importedAbstractExpr = importManager.getImportedName(__genExprProvider.getContainer().getAbstractExpressionQualifiedClassName());
- String evalCtxQualifiedName = __genExprProvider.getQualifiedInstanceClassName(__genExprContext);
- // support GenClassifier and also String based qualified java class name
- Object __genExprResultTypeObj = __genExprResultType;
- String __exprResultTypeQualifiedName = null;
- if(__genExprResultTypeObj instanceof String)
- __exprResultTypeQualifiedName = (String)__genExprResultTypeObj;
- else if(__genExprResultTypeObj instanceof org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)
- __exprResultTypeQualifiedName = __genExprProvider.getQualifiedInstanceClassName((org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)__genExprResultTypeObj);
- String __exprJavaOperName = ((org.eclipse.gmf.codegen.gmfgen.GenJavaExpressionProvider)__genExprProvider).getOperationName(__genValueExpression);
-%>
-/**
- * @generated
- */
-private static <%=importManager.getImportedName(__exprResultTypeQualifiedName)%> <%=__exprJavaOperName%>(<%=importManager.getImportedName(evalCtxQualifiedName)%> self<%
- for(java.util.Iterator envVarIt = __exprEnvVariables.keySet().iterator(); envVarIt.hasNext();) {
- String __nextVarName = (String)envVarIt.next();
- org.eclipse.emf.codegen.ecore.genmodel.GenClassifier nextVariableType = (org.eclipse.emf.codegen.ecore.genmodel.GenClassifier)__exprEnvVariables.get(__nextVarName);
- String qualifiedTypeName = __genExprProvider.getQualifiedInstanceClassName(nextVariableType);
-
- %>, <%=importManager.getImportedName(qualifiedTypeName)%> <%=__nextVarName%>
-<% }
-%>) {
- // TODO: implement this method
- // Ensure that you remove @generated or mark it @generated NOT
-
- throw new <%=__importedAbstractExpr%>.NoImplException("No user java implementation provided in '<%=__exprJavaOperName%>' operation"); //$NON-NLS-1$
-}
-<%
-} /* end of GenJavaExpressionProvider */
-%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
new file mode 100755
index 000000000..30b74daa3
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2007 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dmitry Stadnik (Borland) - initial API and implementation
+ */
+
+«IMPORT "http://www.eclipse.org/gmf/2006/GenModel"»
+
+«DEFINE OCLExpressionFactory FOR gmfgen::GenExpressionInterpreter-»
+«EXPAND xpt::Common::copyright FOR container.editorGen-»
+package «container.expressionsPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «className» {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «className»() {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
+ String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
+ return new Expression(body, context, environment);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
+ String body, org.eclipse.emf.ecore.EClassifier context) {
+ return getExpression(body, context, java.util.Collections.EMPTY_MAP);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class Expression extends «container.getAbstractExpressionQualifiedClassName()» {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private java.lang.ref.WeakReference queryRef;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final org.eclipse.ocl.ecore.OCL oclInstance;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public Expression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
+ super(body, context);
+ oclInstance = org.eclipse.ocl.ecore.OCL.newInstance();
+ initCustomEnv(oclInstance.getEnvironment(), environment);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected org.eclipse.ocl.Query getQuery() {
+ org.eclipse.ocl.Query oclQuery = null;
+ if (this.queryRef != null) {
+ oclQuery = (org.eclipse.ocl.Query) this.queryRef.get();
+ }
+ if (oclQuery == null) {
+ org.eclipse.ocl.helper.OCLHelper oclHelper = oclInstance.createOCLHelper();
+ oclHelper.setContext(context());
+ try {
+ org.eclipse.ocl.expressions.OCLExpression oclExpression = oclHelper.createQuery(body());
+ oclQuery = oclInstance.createQuery(oclExpression);
+ this.queryRef = new java.lang.ref.WeakReference(oclQuery);
+ setStatus(org.eclipse.core.runtime.IStatus.OK, null, null);
+ } catch (org.eclipse.ocl.ParserException e) {
+ setStatus(org.eclipse.core.runtime.IStatus.ERROR, e.getMessage(), e);
+ }
+ }
+ return oclQuery;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object doEvaluate(Object context, java.util.Map env) {
+ org.eclipse.ocl.Query oclQuery = getQuery();
+ if (oclQuery == null) {
+ return null;
+ }
+ org.eclipse.ocl.EvaluationEnvironment evalEnv = oclQuery.getEvaluationEnvironment();
+ // init environment
+ for (java.util.Iterator it = env.entrySet().iterator(); it.hasNext();) {
+ java.util.Map.Entry nextEntry = (java.util.Map.Entry) it.next();
+ evalEnv.replace((String) nextEntry.getKey(), nextEntry.getValue());
+ }
+ try {
+ initExtentMap(context);
+ Object result = oclQuery.evaluate(context);
+ return (result != oclInstance.getEnvironment().getOCLStandardLibrary().getOclInvalid()) ? result : null;
+ } finally {
+ evalEnv.clear();
+ oclQuery.getExtentMap().clear();
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object performCast(Object value, org.eclipse.emf.ecore.ETypedElement targetType) {
+ if (targetType.getEType() instanceof org.eclipse.emf.ecore.EEnum) {
+ if (value instanceof org.eclipse.emf.ecore.EEnumLiteral) {
+ org.eclipse.emf.ecore.EEnumLiteral literal = (org.eclipse.emf.ecore.EEnumLiteral) value;
+ return (literal.getInstance() != null) ? literal.getInstance() : literal;
+ }
+ }
+ return super.performCast(value, targetType);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private void initExtentMap(Object context) {
+ if (!getStatus().isOK() || context == null) {
+ return;
+ }
+ final org.eclipse.ocl.Query queryToInit = getQuery();
+ final Object extentContext = context;
+ queryToInit.getExtentMap().clear();
+ if (queryToInit.queryText() != null
+ && queryToInit.queryText().indexOf(org.eclipse.ocl.utilities.PredefinedType.ALL_INSTANCES_NAME) >= 0) {
+ org.eclipse.ocl.utilities.AbstractVisitor visitior = new org.eclipse.ocl.utilities.AbstractVisitor() {
+
+ private boolean usesAllInstances = false;
+
+ public Object visitOperationCallExp(org.eclipse.ocl.expressions.OperationCallExp oc) {
+ if (!usesAllInstances) {
+ usesAllInstances = org.eclipse.ocl.utilities.PredefinedType.ALL_INSTANCES == oc.getOperationCode();
+ if (usesAllInstances) {
+ queryToInit.getExtentMap().putAll(
+ oclInstance.getEvaluationEnvironment().createExtentMap(extentContext));
+ }
+ }
+ return super.visitOperationCallExp(oc);
+ }
+ };
+ queryToInit.getExpression().accept(visitior);
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static void initCustomEnv(org.eclipse.ocl.Environment ecoreEnv, java.util.Map environment) {
+ for (java.util.Iterator it = environment.keySet().iterator(); it.hasNext();) {
+ String varName = (String) it.next();
+ org.eclipse.emf.ecore.EClassifier varType = (org.eclipse.emf.ecore.EClassifier) environment.get(varName);
+ ecoreEnv.addElement(varName, createVar(ecoreEnv, varName, varType), false);
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static org.eclipse.ocl.expressions.Variable createVar(
+ org.eclipse.ocl.Environment ecoreEnv, String name, org.eclipse.emf.ecore.EClassifier type) {
+ org.eclipse.ocl.expressions.Variable var = org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createVariable();
+ var.setName(name);
+ var.setType(ecoreEnv.getUMLReflection().getOCLType(type));
+ return var;
+ }
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
new file mode 100755
index 000000000..1e1d9ffe1
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2007 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Dmitry Stadnik (Borland) - initial API and implementation
+ */
+
+«IMPORT "http://www.eclipse.org/gmf/2006/GenModel"»
+
+«DEFINE RegexpExpressionFactory FOR gmfgen::GenExpressionInterpreter-»
+«EXPAND xpt::Common::copyright FOR container.editorGen-»
+package «container.expressionsPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public class «className» {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «className»() {
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
+ String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
+ return new Expression(body, context, environment);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
+ String body, org.eclipse.emf.ecore.EClassifier context) {
+ return getExpression(body, context, java.util.Collections.EMPTY_MAP);
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static class Expression extends «container.getAbstractExpressionQualifiedClassName()» {
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final java.util.regex.Pattern pattern;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public Expression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
+ super(body, context);
+ java.util.regex.Pattern p;
+ try {
+ p = java.util.regex.Pattern.compile(body);
+ } catch (java.util.regex.PatternSyntaxException e) {
+ setStatus(org.eclipse.core.runtime.IStatus.ERROR, e.getMessage(), e);
+ p = null;
+ }
+ this.pattern = p;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected Object doEvaluate(Object contextInstance, java.util.Map env) {
+ if (pattern == null) {
+ return null;
+ }
+ if (context() instanceof org.eclipse.emf.ecore.EDataType) {
+ contextInstance = org.eclipse.emf.ecore.util.EcoreUtil.convertToString(
+ (org.eclipse.emf.ecore.EDataType) context(), contextInstance);
+ }
+ java.util.regex.Matcher matcher = this.pattern.matcher(String.valueOf(contextInstance));
+ return Boolean.valueOf(«IF language.literal == gmfgen::GenLanguage::nregexp.literal»!«ENDIF»matcher.matches());
+ }
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»

Back to the top