Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/AbstractExpression.xpt145
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/OCLExpressionFactory.xpt148
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/RegexpExpressionFactory.xpt74
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/ValueExpression.qvto15
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/getExpression.xpt19
5 files changed, 401 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/AbstractExpression.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/AbstractExpression.xpt
new file mode 100644
index 000000000..47f7a0866
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/AbstractExpression.xpt
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2007, 2008 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/2008/GenModel'»
+
+«DEFINE AbstractExpression FOR gmfgen::GenDiagram-»
+«EXPAND xpt::Common::copyright FOR editorGen-»
+package «editorGen.expressionProviders.expressionsPackageName»;
+
+«EXPAND xpt::Common::generatedClassComment»
+public abstract class «editorGen.expressionProviders.abstractExpressionClassName» «EXPAND supertypes»{
+
+«EXPAND status-»
+
+«EXPAND body-»
+
+«EXPAND context-»
+
+«EXPAND ctors-»
+
+«EXPAND evaluate-»
+
+«EXPAND performCast-»
+
+«EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE supertypes FOR gmfgen::GenDiagram»«ENDDEFINE»
+«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
+
+«DEFINE status FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private org.eclipse.core.runtime.IStatus status = org.eclipse.core.runtime.Status.OK_STATUS;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected void setStatus(int severity, String message, Throwable throwable) {
+ String pluginID = «editorGen.plugin.getActivatorQualifiedClassName()».ID;
+ this.status = new org.eclipse.core.runtime.Status(severity, pluginID, -1, (message != null) ? message : "", throwable);«EXPAND xpt::Common::nonNLS»
+ if(!this.status.isOK()) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Expression problem:" + message + "body:"+ body(), throwable);«EXPAND xpt::Common::nonNLS»«EXPAND xpt::Common::nonNLS(2)»
+ }
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.core.runtime.IStatus getStatus() {
+ return status;
+ }
+«ENDDEFINE»
+
+«DEFINE body FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final String myBody;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public String body() {
+ return myBody;
+ }
+«ENDDEFINE»
+
+«DEFINE context FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final org.eclipse.emf.ecore.EClassifier myContext;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public org.eclipse.emf.ecore.EClassifier context() {
+ return myContext;
+ }
+«ENDDEFINE»
+
+«DEFINE ctors FOR gmfgen::GenDiagram-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected «editorGen.expressionProviders.abstractExpressionClassName»(String body, org.eclipse.emf.ecore.EClassifier context) {
+ myBody = body;
+ myContext = context;
+ }
+«ENDDEFINE»
+
+«DEFINE evaluate FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected abstract Object doEvaluate(Object context, java.util.Map env);
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public Object evaluate(Object context) {
+ return evaluate(context, java.util.Collections.EMPTY_MAP);
+ }
+
+«EXPAND xpt::Common::generatedMemberComment»
+ public Object evaluate(Object context, java.util.Map env) {
+ if(context().isInstance(context)) {
+ try {
+ return doEvaluate(context, env);
+ } catch(Exception e) {
+ «editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Expression evaluation failure: " + body(), e);«EXPAND xpt::Common::nonNLS»
+ }
+ }
+ return null;
+ }
+«ENDDEFINE»
+
+«DEFINE performCast FOR gmfgen::GenDiagram-»
+ «EXPAND xpt::Common::generatedMemberComment('Expression may return number value which is not directly compatible with feature type (e.g. Double when Integer is expected), or EEnumLiteral meta-object when literal instance is expected')»
+ public static Object performCast(Object value, org.eclipse.emf.ecore.EDataType targetType) {
+ if (targetType 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;
+ }
+ }
+ if (false == value instanceof Number || targetType == null || targetType.getInstanceClass() == null) {
+ return value;
+ }
+ Class targetClass = targetType.getInstanceClass();
+ Number num = (Number) value;
+ Class valClass = value.getClass();
+ Class targetWrapperClass = targetClass;
+ if (targetClass.isPrimitive()) {
+ targetWrapperClass = org.eclipse.emf.ecore.util.EcoreUtil.wrapperClassFor(targetClass);
+ }
+ if (valClass.equals(targetWrapperClass)) {
+ return value;
+ }
+ if (Number.class.isAssignableFrom(targetWrapperClass)) {
+ if (targetWrapperClass.equals(Byte.class)) return new Byte(num.byteValue());
+ if (targetWrapperClass.equals(Integer.class)) return new Integer(num.intValue());
+ if (targetWrapperClass.equals(Short.class)) return new Short(num.shortValue());
+ if (targetWrapperClass.equals(Long.class)) return new Long(num.longValue());
+ if (targetWrapperClass.equals(java.math.BigInteger.class)) return java.math.BigInteger.valueOf(num.longValue());
+ if (targetWrapperClass.equals(Float.class)) return new Float(num.floatValue());
+ if (targetWrapperClass.equals(Double.class)) return new Double(num.doubleValue());
+ if (targetWrapperClass.equals(java.math.BigDecimal.class)) return new java.math.BigDecimal(num.doubleValue());
+ }
+ return value;
+ }
+«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/OCLExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/OCLExpressionFactory.xpt
new file mode 100644
index 000000000..5d96611e0
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/OCLExpressionFactory.xpt
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2007, 2008 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/2008/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»
+ 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.migrated/xpt/expressions/RegexpExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/RegexpExpressionFactory.xpt
new file mode 100644
index 000000000..42c3c6f16
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/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/2008/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 = gmfgen::GenLanguage::nregexp»!«ENDIF»matcher.matches());
+ }
+ }
+ «EXPAND additions-»
+}
+«ENDDEFINE»
+
+«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/ValueExpression.qvto b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/ValueExpression.qvto
new file mode 100644
index 000000000..15a65f053
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/ValueExpression.qvto
@@ -0,0 +1,15 @@
+modeltype genModel uses "http://www.eclipse.org/gmf/2008/GenModel";
+
+library ValueExpression;
+
+helper constraintFieldName(cb : genModel::GenCommonBase) : String {
+ return cb.getUniqueIdentifier() + '_Constraint'
+}
+
+helper sourceConstraintFieldName(l : genModel::GenLink) : String {
+ return l.getUniqueIdentifier() + '_SourceExpression'
+}
+
+helper targetConstraintFieldName(l : genModel::GenLink) : String {
+ return l.getUniqueIdentifier() + '_TargetExpression'
+}
diff --git a/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/getExpression.xpt b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/getExpression.xpt
new file mode 100644
index 000000000..abb1d699a
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.migrated/xpt/expressions/getExpression.xpt
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2007, 2008 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:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ */
+
+«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
+
+«DEFINE getExpression(valueExpr : gmfgen::ValueExpression, context : genmodel::GenClassifier) FOR gmfgen::GenExpressionInterpreter-»
+«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«valueExpr.getBodyString()», «EXPAND MetaModel::MetaClass FOR context»)«-»
+«ENDDEFINE» \ No newline at end of file

Back to the top