aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskovalsky2012-03-18 18:38:51 (EDT)
committermgolubev2012-03-18 18:38:51 (EDT)
commit03d3fff0d22260c8876a2fc8106ebe4ea292f155 (patch)
tree8946be17917999e31fb20a36546abb85825a1679
parent6ba37f8c65a3a68a52034ae28bf6cdac247e376f (diff)
downloadorg.eclipse.gmf-tooling-03d3fff0d22260c8876a2fc8106ebe4ea292f155.zip
org.eclipse.gmf-tooling-03d3fff0d22260c8876a2fc8106ebe4ea292f155.tar.gz
org.eclipse.gmf-tooling-03d3fff0d22260c8876a2fc8106ebe4ea292f155.tar.bz2
[374583] - OCL-choice parser: support in templates
-rw-r--r--plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/CodegenEmitters.java4
-rw-r--r--plugins/org.eclipse.gmf.codegen/src/org/eclipse/gmf/codegen/util/Generator.java1
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/ChoiceUtils.qvto42
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/EnumUtils.qvto17
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt62
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt38
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto35
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/parsers/PredefinedEnumParser.xpt81
-rw-r--r--[-rwxr-xr-x]plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/AbstractExpression.xpt0
-rw-r--r--[-rwxr-xr-x]plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt34
-rw-r--r--[-rwxr-xr-x]plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt0
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt14
12 files changed, 210 insertions, 118 deletions
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 3e568a2..9346b98 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
@@ -260,10 +260,6 @@ public class CodegenEmitters {
public TextEmitter getPredefinedParserEmitter() throws UnexpectedBehaviourException {
return newXpandEmitter("parsers::PredefinedParser::Main"); //$NON-NLS-1$
}
-
- public TextEmitter getPredefinedEnumParserEmitter() throws UnexpectedBehaviourException {
- return newXpandEmitter("parsers::PredefinedEnumParser::Main"); //$NON-NLS-1$
- }
public TextEmitter getCustomParserEmitter() throws UnexpectedBehaviourException {
return newXpandEmitter("parsers::CustomParser::Main"); //$NON-NLS-1$
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 b28cfc7..8b6f72c 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
@@ -508,7 +508,6 @@ public class Generator extends GeneratorBase implements Runnable {
doGenerateJavaClass(myEmitters.getPredefinedParserEmitter(), ((PredefinedParser) pi).getQualifiedClassName(), pi);
} else if (pi instanceof PredefinedEnumParser) {
needsAbstractParser = true;
- doGenerateJavaClass(myEmitters.getPredefinedEnumParserEmitter(), ((PredefinedEnumParser) pi).getQualifiedClassName(), pi);
} else if (pi instanceof CustomParser && ((CustomParser) pi).isGenerateBoilerplate()) {
doGenerateJavaClass(myEmitters.getCustomParserEmitter(), ((CustomParser) pi).getQualifiedName(), pi);
} else if (pi instanceof ExpressionLabelParser) {
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/ChoiceUtils.qvto b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/ChoiceUtils.qvto
new file mode 100644
index 0000000..3d4b45b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/ChoiceUtils.qvto
@@ -0,0 +1,42 @@
+modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
+modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
+
+library Utils;
+
+
+helper gmfgen::GenCommonBase::isOclChoiceLabel() : Boolean {
+ return let labelModelFacet : gmfgen::LabelModelFacet
+ = if self.oclIsKindOf(gmfgen::GenChildLabelNode) then self.oclAsType(gmfgen::GenChildLabelNode).labelModelFacet
+ else (if self.oclIsKindOf(gmfgen::GenLabel) then self.oclAsType(gmfgen::GenLabel).modelFacet
+ else null
+ endif)
+ endif
+ in (labelModelFacet <> null)
+ and labelModelFacet.parser.oclIsKindOf(gmfgen::OclChoiceParser);
+}
+
+helper gmfgen::GenCommonBase::isOclChoiceLabelWithShowExpr() : Boolean {
+ return let labelModelFacet : gmfgen::LabelModelFacet
+ = if self.oclIsKindOf(gmfgen::GenChildLabelNode) then self.oclAsType(gmfgen::GenChildLabelNode).labelModelFacet
+ else (if self.oclIsKindOf(gmfgen::GenLabel) then self.oclAsType(gmfgen::GenLabel).modelFacet
+ else null
+ endif)
+ endif
+ in (labelModelFacet <> null)
+ and labelModelFacet.parser.oclIsKindOf(gmfgen::OclChoiceParser)
+ and (labelModelFacet.parser.oclAsType(gmfgen::OclChoiceParser).showExpression <> null);
+}
+
+helper isChoiceLabel(modelFacet : gmfgen::LabelModelFacet) : Boolean {
+ return modelFacet.parser.oclIsKindOf(gmfgen::PredefinedEnumParser)
+ or modelFacet.parser.oclIsKindOf(gmfgen::OclChoiceParser);
+}
+
+helper getDirectManagerFQN(modelFacet : gmfgen::LabelModelFacet) : String {
+ return
+ (if isChoiceLabel(modelFacet) then
+ 'org.eclipse.gmf.runtime.diagram.ui.tools.ComboDirectEditManager'
+ else
+ 'org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager'
+ endif);
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/EnumUtils.qvto b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/EnumUtils.qvto
deleted file mode 100644
index 25e00b4..0000000
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/EnumUtils.qvto
+++ /dev/null
@@ -1,17 +0,0 @@
-modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
-modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
-
-library Utils;
-
-helper isEnumLabel(modelFacet : gmfgen::LabelModelFacet) : Boolean {
- return modelFacet.parser.oclIsKindOf(gmfgen::PredefinedEnumParser);
-}
-
-helper getDirectManagerFQN(modelFacet : gmfgen::LabelModelFacet) : String {
- return
- (if isEnumLabel(modelFacet) then
- 'org.eclipse.gmf.runtime.diagram.ui.tools.ComboDirectEditManager'
- else
- 'org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager'
- endif);
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
index 0b9a0ae..4e37261 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/diagram/editparts/TextAware.xpt
@@ -13,7 +13,8 @@
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«EXTENSION xpt::diagram::ViewmapAttributesUtils»
-«EXTENSION impl::diagram::editparts::EnumUtils»
+«EXTENSION impl::diagram::editparts::ChoiceUtils»
+«EXTENSION impl::parsers::expression»
«DEFINE fields FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
@@ -22,8 +23,13 @@
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.runtime.common.ui.services.parser.IParser parser;
+ «IF isOclChoiceLabel()-»
«EXPAND xpt::Common::generatedMemberComment»
- private «EXPAND CodeStyle::G('java.util.List', '?')» parserElements;
+ private «getActiveOclPackageName()».expressions.common.OclRegistrator myOclRegistrator;
+ «ELSE-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «EXPAND CodeStyle::G('java.util.List', '?')» parserElements;
+ «ENDIF-»
«EXPAND xpt::Common::generatedMemberComment»
private String defaultText;
@@ -73,7 +79,7 @@
«EXPAND performDirectEditAtPoint(modelFacet)-»
-«IF not(isEnumLabel(modelFacet))-»
+«IF not(isChoiceLabel(modelFacet))-»
«EXPAND performDirectEditWithInitialChar-»
«ENDIF»
@@ -98,6 +104,34 @@
«EXPAND getAccessibleEditPart-»
«EXPAND getFontStyleOwnerView(viewmap)-»
+
+ «IF isOclChoiceLabelWithShowExpr()-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «getActiveOclPackageName()».expressions.common.OclTracker getTracker() {
+ return ((«getActiveOclPackageName()».expressions.common.OclTrackerParser) getParser()).getOclTracker();
+ }
+ «ENDIF-»
+
+ «IF isOclChoiceLabel()-»
+ «EXPAND xpt::Common::generatedMemberComment»
+ private «getActiveOclPackageName()».expressions.common.OclRegistrator getOclRegistrator() {
+ if (myOclRegistrator == null) {
+ myOclRegistrator = new «getActiveOclPackageName()».expressions.common.OclRegistrator() {
+
+ @Override
+ public void registerListener(String filterId, org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener listener, org.eclipse.emf.ecore.EObject element) {
+ addListenerFilter(filterId, listener, element);
+ }
+
+ @Override
+ public void unregisterListener(String filterId) {
+ removeListenerFilter(filterId);
+ }
+ };
+ }
+ return myOclRegistrator;
+ }
+ «ENDIF-»
«ENDDEFINE»
«DEFINE labelSetterName FOR gmfgen::ParentAssignedViewmap-»
@@ -389,7 +423,7 @@
public void run() {
if (isActive() && isEditable()) {
- «IF not(isEnumLabel(modelFacet))-»
+ «IF not(isChoiceLabel(modelFacet))-»
if (theRequest.getExtendedData().get(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
Character initialChar = (Character) theRequest.getExtendedData().get(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
performDirectEdit(initialChar.charValue());
@@ -489,6 +523,16 @@
«DEFINE addSemanticListeners FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected void addSemanticListeners() {
+«IF isOclChoiceLabel()-»
+ «IF isOclChoiceLabelWithShowExpr()-»
+ «getActiveOclPackageName()».expressions.common.OclTracker tracker = getTracker();
+ tracker.initialize(resolveSemanticElement());
+ tracker.installListeners(getEditingDomain(), this, getOclRegistrator());
+ «ELSE-»
+ super.addSemanticListeners();
+ «ENDIF-»
+ ((«getRuntimePackageName()».parsers.OCLChoiceParser) getParser()).installListeners(this, getOclRegistrator());
+«ELSE-»
if (getParser() instanceof org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) {
org.eclipse.emf.ecore.EObject element = resolveSemanticElement();
parserElements = ((org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser) getParser()).getSemanticElementsBeingParsed(element);
@@ -498,12 +542,21 @@
} else {
super.addSemanticListeners();
}
+«ENDIF-»
}
«ENDDEFINE»
«DEFINE removeSemanticListeners FOR gmfgen::GenCommonBase-»
«EXPAND xpt::Common::generatedMemberComment»
protected void removeSemanticListeners() {
+«IF isOclChoiceLabel()-»
+ ((«getRuntimePackageName()».parsers.OCLChoiceParser) getParser()).uninstallListeners();
+ «IF isOclChoiceLabelWithShowExpr()-»
+ getTracker().uninstallListeners();
+ «ELSE-»
+ super.removeSemanticListeners();
+ «ENDIF-»
+«ELSE-»
if (parserElements != null) {
for (int i = 0; i < parserElements.size(); i++) {
removeListenerFilter("SemanticModel" + i); «EXPAND xpt::Common::nonNLS»
@@ -511,6 +564,7 @@
} else {
super.removeSemanticListeners();
}
+«ENDIF-»
}
«ENDDEFINE»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
index 56aacf6..b4eb4ee 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/ParserProvider.xpt
@@ -14,7 +14,9 @@
*/
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
+«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»
«EXTENSION xpt::providers::ParserUtils»
+«EXTENSION impl::parsers::expression»
«DEFINE accessorMethod_delegate2providers FOR gmfgen::GenParsers-»
«EXPAND xpt::Common::generatedMemberComment('Utility method that consults ParserService')»
@@ -150,6 +152,10 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
«EXPAND _doGetParser(element)-»
«ENDDEFINE»
+«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::OclChoiceParser»
+ «EXPAND _doGetParser(element)-»
+«ENDDEFINE»
+
«DEFINE _getParser(modelFacet : gmfgen::LabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::CustomParser-»
«EXPAND _doGetParser(element)-»
«ENDDEFINE»
@@ -196,6 +202,10 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
«EXPAND _predefinedParser(modelFacet, element)»
«ENDDEFINE»
+«DEFINE _parser(modelFacet : gmfgen::FeatureLabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::OclChoiceParser»
+ «EXPAND _predefinedParser(modelFacet, element)»
+«ENDDEFINE»
+
«DEFINE _predefinedParser(modelFacet : gmfgen::FeatureLabelModelFacet, element : gmfgen::GenCommonBase) FOR gmfgen::GenParserImplementation»
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.gmf.runtime.common.ui.services.parser.IParser «parserFieldName(element)»;
@@ -211,7 +221,7 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
«ENDDEFINE»
«DEFINE _createPredefinedParser(modelFacet : gmfgen::FeatureLabelModelFacet, parserVar : String) FOR gmfgen::GenParserImplementation»
- «ERROR 'PredefinedParser or PredefinedEnumParser expected but occured: ' + self.repr()»
+ «ERROR 'PredefinedParser, PredefinedEnumParser or OclChoiceParser expected but occured: ' + self.repr()»
«ENDDEFINE»
«DEFINE _createPredefinedParser(modelFacet : gmfgen::FeatureLabelModelFacet, parserVar : String) FOR gmfgen::PredefinedParser»
@@ -232,6 +242,32 @@ org.eclipse.gmf.runtime.common.ui.services.parser.ParserService.getInstance().ge
«getQualifiedClassName()» «parserVar» = new «getQualifiedClassName()»(editableFeature);
«ENDDEFINE»
+«DEFINE _createPredefinedParser(modelFacet : gmfgen::FeatureLabelModelFacet, parserVar : String) FOR gmfgen::OclChoiceParser»
+ «LET modelFacet.editableMetaFeatures->first() AS feature-»
+ org.eclipse.emf.ecore.EStructuralFeature editableFeature = «EXPAND MetaModel::MetaFeature FOR feature»;
+ «LET feature.genClass AS context-»
+ «getQualifiedClassName()» «parserVar» = new «getQualifiedClassName()»(editableFeature,
+ «IF itemsExpression = null-»
+ "«feature.ecoreFeature.oclAsType(ecore::EReference).eReferenceType.name».allInstances()"
+ «ELSE-»
+ «EXPAND xpt::expressions::getExpression::getExpressionBody FOR itemsExpression»
+ «ENDIF»,
+ «IF showExpression = null-»
+ null
+ «ELSE-»
+ «EXPAND xpt::expressions::getExpression::getExpressionBody FOR showExpression»
+ «ENDIF»,
+ «holder.editorGen.plugin.getActivatorQualifiedClassName()».getInstance().getItemProvidersAdapterFactory()
+ «IF showExpression <> null-»
+ , new «holder.getActiveOclPackageName()».parsers.«IF showExpression <> null and showExpression.body.startsWith('--IA')-»
+ ImpactAnalyzerTrackerFactory()
+ «ELSE-»
+ ActiveOclTrackerFactory()
+ «ENDIF-»
+ «ENDIF»);
+ «ENDLET-»
+ «ENDLET-»
+«ENDDEFINE»
«DEFINE _setPatterns(viewMethod : gmfgen::LabelTextAccessMethod, editMethod : gmfgen::LabelTextAccessMethod, parserVar : String) FOR gmfgen::FeatureLabelModelFacet-»
«IF viewMethod <> gmfgen::LabelTextAccessMethod::NATIVE-»
diff --git a/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto
new file mode 100644
index 0000000..7bb19be
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates/impl/parsers/expression.qvto
@@ -0,0 +1,35 @@
+modeltype gmfgen uses "http://www.eclipse.org/gmf/2009/GenModel";
+
+library expression;
+
+helper gmfgen::GenExpressionProviderBase::getActiveOclPackageName() : String {
+ return '/* [Error: call for the abstract method: gmfgen::GenExpressionProviderBase::getActiveOclPackageName] */';
+}
+
+helper gmfgen::GenExpressionInterpreter::getActiveOclPackageName() : String {
+ return self.container.getActiveOclPackageName();
+}
+
+helper gmfgen::GenExpressionProviderContainer::getActiveOclPackageName() : String {
+ return self.getRuntimePackageName() + '.ocl';
+}
+
+helper gmfgen::GenExpressionProviderContainer::getRuntimePackageName() : String {
+ return 'org.eclipse.gmf.tooling.runtime';
+}
+
+helper gmfgen::GenParsers::getActiveOclPackageName() : String {
+ return self.editorGen.expressionProviders.getActiveOclPackageName();
+}
+
+helper gmfgen::ExpressionLabelParser::getActiveOclPackageName() : String {
+ return self.viewExpression.provider.getActiveOclPackageName();
+}
+
+helper gmfgen::GenCommonBase::getActiveOclPackageName() : String {
+ return self.getDiagram().editorGen.expressionProviders.getActiveOclPackageName();
+}
+
+helper gmfgen::GenCommonBase::getRuntimePackageName() : String {
+ return self.getDiagram().editorGen.expressionProviders.getRuntimePackageName();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/parsers/PredefinedEnumParser.xpt b/plugins/org.eclipse.gmf.codegen/templates/parsers/PredefinedEnumParser.xpt
deleted file mode 100644
index 9afe7c0..0000000
--- a/plugins/org.eclipse.gmf.codegen/templates/parsers/PredefinedEnumParser.xpt
+++ /dev/null
@@ -1,81 +0,0 @@
-«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
-
-«DEFINE Main FOR gmfgen::PredefinedEnumParser»
-«EXPAND xpt::Common::copyright FOR holder.editorGen-»
-package «holder.implPackageName»;
-
-«EXPAND xpt::Common::generatedClassComment»
-public class EnumParser extends «EXPAND impl::parsers::AbstractParser::qualifiedClassName FOR holder» implements org.eclipse.gmf.runtime.diagram.ui.tools.ComboDirectEditManager.IChoiceParser {
-
- «EXPAND xpt::Common::generatedMemberComment»
- private static final int SINGLE_FEATURE_INDEX = 0;
-
- «EXPAND xpt::Common::generatedMemberComment»
- public EnumParser(org.eclipse.emf.ecore.EAttribute enumFeature) {
- super(new org.eclipse.emf.ecore.EAttribute[] { enumFeature });
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- @Override
- public String getEditString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
- org.eclipse.emf.ecore.EObject element = (org.eclipse.emf.ecore.EObject) adapter.getAdapter(org.eclipse.emf.ecore.EObject.class);
- return getEditChoice(getEditableValues(element)[SINGLE_FEATURE_INDEX].toString());
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- @Override
- public org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus isValidEditString(org.eclipse.core.runtime.IAdaptable element, String editString) {
- return getEditChoices().contains(editString) //
- ? org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus.EDITABLE_STATUS //
- : new org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus(org.eclipse.gmf.tests.ocl.model.oclTest.diagram.part.OclTestDiagramEditorPlugin.ID, org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus.UNEDITABLE, editString);
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- @Override
- public org.eclipse.gmf.runtime.common.core.command.ICommand getParseCommand(org.eclipse.core.runtime.IAdaptable adapter, String newString, int flags) {
- return getParseCommand(adapter, new Object[] { findChoiceValue(newString) }, flags);
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- @Override
- public String getPrintString(org.eclipse.core.runtime.IAdaptable adapter, int flags) {
- return getEditString(adapter, flags);
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- @Override
- public java.util.List<String> getEditChoices() {
- java.util.List<String> result = new java.util.ArrayList<String>();
- for (String literal : getLiterals()) {
- result.add(getEditChoice(literal));
- }
- return result;
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- private java.util.List<String> getLiterals() {
- java.util.List<String> result = new java.util.ArrayList<String>();
- org.eclipse.emf.ecore.EAttribute enumFeature = editableFeatures[SINGLE_FEATURE_INDEX];
- org.eclipse.emf.ecore.EEnum type = (org.eclipse.emf.ecore.EEnum) enumFeature.getEType();
- for (org.eclipse.emf.ecore.EEnumLiteral literal : type.getELiterals()) {
- result.add(literal.getLiteral());
- }
- return result;
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- private String findChoiceValue(String editChoice) {
- for (String literal : getLiterals()) {
- if (editChoice.equals(getEditChoice(literal))) {
- return literal;
- }
- }
- return null;
- }
-
- «EXPAND xpt::Common::generatedMemberComment»
- protected String getEditChoice(String literal) {
- return literal;
- }
-}
-«ENDDEFINE» \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/AbstractExpression.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/AbstractExpression.xpt
index 843def1..843def1 100755..100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/AbstractExpression.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/AbstractExpression.xpt
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 d4312d0..e0e7b72 100755..100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/OCLExpressionFactory.xpt
@@ -116,10 +116,31 @@ org.eclipse.ocl.options.ParsingOptions.setOption(«environmentVar», org.eclipse
«DEFINE _initInterpreterFactory FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::generatedMemberComment»
private final «container.getAbstractExpressionQualifiedClassName()»[] expressions;
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private final String [] expressionBodies;
«EXPAND xpt::Common::generatedMemberComment»
protected «className»() {
this.expressions = new «container.getAbstractExpressionQualifiedClassName()»[«expressions->size()»];
+ this.expressionBodies = new String[] {
+ «FOREACH expressions.getBodyString() AS b»«b», «EXPAND xpt::Common::nonNLS»
+ «ENDFOREACH-»
+ };
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ private static «className» getInstance() {
+ «className» instance = «EXPAND plugin::Activator::instanceAccess FOR container.editorGen».get«className»();
+ if (instance == null) {
+ «EXPAND plugin::Activator::instanceAccess FOR container.editorGen».set«className»(instance = new «className»());
+ }
+ return instance;
+ }
+
+ «EXPAND xpt::Common::generatedMemberComment»
+ public static String getExpressionBody(int index) {
+ return getInstance().expressionBodies[index];
}
«EXPAND xpt::Common::generatedMemberComment»
@@ -133,19 +154,12 @@ org.eclipse.ocl.options.ParsingOptions.setOption(«environmentVar», org.eclipse
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»());
- }
+ «className» cached = getInstance();
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, environment == null ? «EXPAND CodeStyle::emptyMap('String, org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» : environment);
+ if (cached.expressions[index] == null) {
+ cached.expressions[index] = getExpression(cached.expressionBodies[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/RegexpExpressionFactory.xpt b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
index a42c198..a42c198 100755..100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/RegexpExpressionFactory.xpt
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 ee20b2a..b2e0b1c 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
+++ b/plugins/org.eclipse.gmf.codegen/templates/xpt/expressions/getExpression.xpt
@@ -13,6 +13,20 @@
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/GenModel'»
+
+«DEFINE getExpressionBody FOR gmfgen::ValueExpression-»
+«EXPAND getExpressionBody(self) FOR provider»
+«ENDDEFINE»
+
+«DEFINE getExpressionBody(gmfgen::ValueExpression valueExpr) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: getExpression'»«ENDDEFINE»
+
+«DEFINE getExpressionBody(gmfgen::ValueExpression valueExpr) FOR gmfgen::GenExpressionInterpreter-»
+«getQualifiedClassName()».getExpressionBody(«expressions->indexOf(valueExpr) - 1»)«-»
+«ENDDEFINE»
+
+
+«DEFINE getExpression(gmfgen::ValueExpression valueExpr, genmodel::GenClassifier context) FOR gmfgen::GenExpressionProviderBase»«ERROR 'Abstract template call: getExpression'»«ENDDEFINE»
+
«DEFINE getExpression(gmfgen::ValueExpression valueExpr, genmodel::GenClassifier context) FOR gmfgen::GenExpressionInterpreter-»
«EXPAND getExpression(valueExpr, context, 'null')-»
«ENDDEFINE»