Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2010-04-27 21:12:24 -0400
committeratikhomirov2010-04-27 21:12:24 -0400
commit146088824765971ba2850f3a9c8465fc8059f9f9 (patch)
treefe866a544d49c44523a13b58e2f6a2b23756554e
parentf9efde529b73f9c7bc08675e32f87c1710249c77 (diff)
downloadorg.eclipse.gmf-tooling-146088824765971ba2850f3a9c8465fc8059f9f9.tar.gz
org.eclipse.gmf-tooling-146088824765971ba2850f3a9c8465fc8059f9f9.tar.xz
org.eclipse.gmf-tooling-146088824765971ba2850f3a9c8465fc8059f9f9.zip
[231330] reduce use of static fields. Fields in each place we use expressions replaced with single storage (array) inside factory that creates them. The factory records its single instance with the activator class.v20100427-2359
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt44
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/editor/VisualIDRegistry.xpt30
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt36
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt6
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto7
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt4
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt44
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementInitializers.xpt42
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementTypes.xpt2
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/providers/MetricProvider.xpt17
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/providers/Metrics.qvto6
-rwxr-xr-xplugins/org.eclipse.gmf.codegen/templates/xpt/providers/ValidationProvider.xpt10
12 files changed, 131 insertions, 117 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
index 8cdeb0802..9eaae5046 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ExpressionLabelParser.xpt
@@ -12,35 +12,11 @@
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
-«DEFINE fields FOR gmfgen::ExpressionLabelParser-»
-«IF not viewExpression.oclIsUndefined() and viewExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)»
- «EXPAND xpt::Common::generatedMemberComment»
- private final «holder.editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» printExpression;
-«ENDIF-»
-
-«IF not editExpression.oclIsUndefined() and editExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)»
- «EXPAND xpt::Common::generatedMemberComment»
- private final «holder.editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» editExpression;
-«ENDIF-»
-
-«IF not validateExpression.oclIsUndefined() and validateExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)»
- «EXPAND xpt::Common::generatedMemberComment»
- private final «holder.editorGen.expressionProviders.getAbstractExpressionQualifiedClassName()» validateExpression;
-«ENDIF-»
-«ENDDEFINE»
+«DEFINE fields FOR gmfgen::ExpressionLabelParser»«ENDDEFINE»
«DEFINE cons(String name) FOR gmfgen::ExpressionLabelParser-»
«EXPAND xpt::Common::generatedMemberComment»
public «name»() {
- «IF not viewExpression.oclIsUndefined() and viewExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)-»
- this.printExpression = «EXPAND xpt::expressions::getExpression::getExpression(viewExpression, self.expressionContext) FOR viewExpression.provider.oclAsType(gmfgen::GenExpressionInterpreter)»;«EXPAND xpt::Common::nonNLS»
- «ENDIF-»
- «IF not editExpression.oclIsUndefined() and editExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)-»
- this.editExpression = «EXPAND xpt::expressions::getExpression::getExpression(editExpression, self.expressionContext) FOR editExpression.provider.oclAsType(gmfgen::GenExpressionInterpreter)»;«EXPAND xpt::Common::nonNLS»
- «ENDIF-»
- «IF not validateExpression.oclIsUndefined() and validateExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)-»
- this.validateExpression = «EXPAND xpt::expressions::getExpression::getExpression(validateExpression, 'org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getEString()') FOR validateExpression.provider.oclAsType(gmfgen::GenExpressionInterpreter)»;«EXPAND xpt::Common::nonNLS»
- «ENDIF-»
}
«ENDDEFINE»
@@ -48,7 +24,7 @@
«IF editExpression.oclIsUndefined()-»
return getPrintString(element, flags);
«ELSE-»
-«EXPAND _evaluateAndReturnExpressionResult('this.editExpression', 'evaluateEditExpression', editExpression) FOR editExpression.provider-»
+«EXPAND _evaluateAndReturnExpressionResult(self, 'evaluateEditExpression', editExpression) FOR editExpression.provider-»
«ENDIF-»
«ENDDEFINE»
@@ -57,27 +33,29 @@
// TODO
throw new UnsupportedOperationException();
«ELSE-»
-«EXPAND _evaluateAndReturnExpressionResult('this.printExpression', 'evaluatePrintExpression', viewExpression) FOR viewExpression.provider-»
+«EXPAND _evaluateAndReturnExpressionResult(self, 'evaluatePrintExpression', viewExpression) FOR viewExpression.provider-»
«ENDIF-»
«ENDDEFINE»
-«DEFINE _evaluateAndReturnExpressionResult(String expressionFieldName, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: _evaluateAndReturnExpressionResult'»«ENDDEFINE»
-«DEFINE _evaluateAndReturnExpressionResult(String expressionFieldName, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionInterpreter-»
+«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: _evaluateAndReturnExpressionResult'»«ENDDEFINE»
+«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenExpressionInterpreter-»
org.eclipse.emf.ecore.EObject target = (org.eclipse.emf.ecore.EObject) element.getAdapter(org.eclipse.emf.ecore.EObject.class);
-Object result = «expressionFieldName».evaluate(target);
+Object result = «EXPAND xpt::expressions::getExpression::getExpression(expression, parser.expressionContext)».evaluate(target);
return String.valueOf(result);
«ENDDEFINE»
-«DEFINE _evaluateAndReturnExpressionResult(String expressionFieldName, String javaMethodName, ValueExpression expression) FOR gmfgen::GenJavaExpressionProvider-»
+«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenJavaExpressionProvider-»
return «javaMethodName»((org.eclipse.emf.ecore.EObject) element.getAdapter(org.eclipse.emf.ecore.EObject.class));
«ENDDEFINE»
-«DEFINE _evaluateAndReturnExpressionResult(String expressionFieldName, String javaMethodName, ValueExpression expression) FOR gmfgen::GenLiteralExpressionProvider-»
+«DEFINE _evaluateAndReturnExpressionResult(gmfgen::ExpressionLabelParser parser, String javaMethodName, ValueExpression expression) FOR gmfgen::GenLiteralExpressionProvider-»
return «expression.body»;
«ENDDEFINE»
«DEFINE accessValidateExpression FOR gmfgen::ExpressionLabelParser-»
«IF not validateExpression.oclIsUndefined() -»
- if («IF validateExpression.provider.getLanguage() = gmfgen::GenLanguage::_literal»!«validateExpression.body»«ELSE»Boolean.FALSE.equals(«IF validateExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)»this.validateExpression.evaluate(editString)«ELSEIF validateExpression.provider.oclIsKindOf(gmfgen::GenJavaExpressionProvider)»evaluateValidateExpression(editString)«ENDIF»)«ENDIF») {
+ if («IF validateExpression.provider.getLanguage() = gmfgen::GenLanguage::_literal»!«validateExpression.body»«ELSE-»
+ Boolean.FALSE.equals(«IF validateExpression.provider.oclIsKindOf(gmfgen::GenExpressionInterpreter)»«EXPAND xpt::expressions::getExpression::getExpression(validateExpression, 'org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getEString()') FOR validateExpression.provider.oclAsType(gmfgen::GenExpressionInterpreter)».evaluate(editString)«-»
+ «ELSEIF validateExpression.provider.oclIsKindOf(gmfgen::GenJavaExpressionProvider)»evaluateValidateExpression(editString)«ENDIF»)«ENDIF») {
return org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.UNEDITABLE_STATUS;
} // else fall-through
«ENDIF-»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/VisualIDRegistry.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/VisualIDRegistry.xpt
index a73432be0..9cc52d40c 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/VisualIDRegistry.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/editor/VisualIDRegistry.xpt
@@ -88,11 +88,6 @@ public class «visualIDRegistryClassName» {
«DEFINE attributes FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::generatedMemberComment»
private static final String DEBUG_KEY = "«editorGen.plugin.iD»/debug/visualID"; «EXPAND xpt::Common::nonNLS»
-«IF null <> editorGen.expressionProviders-»
- «EXPAND _constraintField FOREACH topLevelNodes-»
- «EXPAND _constraintField FOREACH childNodes-»
- «EXPAND _constraintField FOREACH links-»
-«ENDIF-»
«ENDDEFINE»
«DEFINE getViewVisualID FOR gmfgen::GenDiagram-»
@@ -314,7 +309,7 @@ private static boolean isDiagram(«EXPAND MetaModel::QualifiedClassName FOR doma
«IF null <> editorGen.expressionProviders-»
«EXPAND _constraintMethod FOREACH topLevelNodes->select(n | n.modelFacet.modelElementSelector <> null)-»
«EXPAND _constraintMethod FOREACH childNodes->select(n | n.modelFacet.modelElementSelector <> null)-»
- «FOREACH links->asSequence() AS l»«EXPAND _constraintMethod(l) FOR l.modelFacet»«ENDFOREACH»
+ «FOREACH links AS l»«EXPAND _constraintMethod(l) FOR l.modelFacet»«ENDFOREACH»
«ENDIF-»
«ENDDEFINE»
@@ -347,34 +342,15 @@ private static boolean isDiagram(«EXPAND MetaModel::QualifiedClassName FOR doma
}
«ENDDEFINE»
+// FIXME move these methods to ElementInitializers or any other more suitable place
«DEFINE _domainElementConstraintMethod(diagramElement : gmfgen::GenCommonBase, expression : gmfgen::ValueExpression, context : genmodel::GenClass) FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
private static boolean «EXPAND _domainElementConstraintMethodName FOR diagramElement»(«EXPAND MetaModel::QualifiedClassName FOR context» domainElement) {
- if («constraintFieldName(diagramElement)» == null) { // lazy initialization
- «constraintFieldName(diagramElement)» = «EXPAND xpt::expressions::getExpression::getExpression(expression, context)»; «EXPAND xpt::Common::nonNLS»
- }
- Object result = «constraintFieldName(diagramElement)».evaluate(domainElement);
+ Object result = «EXPAND xpt::expressions::getExpression::getExpression(expression, context)».evaluate(domainElement);
return result instanceof Boolean && ((Boolean)result).booleanValue();
}
«ENDDEFINE»
-
-«DEFINE _constraintField FOR gmfgen::GenNode»«EXPAND _constraintField(self) FOR modelFacet»«ENDDEFINE»
-«DEFINE _constraintField FOR gmfgen::GenLink»«EXPAND _constraintField(self) FOR modelFacet»«ENDDEFINE»
-
-«DEFINE _constraintField(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::ModelFacet»«ENDDEFINE»
-«DEFINE _constraintField(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::TypeModelFacet-»
-«IF modelElementSelector <> null»«EXPAND _constraintField(diagramElement) FOR modelElementSelector.provider»«ENDIF-»
-«ENDDEFINE»
-
-«DEFINE _constraintField(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenExpressionInterpreter»
- «EXPAND xpt::Common::generatedMemberComment»
- private static «container.getAbstractExpressionQualifiedClassName()» «constraintFieldName(diagramElement)»;
-«ENDDEFINE»
-
-«DEFINE _constraintField(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Need to define approach to constraint fields for ' + self.repr()»«ENDDEFINE»
-«DEFINE _constraintField(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenJavaExpressionProvider»«ENDDEFINE»// IOW, no fields for Java
-
«REM»
Constraints support end.
«ENDREM»
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 5473d6bc0..1aa27c046 100755
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
@@ -19,16 +19,14 @@ package «container.expressionsPackageName»;
«EXPAND xpt::Common::generatedClassComment»
public class «className» {
- «EXPAND xpt::Common::generatedMemberComment»
- private «className»() {
- }
+ «EXPAND _initInterpreterFactory»
«EXPAND xpt::Common::generatedMemberComment»
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»
+ «EXPAND xpt::Common::generatedMemberComment('This method will become private in the next release')»«REM»FIXME private or completely remove in the next release «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»);
}
@@ -113,3 +111,33 @@ org.eclipse.ocl.options.ParsingOptions.setOption(«environmentVar», org.eclipse
«ENDDEFINE»
«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»
+
+// just to avoid identical piece of template in the RegexpExpressionFactory
+«DEFINE _initInterpreterFactory FOR gmfgen::GenExpressionInterpreter-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final «container.getAbstractExpressionQualifiedClassName()»[] expressions;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ protected «className»() {
+ this.expressions = new «container.getAbstractExpressionQualifiedClassName()»[«expressions->size()»];
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «container.getAbstractExpressionQualifiedClassName()» getExpression(int index, org.eclipse.emf.ecore.EClassifier context) {
+ «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»());
+ }
+ if (index < 0 || index >= cached.expressions.length) {
+ throw new IllegalArgumentException();
+ }
+ if (cached.expressions[index] == null) {
+ final String[] exprBodies = new String[] {
+ «FOREACH expressions.getBodyString() AS b»«b», «EXPAND xpt::Common::nonNLS»
+ «ENDFOREACH-»
+ };
+ cached.expressions[index] = getExpression(exprBodies[index], context);
+ }
+ return cached.expressions[index];
+ }
+«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
index bed2d4d85..a42c198c0 100755
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
@@ -19,16 +19,14 @@ package «container.expressionsPackageName»;
«EXPAND xpt::Common::generatedClassComment»
public class «className» {
- «EXPAND xpt::Common::generatedMemberComment»
- private «className»() {
- }
+ «EXPAND xpt::expressions::OCLExpressionFactory::_initInterpreterFactory»
«EXPAND xpt::Common::generatedMemberComment»
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»
+ «EXPAND xpt::Common::generatedMemberComment('This method will become private in the next release')»«REM»FIXME private or completely remove in the next release «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»);
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto
index 9389b45d2..028c4b8a7 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/ValueExpression.qvto
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009 Borland Software Corporation
+ * 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
@@ -14,9 +14,8 @@ modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
library ValueExpression;
-helper constraintFieldName(cb : gmfgen::GenCommonBase) : String {
- return cb.getUniqueIdentifier() + '_Constraint'
-}
+// 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'
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 98de181ed..7d34c03c5 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
@@ -14,12 +14,12 @@
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
«DEFINE getExpression(gmfgen::ValueExpression valueExpr, genmodel::GenClassifier context) FOR gmfgen::GenExpressionInterpreter-»
-«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«valueExpr.getBodyString()», «EXPAND MetaModel::MetaClass FOR context»)«-»
+«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «EXPAND MetaModel::MetaClass FOR context»)«-»
«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)»(«valueExpr.getBodyString()», «contextMetaClassifier»)«-»
+«getQualifiedClassName()».«getExpressionAccessor(valueExpr)»(«expressions->indexOf(valueExpr) - 1», «contextMetaClassifier»)«-»
«ENDDEFINE»
// pass specific environment to obtain expression
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
index cdddeab1c..379ee79d1 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/plugin/Activator.xpt
@@ -40,6 +40,17 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
private «editorGen.diagram.getLinkCreationConstraintsQualifiedClassName()» linkConstraints;
«ENDIF-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «editorGen.diagram.getElementInitializersPackageName()».«editorGen.diagram.getElementInitializersClassName()» initializers;
+
+«IF not editorGen.expressionProviders.oclIsUndefined() -»
+«FOREACH editorGen.expressionProviders.providers[gmfgen::GenExpressionInterpreter] AS p-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «p.getQualifiedClassName()» «p.language»Factory;
+«ENDFOREACH-»
+«ENDIF-»
+
«EXPAND xpt::Common::generatedMemberComment»
public «activatorClassName»() {
}
@@ -58,7 +69,13 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
adapterFactory = null;
«IF editorGen.diagram.links->exists(not sansDomain)-»
linkConstraints = null;
-«ENDIF-»
+«ENDIF-»
+ initializers = null;
+«IF not editorGen.expressionProviders.oclIsUndefined() -»
+«FOREACH editorGen.expressionProviders.providers[gmfgen::GenExpressionInterpreter] AS p-»
+ «p.language»Factory = null;
+«ENDFOREACH-»
+«ENDIF-»
instance = null;
super.stop(context);
}
@@ -178,6 +195,31 @@ public class «activatorClassName» extends org.eclipse.ui.plugin.AbstractUIPlug
«ENDIF-»
«EXPAND xpt::Common::generatedMemberComment»
+ public «editorGen.diagram.getElementInitializersPackageName()».«editorGen.diagram.getElementInitializersClassName()» getElementInitializers() {
+ return initializers;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void setElementInitializers(«editorGen.diagram.getElementInitializersPackageName()».«editorGen.diagram.getElementInitializersClassName()» i) {
+ this.initializers = i;
+ }
+
+«IF not editorGen.expressionProviders.oclIsUndefined() -»
+«FOREACH editorGen.expressionProviders.providers[gmfgen::GenExpressionInterpreter] AS p-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ public «p.getQualifiedClassName()» get«p.className»() {
+ return «p.language»Factory;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public void set«p.className»(«p.getQualifiedClassName()» f) {
+ this.«p.language»Factory = f;
+ }
+
+«ENDFOREACH-»
+«ENDIF-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
public void logError(String error) {
logError(error, null);
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementInitializers.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementInitializers.xpt
index cbef1b472..9d79955b5 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementInitializers.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementInitializers.xpt
@@ -20,15 +20,31 @@
«EXTENSION xpt::GenModelUtils»
«EXTENSION gmf::GenModelUtils»
+// XXX should generate this class only when there is initialization logic defined in the model
+
«DEFINE ElementInitializers FOR gmfgen::GenDiagram-»
«EXPAND xpt::Common::copyright FOR editorGen-»
-package «providersPackageName»;
+package «getElementInitializersPackageName()»;
«EXPAND xpt::Common::generatedClassComment»
-public class ElementInitializers {
+public class «getElementInitializersClassName()» {
+
+ protected «getElementInitializersClassName()»() {
+ // use #getInstance to access cached instance
+ }
+
«EXPAND Initializers»
«EXPAND JavaSupport»
«EXPAND additions-»
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static «getElementInitializersClassName()» getInstance() {
+ «getElementInitializersClassName()» cached = «EXPAND plugin::Activator::instanceAccess FOR editorGen».getElementInitializers();
+ if (cached == null) {
+ «EXPAND plugin::Activator::instanceAccess FOR editorGen».setElementInitializers(cached = new «getElementInitializersClassName()»());
+ }
+ return cached;
+ }
}
«ENDDEFINE»
@@ -65,9 +81,9 @@ public class ElementInitializers {
«DEFINE initMethod(diagramElement : gmfgen::GenCommonBase) FOR gmfgen::GenFeatureSeqInitializer-»
«EXPAND xpt::Common::generatedMemberComment»
- public static void init_«diagramElement.getUniqueIdentifier()»(«EXPAND MetaModel::QualifiedClassName FOR elementClass» instance) {
+ public void init_«diagramElement.getUniqueIdentifier()»(«EXPAND MetaModel::QualifiedClassName FOR elementClass» instance) {
try {
- «FOREACH initializers->asSequence() AS i»«EXPAND performInit(diagramElement, 'instance', elementClass, getSuffixes((initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH-»
+ «FOREACH initializers AS i»«EXPAND performInit(diagramElement, 'instance', elementClass, getSuffixes((initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH-»
} catch(RuntimeException e) {
«diagramElement.getDiagram().editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError("Element initialization failed", e); //$NON-NLS-1$
}
@@ -113,12 +129,12 @@ public class ElementInitializers {
«ENDDEFINE»
«DEFINE performInit(diagramElement : gmfgen::GenCommonBase, instanceVar : String, instanceClass : genmodel::GenClass, counters : Sequence(Integer)) FOR gmfgen::GenReferenceNewElementSpec-»
-«FOREACH newElementInitializers->asSequence() AS newElemInit-»
+«FOREACH newElementInitializers AS newElemInit-»
«LET getSuffixes(counters, (newElementInitializers->indexOf(newElemInit) - 1)) AS initializerCounters-»
«LET getVariableName('newInstance', initializerCounters) AS newInstanceVar-»
«EXPAND MetaModel::NewInstance(newInstanceVar) FOR newElemInit.elementClass-»
«EXPAND MetaModel::modifyFeature(instanceVar, instanceClass, newInstanceVar) FOR feature»
-«FOREACH newElemInit.initializers->asSequence() AS i»«EXPAND performInit(diagramElement, newInstanceVar, newElemInit.elementClass, getSuffixes(initializerCounters, (newElemInit.initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH»
+«FOREACH newElemInit.initializers AS i»«EXPAND performInit(diagramElement, newInstanceVar, newElemInit.elementClass, getSuffixes(initializerCounters, (newElemInit.initializers->indexOf(i) - 1))) FOR i»«ENDFOREACH»
«ENDLET-»
«ENDLET-»
«ENDFOREACH-»
@@ -128,10 +144,7 @@ public class ElementInitializers {
«DEFINE evaluateExpr(diagramElement : gmfgen::GenCommonBase, valueExpr : gmfgen::GenFeatureValueSpec, instanceVar : String) FOR gmfgen::GenExpressionProviderBase»«ENDDEFINE»
-// XXX perhaps, using instance.eClass() is better option than MetaModel::MetaClass (though, need to rely on instance variable name/type)
-// FIXME - creating new expression each time we need to initialize an element is not very efficient (e.g. OCLFactory.getExpression()).
-// Perhaps, factory implementation should be changed instead, to keep all optimization in a single place?
-«DEFINE evaluateExpr(diagramElement : gmfgen::GenCommonBase, valueExpr : gmfgen::GenFeatureValueSpec, instanceVar : String) FOR gmfgen::GenExpressionInterpreter-»
+«DEFINE evaluateExpr(gmfgen::GenCommonBase diagramElement, gmfgen::GenFeatureValueSpec valueExpr, String instanceVar) FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::expressions::getExpression::getExpression(valueExpr.value, valueExpr.featureSeqInitializer.elementClass)».evaluate(«instanceVar»)«-»
«ENDDEFINE»
@@ -162,7 +175,7 @@ public class ElementInitializers {
«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase, vs : gmfgen::GenFeatureValueSpec) FOR gmfgen::GenExpressionProviderBase-»«ENDDEFINE»
«DEFINE javaMethod(diagramElement : gmfgen::GenCommonBase, vs : gmfgen::GenFeatureValueSpec) FOR gmfgen::GenJavaExpressionProvider-»
«EXPAND xpt::Common::generatedMemberComment»
- private static «EXPAND MetaModel::featureTargetType FOR vs.feature» «javaMethodName(diagramElement, vs)»(«EXPAND MetaModel::QualifiedClassName FOR vs.featureSeqInitializer.elementClass» self) {
+ private «EXPAND MetaModel::featureTargetType FOR vs.feature» «javaMethodName(diagramElement, vs)»(«EXPAND MetaModel::QualifiedClassName FOR vs.featureSeqInitializer.elementClass» self) {
«IF injectExpressionBody and (vs.value.body <> null and vs.value.body.size() <> 0)-»
«vs.value.body»
«ELSEIF throwException or (injectExpressionBody and (vs.value.body = null or vs.value.body.size() = 0))-»
@@ -174,4 +187,11 @@ public class ElementInitializers {
return null;
«ENDIF-»
}
+«ENDDEFINE»
+
+// GenLink or GenNode
+«DEFINE initMethodCall(gmfgen::TypeModelFacet modelFacet, String newElementVar) FOR gmfgen::GenCommonBase-»
+«IF modelFacet.modelElementInitializer <> null -»
+«getDiagram().getElementInitializersPackageName()».«getDiagram().getElementInitializersClassName()».getInstance().init_«getUniqueIdentifier()»(«newElementVar»);
+«ENDIF-»
«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementTypes.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementTypes.xpt
index aa75db597..6012c104a 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementTypes.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ElementTypes.xpt
@@ -19,7 +19,7 @@
package «providersPackageName»;
«EXPAND xpt::Common::generatedClassComment»
-public class «elementTypesClassName» extends ElementInitializers {
+public class «elementTypesClassName» {
«EXPAND _constructor-»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/MetricProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/MetricProvider.xpt
index 164cf2be2..1c620ce63 100755
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/MetricProvider.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/MetricProvider.xpt
@@ -66,7 +66,6 @@ public class «metricProviderClassName» {
«EXPAND keysAndToolTipsMethods FOR editorGen.metrics»
-«EXPAND metricCalcField FOREACH editorGen.metrics.metrics->select(m | m.rule <> null and (m.target <> null and m.target.getContext() <> null))»
«EXPAND metricCalcMethod FOREACH editorGen.metrics.metrics->select(m | m.rule <> null and (m.target <> null and m.target.getContext() <> null))»
«EXPAND MetricsResultView::Class»
@@ -359,14 +358,10 @@ public class «metricProviderClassName» {
«REM»Note, use of QualifiedClassName here assumes it always works the same for the notation model, regardless of 'dynamic model' use (i.e. always gives qName of oeg.runtime.notation.* Java class)«ENDREM»
«DEFINE calcMethodArgs(metric : gmfgen::GenMetricRule) FOR gmfgen::GenNotationElementTarget»«EXPAND MetaModel::QualifiedClassName FOR element» target«ENDDEFINE»
-
«DEFINE calcMethodBody(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionProviderBase»«ERROR 'No idea how to calculate metric\'s value for ' + self.repr()»«ENDDEFINE»
«DEFINE calcMethodBody(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionInterpreter-»
- if («exprFieldName(metric)» == null) {
- «exprFieldName(metric)» = «EXPAND xpt::expressions::getExpression::getExpression(metric.rule, metric.target.getContext())»;
- }
- Object val = «exprFieldName(metric)».evaluate(target);
+ Object val = «EXPAND xpt::expressions::getExpression::getExpression(metric.rule, metric.target.getContext())».evaluate(target);
if (val instanceof Number) {
return val.getClass() == Double.class ? (Double) val : new Double(((Number) val).doubleValue());
}
@@ -385,16 +380,6 @@ public class «metricProviderClassName» {
«ENDIF-»
«ENDDEFINE»
-«DEFINE metricCalcField FOR gmfgen::GenMetricRule-»
-«EXPAND metricCalcField(self) FOR rule.provider-»
-«ENDDEFINE»
-
-«DEFINE metricCalcField(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionProviderBase»«REM»NO-OP«ENDREM»«ENDDEFINE»
-«DEFINE metricCalcField(metric : gmfgen::GenMetricRule) FOR gmfgen::GenExpressionInterpreter-»
- «EXPAND xpt::Common::generatedMemberComment»
- private static«REM»FIXME: refactor to get rid of static fields«ENDREM» «container.getAbstractExpressionQualifiedClassName()» «exprFieldName(metric)»;
-«ENDDEFINE»
-
«DEFINE invokeCalcMethod(accessor : String, isSpecific : Boolean) FOR gmfgen::GenMetricRule»
«container.editorGen.diagram.getMetricProviderQualifiedClassName()».«calcMethodName(self)»(«IF not isSpecific /*CastEObject would be better, however need GenClassifier*/»(«EXPAND MetaModel::QualifiedClassName FOR target.getContext()») «ENDIF»«accessor»)«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/Metrics.qvto b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/Metrics.qvto
index 15303b925..b4eead6ca 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/Metrics.qvto
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/Metrics.qvto
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009 Borland Software Corporation
+ * 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
@@ -31,10 +31,6 @@ helper getDomainMetrics(c : gmfgen::GenMetricContainer) : Sequence(gmfgen::GenMe
return c.metrics->asSequence()->select(target.oclIsKindOf(gmfgen::GenDomainElementTarget))
}
-helper exprFieldName(m : gmfgen::GenMetricRule) : String {
- return 'expression' + validJavaIdentifier(m.key).firstToUpper()
-}
-
helper calcMethodName(m : gmfgen::GenMetricRule) : String {
return 'calc' + validJavaIdentifier(m.key).firstToUpper()
}
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ValidationProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ValidationProvider.xpt
index 0272747e6..78d48a337 100755
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ValidationProvider.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/providers/ValidationProvider.xpt
@@ -234,11 +234,6 @@ static boolean isInDefaultEditorContext(Object object) {
«EXPAND xpt::Common::generatedMemberComment»
public static class «getConstraintAdapterLocalClassName()» extends org.eclipse.emf.validation.AbstractModelConstraint {
-«IF rule.provider.getLanguage() <> gmfgen::GenLanguage::java-»
- «EXPAND xpt::Common::generatedMemberComment»
- private «container.getAbstractExpressionQualifiedClassName()» expression;
-
-«ENDIF-»
«EXPAND xpt::Common::generatedMemberComment»
public org.eclipse.core.runtime.IStatus validate(org.eclipse.emf.validation.IValidationContext ctx) {
«EXPAND constraintAdapter_initContext(self) FOR target-»
@@ -262,10 +257,7 @@ static boolean isInDefaultEditorContext(Object object) {
«DEFINE constraintAdapter_validateMethod(audit : gmfgen::GenAuditRule) FOR gmfgen::GenExpressionProviderBase»«ERROR 'No idea how to evaluate an audit rule for ' + self.repr()»«ENDDEFINE»
«DEFINE constraintAdapter_validateMethod(audit : gmfgen::GenAuditRule) FOR gmfgen::GenExpressionInterpreter-»
- if (expression == null) {
- expression = «EXPAND xpt::expressions::getExpression::getExpression(audit.rule, audit.target.getContext())»;
- }
- Object result = expression.evaluate(context);
+ Object result = «EXPAND xpt::expressions::getExpression::getExpression(audit.rule, audit.target.getContext())».evaluate(context);
if (result instanceof Boolean && ((Boolean) result).booleanValue()) {
return org.eclipse.core.runtime.Status.OK_STATUS;«REM»XXX why not ctx.createSuccessStatus()???«ENDREM»
}

Back to the top