Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2010-04-28 16:31:30 -0400
committeratikhomirov2010-04-28 16:31:30 -0400
commitcfe2f8ad3d2760e9a3e5ae575e6293492e7f303e (patch)
treee628d387c9d31c405b4ebf816c4aa185c7e2c069
parent8a91e9f2648488e6caa9b16e34b647260afaa4cd (diff)
downloadorg.eclipse.gmf-tooling-cfe2f8ad3d2760e9a3e5ae575e6293492e7f303e.tar.gz
org.eclipse.gmf-tooling-cfe2f8ad3d2760e9a3e5ae575e6293492e7f303e.tar.xz
org.eclipse.gmf-tooling-cfe2f8ad3d2760e9a3e5ae575e6293492e7f303e.zip
[231330] reduce use of static fields - completely moved expression handling to originating factory.
LinkConstraints refactored to give access to present link instance in canExist method
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt10
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt31
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt82
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt17
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto26
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt6
6 files changed, 66 insertions, 106 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
index d43728fed..b096e0f72 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/CreateLinkUtils.xpt
@@ -47,17 +47,11 @@
return false;
}
«ENDIF-»
- return «EXPAND validatorInvocation FOR link»(«IF hasContainerOtherThanSource(self)»getContainer(), «ENDIF»getSource(), getTarget());
+ return «EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canCreateCall(link, 'getContainer()', 'getSource()', 'getTarget()')»;
«ENDDEFINE»
«DEFINE canCreateElement(link : gmfgen::GenLink) FOR gmfgen::FeatureLinkModelFacet-»
- return «EXPAND validatorInvocation FOR link»(getSource(), getTarget());
-«ENDDEFINE»
-
-// FIXME In fact, BaseItemSemanticEditPolicy knows what arguments and in which order should be passed to the canCreate method,
-// hence, need to refactor this invocation to delegate complete call to the policy.
-«DEFINE validatorInvocation FOR gmfgen::GenLink-»
-«EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canCreateCall-»
+ return «EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canCreateCall(link, 'getSource()', 'getTarget()')»;
«ENDDEFINE»
«REM»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
index 0fbc17922..59eb97381 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/commands/ReorientLinkUtils.xpt
@@ -124,8 +124,7 @@
}
«ENDDEFINE»
-«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet-»
-«ENDDEFINE»
+«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet»«ENDDEFINE»
«DEFINE checkSourceRequestValidity(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet-»
if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getSourceType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getSourceType()»)) {
@@ -142,11 +141,10 @@
if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getSourceType()»)) {
return false;
}
- return «EXPAND checkLinkConstraintInvocation FOR link»(getNewSource(), getOldTarget());
+ return «EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canExistCall(link, 'getNewSource()', 'getOldTarget()')»;
«ENDDEFINE»
-«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet-»
-«ENDDEFINE»
+«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::LinkModelFacet»«ENDDEFINE»
«DEFINE checkTargetRequestValidity(link : gmfgen::GenLink) FOR gmfgen::TypeLinkModelFacet-»
if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getTargetType()»)) {
@@ -167,7 +165,7 @@
if (!(«EXPAND MetaModel::IsInstance('oldEnd') FOR getTargetType()» && «EXPAND MetaModel::IsInstance('newEnd') FOR getTargetType()»)) {
return false;
}
- return «EXPAND checkLinkConstraintInvocation FOR link»(getOldSource(), getNewTarget());
+ return «EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canExistCall(link, 'getOldSource()', 'getNewTarget()')»;
«ENDDEFINE»
«DEFINE extractFeatureWithCheck(containerVar : String, containerMetaClass : genmodel::GenClass, _var : String, varMetaClass : genmodel::GenClass) FOR genmodel::GenFeature-»
@@ -182,20 +180,13 @@
«ENDDEFINE»
«DEFINE checkLinkConstraint(link : gmfgen::GenLink, sourceVar : String, targetVar : String) FOR gmfgen::TypeLinkModelFacet-»
- «IF hasContainerOtherThanSource(self)-»
- if (!(«EXPAND MetaModel::IsContainerInstance('getLink()', metaClass) FOR containmentMetaFeature.genClass»)) {
- return false;
- }
- «EXPAND MetaModel::DeclareAndAssignContainer('container', 'getLink()', metaClass) FOR containmentMetaFeature.genClass»
- return «EXPAND checkLinkConstraintInvocation FOR link»(container, «sourceVar», «targetVar»);
- «ELSE-»
- return «EXPAND checkLinkConstraintInvocation FOR link»(«sourceVar», «targetVar»);
- «ENDIF-»
-«ENDDEFINE»
-
-// FIXME refactor: only BaseItemSemanticEditPolicy knows arguments and their order
-«DEFINE checkLinkConstraintInvocation FOR gmfgen::GenLink-»
-«EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canExistCall»
+«IF hasContainerOtherThanSource(self)-»
+ if (!(«EXPAND MetaModel::IsContainerInstance('getLink()', metaClass) FOR containmentMetaFeature.genClass»)) {
+ return false;
+ }
+ «EXPAND MetaModel::DeclareAndAssignContainer('container', 'getLink()', metaClass) FOR containmentMetaFeature.genClass»
+«ENDIF-»
+ return «EXPAND xpt::diagram::editpolicies::BaseItemSemanticEditPolicy::canExistCall(link, 'container', 'getLink()', sourceVar, targetVar)»;
«ENDDEFINE»
«REM»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
index 1b4be63f5..7525f462f 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/diagram/editpolicies/BaseItemSemanticEditPolicy.xpt
@@ -16,7 +16,6 @@
«EXTENSION xpt::diagram::editpolicies::Utils»
«EXTENSION xpt::diagram::Utils»
«EXTENSION xpt::GenModelUtils»
-«EXTENSION xpt::expressions::ValueExpression»
«DEFINE BaseItemSemanticEditPolicy FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
@@ -305,15 +304,25 @@ protected org.eclipse.gef.commands.Command getReorientRelationshipCommand(org.ec
«getBaseItemSemanticEditPolicyQualifiedClassName()».getLinkConstraints()«-»
«ENDDEFINE»
-«DEFINE canExistCall FOR gmfgen::GenLink-»
-«EXPAND _accessLinkConstraints FOR diagram».canExist«getUniqueIdentifier()-»
+«DEFINE canExistCall(gmfgen::GenLink link, String sourceVar, String targetVar) FOR gmfgen::FeatureLinkModelFacet-»
+«EXPAND _accessLinkConstraints FOR link.diagram».canExist«link.getUniqueIdentifier()»(«sourceVar», «targetVar»)«-»
+«ENDDEFINE»
+// NOTE, containerVar will be used only when link has other container than its source. It's safe to pass variable/method name that doesn't exist
+«DEFINE canExistCall(gmfgen::GenLink link, String containerVar, String linkVar, String sourceVar, String targetVar) FOR gmfgen::TypeLinkModelFacet-»
+«EXPAND _accessLinkConstraints FOR link.diagram».canExist«link.getUniqueIdentifier()»(«IF hasContainerOtherThanSource(self)»«containerVar», «ENDIF»«linkVar», «sourceVar», «targetVar»)«-»
«ENDDEFINE»
-«DEFINE canCreateCall FOR gmfgen::GenLink-»
-«EXPAND _accessLinkConstraints FOR diagram».canCreate«getUniqueIdentifier()-»
+«DEFINE canCreateCall(gmfgen::GenLink link, String sourceVar, String targetVar) FOR gmfgen::FeatureLinkModelFacet-»
+«EXPAND _accessLinkConstraints FOR link.diagram».canCreate«link.getUniqueIdentifier()»(«sourceVar», «targetVar»)«-»
+«ENDDEFINE»
+// NOTE, containerVar will be used only when link has other container than its source. It's safe to pass variable/method name that doesn't exist
+// Yes, this is sorta hack, but no idea of better approach right now. Perhaps, CreateLinkUtils may always define getContainer() for TypeLinkModelFacet, and use getSource() by default?
+«DEFINE canCreateCall(gmfgen::GenLink link, String containerVar, String sourceVar, String targetVar) FOR gmfgen::TypeLinkModelFacet-»
+«EXPAND _accessLinkConstraints FOR link.diagram».canCreate«link.getUniqueIdentifier()»(«IF hasContainerOtherThanSource(self)»«containerVar», «ENDIF»«sourceVar», «targetVar»)«-»
«ENDDEFINE»
+
«REM»
FIXME need to check constraint's provider to ensure we don't generate a field
for e.g. Java (or Literal, which is unlikely, though) expressions
@@ -333,22 +342,6 @@ protected org.eclipse.gef.commands.Command getReorientRelationshipCommand(org.ec
«EXPAND xpt::Common::generatedClassComment»
public static class «getLinkCreationConstraintsClassName()» {
-«IF null <> editorGen.expressionProviders-»
- «EXPAND xpt::Common::generatedMemberComment»
- private static final String OPPOSITE_END_VAR = "oppositeEnd"; «EXPAND xpt::Common::nonNLS»
-
-«FOREACH getValidLinkConstraints(self) AS lc-»
-«IF lc.sourceEnd <> null-»
- «EXPAND xpt::Common::generatedMemberComment»
- private «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «sourceConstraintFieldName(lc.link)»;
-«ENDIF-»
-«IF lc.targetEnd <> null-»
- «EXPAND xpt::Common::generatedMemberComment»
- private «editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» «targetConstraintFieldName(lc.link)»;
-«ENDIF-»
-«ENDFOREACH»
-«ENDIF-»
-
«EXPAND xpt::Common::generatedMemberComment»
«getLinkCreationConstraintsClassName()»() {«REM»package-local for the BaseItemSemanticEditPolicy to instantiate. Perhaps, protected is better (i.e. if someone subclasses it?)«ENDREM»
// use static method #getLinkConstraints() to access instance
@@ -378,18 +371,18 @@ public boolean canCreate«getUniqueIdentifier()»(«EXPAND canCreateParameters F
«ENDREM»
«DEFINE canExist FOR gmfgen::GenLink»
«EXPAND xpt::Common::generatedMemberComment»
- public boolean canExist«getUniqueIdentifier()»(«EXPAND canCreateParameters FOR modelFacet») {
+ public boolean canExist«getUniqueIdentifier()»(«EXPAND canExistParameters FOR modelFacet») {
«IF creationConstraints <> null and (creationConstraints.isValid() and null <> getDiagram().editorGen.expressionProviders)-»
try {
«IF null <> creationConstraints.sourceEnd-»
- «EXPAND checkAdditionalConstraint(creationConstraints.sourceEnd, sourceConstraintFieldName(self), 'source', 'target', creationConstraints.getSourceEndContextClass(), creationConstraints.getTargetEndContextClass()) FOR creationConstraints.sourceEnd.provider-»
+ «EXPAND _checkAdditionalConstraint(creationConstraints.sourceEnd, 'source', 'target', creationConstraints.getSourceEndContextClass(), creationConstraints.getTargetEndContextClass()) FOR creationConstraints.sourceEnd.provider-»
«ENDIF-»
«IF null <> creationConstraints.targetEnd-»
- «EXPAND checkAdditionalConstraint(creationConstraints.targetEnd, targetConstraintFieldName(self), 'target', 'source', creationConstraints.getTargetEndContextClass(), creationConstraints.getSourceEndContextClass()) FOR creationConstraints.targetEnd.provider-»
+ «EXPAND _checkAdditionalConstraint(creationConstraints.targetEnd, 'target', 'source', creationConstraints.getTargetEndContextClass(), creationConstraints.getSourceEndContextClass()) FOR creationConstraints.targetEnd.provider-»
«ENDIF-»
return true;
} catch(Exception e) {
- «getDiagram().editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Link constraint evaluation error", e); «EXPAND xpt::Common::nonNLS»
+ «EXPAND plugin::Activator::instanceAccess FOR getDiagram().editorGen».logError("Link constraint evaluation error", e);«EXPAND xpt::Common::nonNLS»
return false;
}
«ELSE-»
@@ -398,19 +391,21 @@ public boolean canCreate«getUniqueIdentifier()»(«EXPAND canCreateParameters F
}
«ENDDEFINE»
-«DEFINE canCreateParameters FOR gmfgen::LinkModelFacet»«EXPAND incorrectLinkModelFacet»«ENDDEFINE»
+// FIXME mark as private (_) and move to impl::<find proper place>::LinkConstraints.xpt
+«DEFINE canCreateParameters FOR gmfgen::LinkModelFacet»«EXPAND sourceTargetParameters»«ENDDEFINE»// source and target are reasonable defaults
«DEFINE canCreateParameters FOR gmfgen::TypeLinkModelFacet»«IF hasContainerOtherThanSource(self)»«EXPAND MetaModel::QualifiedClassName FOR containmentMetaFeature.genClass» container, «ENDIF»«EXPAND sourceTargetParameters»«ENDDEFINE»
-«DEFINE canCreateParameters FOR gmfgen::FeatureLinkModelFacet»«EXPAND sourceTargetParameters»«ENDDEFINE»
-«DEFINE sourceTargetParameters FOR gmfgen::LinkModelFacet»«EXPAND MetaModel::QualifiedClassName FOR getSourceType()» source, «EXPAND MetaModel::QualifiedClassName FOR getTargetType()» target«ENDDEFINE»
+«DEFINE canExistParameters FOR gmfgen::LinkModelFacet»«EXPAND sourceTargetParameters»«ENDDEFINE»// source and target are reasonable defaults
+«DEFINE canExistParameters FOR gmfgen::TypeLinkModelFacet»«IF hasContainerOtherThanSource(self)»«EXPAND MetaModel::QualifiedClassName FOR containmentMetaFeature.genClass» container, «ENDIF»«EXPAND MetaModel::QualifiedClassName FOR metaClass» linkInstance, «EXPAND sourceTargetParameters»«ENDDEFINE»
-«DEFINE canCreateValues FOR gmfgen::LinkModelFacet»«EXPAND incorrectLinkModelFacet»«ENDDEFINE»
-«DEFINE canCreateValues FOR gmfgen::TypeLinkModelFacet»«IF hasContainerOtherThanSource(self)»container, «ENDIF»source, target«ENDDEFINE»
-«DEFINE canCreateValues FOR gmfgen::FeatureLinkModelFacet»source, target«ENDDEFINE»
+«DEFINE sourceTargetParameters FOR gmfgen::LinkModelFacet»«EXPAND MetaModel::QualifiedClassName FOR getSourceType()» source, «EXPAND MetaModel::QualifiedClassName FOR getTargetType()» target«ENDDEFINE»
+// these are in fact 'canExist' values
+«DEFINE canCreateValues FOR gmfgen::LinkModelFacet»source, target«ENDDEFINE» // defaults
+«DEFINE canCreateValues FOR gmfgen::TypeLinkModelFacet»«IF hasContainerOtherThanSource(self)»container, «ENDIF»null, source, target«ENDDEFINE»
-«DEFINE checkEMFConstraints FOR gmfgen::LinkModelFacet»«EXPAND incorrectLinkModelFacet»«ENDDEFINE»
+«DEFINE checkEMFConstraints FOR gmfgen::LinkModelFacet»«ERROR 'Unrecognized link model facet in checkEMFConstraints: ' + self.repr()»«ENDDEFINE»
«DEFINE checkEMFConstraints FOR gmfgen::TypeLinkModelFacet-»
«LET childMetaFeature <> containmentMetaFeature and childMetaFeature.ecoreFeature.upperBound.oclAsType(Integer) > 0 AS checkChildFeatureUpperBound-»
@@ -464,25 +459,23 @@ if (target != null && («EXPAND featureBoundsConditionClause('target', getTarget
«DEFINE featureUniquenessComparator(featureVar : String, featureVarGenClass : genmodel::GenClass) FOR genmodel::GenFeature»«EXPAND MetaModel::getFeatureValue(featureVar, featureVarGenClass) FOR self».contains(target)«ENDDEFINE»
-«DEFINE checkAdditionalConstraint(valueExpr : gmfgen::ValueExpression, constraintFieldName : String, sourceEndVar : String, targetEndVar : String, context : genmodel::GenClass, oppositeEndContext : genmodel::GenClass) FOR gmfgen::GenExpressionProviderBase»
+«DEFINE _checkAdditionalConstraint(gmfgen::ValueExpression valueExpr, String sourceEndVar, String targetEndVar, genmodel::GenClass context, genmodel::GenClass oppositeEndContext) FOR gmfgen::GenExpressionProviderBase»
«ERROR 'Have no idea what extra constraints to check for ' + self.repr()»
«ENDDEFINE»
-«DEFINE checkAdditionalConstraint(valueExpr : gmfgen::ValueExpression, constraintFieldName : String, sourceEndVar : String, targetEndVar : String, context : genmodel::GenClass, oppositeEndContext : genmodel::GenClass) FOR gmfgen::GenExpressionInterpreter-»
+«DEFINE _checkAdditionalConstraint(gmfgen::ValueExpression valueExpr, String sourceEndVar, String targetEndVar, genmodel::GenClass context, genmodel::GenClass oppositeEndContext) FOR gmfgen::GenExpressionInterpreter-»
if («sourceEndVar» == null) {
return true;
+ } else {«REM»else is important here as it gives scope for the env variable«ENDREM»
+ java.util.Map«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» env = java.util.Collections.«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram»singletonMap(«EXPAND oppositeEndVariableNameValue», «EXPAND MetaModel::MetaClass FOR oppositeEndContext»);«EXPAND xpt::Common::nonNLS»
+ Object «sourceEndVar»Val = «EXPAND xpt::expressions::getExpression::getExpression(valueExpr, context, 'env')».evaluate(«sourceEndVar», java.util.Collections.singletonMap(«EXPAND oppositeEndVariableNameValue», «targetEndVar»));«EXPAND xpt::Common::nonNLS»
+ if (false == «sourceEndVar»Val instanceof Boolean || !((Boolean) «sourceEndVar»Val).booleanValue()) {
+ return false;
+ } // else fall-through
}
- if («constraintFieldName» == null) {
- java.util.Map«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» env = java.util.Collections.«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram»singletonMap(OPPOSITE_END_VAR, «EXPAND MetaModel::MetaClass FOR oppositeEndContext»);
- «constraintFieldName» = «EXPAND xpt::expressions::getExpression::getExpression(valueExpr, context, 'env')»;«EXPAND xpt::Common::nonNLS»
- }
- Object «sourceEndVar»Val = «constraintFieldName».evaluate(«sourceEndVar», java.util.Collections.singletonMap(OPPOSITE_END_VAR, «targetEndVar»));
- if (false == «sourceEndVar»Val instanceof Boolean || !((Boolean) «sourceEndVar»Val).booleanValue()) {
- return false;
- } // else fall-through
«ENDDEFINE»
-«DEFINE checkAdditionalConstraint(valueExpr : gmfgen::ValueExpression, constraintFieldName : String, sourceEndVar : String, targetEndVar : String, context : genmodel::GenClass, oppositeEndContext : genmodel::GenClass) FOR gmfgen::GenJavaExpressionProvider-»
+«DEFINE _checkAdditionalConstraint(gmfgen::ValueExpression valueExpr, String sourceEndVar, String targetEndVar, genmodel::GenClass context, genmodel::GenClass oppositeEndContext) FOR gmfgen::GenJavaExpressionProvider-»
«IF injectExpressionBody and (valueExpr.body <> null and valueExpr.body.size() <> 0)-»
«valueExpr.body»
«ELSEIF throwException or (injectExpressionBody and (valueExpr.body = null or valueExpr.body.size() = 0))-»
@@ -499,8 +492,7 @@ if (target != null && («EXPAND featureBoundsConditionClause('target', getTarget
«ENDIF-»
«ENDDEFINE»
-
-«DEFINE incorrectLinkModelFacet FOR gmfgen::LinkModelFacet»«ERROR 'Unrecognized link model facet: ' + self.repr()»«ENDDEFINE»
+«DEFINE oppositeEndVariableNameValue FOR OclAny»"oppositeEnd"«ENDDEFINE»
«DEFINE additions FOR gmfgen::GenDiagram»«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
index 1aa27c046..d4312d09f 100755
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
@@ -21,12 +21,12 @@ public class «className» {
«EXPAND _initInterpreterFactory»
- «EXPAND xpt::Common::generatedMemberComment»
+ «EXPAND xpt::Common::generatedMemberComment('This is factory method, callers are responsible to keep reference to the return value if they want to reuse parsed expression')»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» environment) {
return new Expression(body, context, environment);
}
- «EXPAND xpt::Common::generatedMemberComment('This method will become private in the next release')»«REM»FIXME private or completely remove in the next release «ENDREM»
+ «EXPAND xpt::Common::generatedMemberComment('This method will become private in the next release')»«REM»FIXME private or completely remove in the next release. Besides, no real need to pass emptyMap when null would suffice «ENDREM»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context) {
return getExpression(body, context, «EXPAND CodeStyle::emptyMap('String, org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram»);
}
@@ -123,7 +123,16 @@ org.eclipse.ocl.options.ParsingOptions.setOption(«environmentVar», org.eclipse
}
«EXPAND xpt::Common::generatedMemberComment»
- public static «container.getAbstractExpressionQualifiedClassName()» getExpression(int index, org.eclipse.emf.ecore.EClassifier context) {
+ «REM»
+ - I'm not quite sure indexes instead of string bodies are good approach, may revisit this later.
+ - There's no confidence we shouldn't keep Map/Set instead of fixed length array for expressions.
+ The reason I didn't use Map/Set right away is uncertainty with the key - i.e. body only, body + context, or
+ body+context+environment(how). I.e. if it's possible (reasonable) to have same body for different contexts -
+ of course, 'self.oclIsUndefined()' may be run in different contexts, but it's useless example.
+ - DGMT and reuse of gmfgen::ValueExpressions might be related here - if we decide identical body is enough to
+ reuse an expression (and change DGMT#bindToProvider accordingly), then the answer to previous point would become obvious (i.e. "body is enough")
+ «ENDREM-»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(int index, org.eclipse.emf.ecore.EClassifier context, java.util.Map«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» environment) {
«className» cached = «EXPAND plugin::Activator::instanceAccess FOR container.editorGen».get«className»();
if (cached == null) {
«EXPAND plugin::Activator::instanceAccess FOR container.editorGen».set«className»(cached = new «className»());
@@ -136,7 +145,7 @@ org.eclipse.ocl.options.ParsingOptions.setOption(«environmentVar», org.eclipse
«FOREACH expressions.getBodyString() AS b»«b», «EXPAND xpt::Common::nonNLS»
«ENDFOREACH-»
};
- cached.expressions[index] = getExpression(exprBodies[index], context);
+ cached.expressions[index] = getExpression(exprBodies[index], context, environment == null ? «EXPAND CodeStyle::emptyMap('String, org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» : environment);
}
return cached.expressions[index];
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto
deleted file mode 100644
index 028c4b8a7..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2008, 2010 Borland Software Corporation and others
- *
- * 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:
- * Artem Tikhomirov (Borland) - initial API and implementation
- */
-
-modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
-
-library ValueExpression;
-
-// next two methods are likely to be removed soon as well
-// (once we completely support expression caching inside factory
-
-helper sourceConstraintFieldName(l : gmfgen::GenLink) : String {
- return l.getUniqueIdentifier() + '_SourceExpression'
-}
-
-helper targetConstraintFieldName(l : gmfgen::GenLink) : String {
- return l.getUniqueIdentifier() + '_TargetExpression'
-}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
index 7d34c03c5..ee20b2a28 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
@@ -14,15 +14,15 @@
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
«DEFINE getExpression(gmfgen::ValueExpression valueExpr, genmodel::GenClassifier context) FOR gmfgen::GenExpressionInterpreter-»
-«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «EXPAND MetaModel::MetaClass FOR context»)«-»
+«EXPAND getExpression(valueExpr, context, 'null')-»
«ENDDEFINE»
// occasionally we need to use some well-known context type, i.e. String
«DEFINE getExpression(gmfgen::ValueExpression valueExpr, String contextMetaClassifier) FOR gmfgen::GenExpressionInterpreter-»
-«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «contextMetaClassifier»)«-»
+«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «contextMetaClassifier», 'null')«-»
«ENDDEFINE»
// pass specific environment to obtain expression
«DEFINE getExpression(gmfgen::ValueExpression valueExpr, genmodel::GenClassifier context, String environmentArg) FOR gmfgen::GenExpressionInterpreter-»
-«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«valueExpr.getBodyString()», «EXPAND MetaModel::MetaClass FOR context», «environmentArg»)«-»
+«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «EXPAND MetaModel::MetaClass FOR context», «environmentArg»)«-»
«ENDDEFINE»

Back to the top