summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorghillairet2012-05-15 11:38:12 (EDT)
committer mgolubev2012-05-15 11:38:12 (EDT)
commit6dcc5662534d94a15366c3ab7bfcf4d0ec80a5b5 (patch)
treec6ffcc661e5875460b0869c6d23573f93809f042
parent923a4ed696f15c092ea31c4817b5e4e59910b45e (diff)
downloadorg.eclipse.gmf-tooling-6dcc5662534d94a15366c3ab7bfcf4d0ec80a5b5.zip
org.eclipse.gmf-tooling-6dcc5662534d94a15366c3ab7bfcf4d0ec80a5b5.tar.gz
org.eclipse.gmf-tooling-6dcc5662534d94a15366c3ab7bfcf4d0ec80a5b5.tar.bz2
Moved GenParser creation to Parsers library
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto44
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto83
2 files changed, 86 insertions, 41 deletions
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto b/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto
index 6b6774b..a67238d 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto
@@ -93,12 +93,13 @@ mapping GMFMAP::LabelMapping::createLabelModelFacet(node: NeedsContainment) : GM
mapping GMFMAP::LabelMapping::createDefaultLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet
when {self.oclIsTypeOf(LabelMapping)}
{
- init {
- if auxParser = null then
- auxParser := object GMFGEN::ExternalParser {}
- endif;
- }
- parser := auxParser;
+-- init {
+-- if auxParser = null then
+-- auxParser := object GMFGEN::ExternalParser {}
+-- endif;
+-- }
+-- parser := auxParser;
+ parser := self.map createExternalParser();
}
mapping GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet(node: NeedsContainment) : GMFGEN::FeatureLabelModelFacet {
@@ -109,37 +110,20 @@ mapping GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet(node: NeedsCon
editorPattern := self.editorPattern;
viewMethod := self.viewMethod.convertLabelTextAccessMethod();
editMethod := self.editMethod.convertLabelTextAccessMethod();
-
-
--- var r := object GMFGEN::FeatureLabelModelFacet {};
--- if exists then select else
--- FIXME allInstances == hack
- var p = GMFGEN::PredefinedParser.allInstances()->any(pp |
- pp.viewMethod = result.oclAsType(FeatureLabelModelFacet).viewMethod and
- pp.editMethod = result.oclAsType(FeatureLabelModelFacet).editMethod);
-
- if p.oclIsUndefined() then p := object PredefinedParser {
- viewMethod := result.oclAsType(FeatureLabelModelFacet).viewMethod;
- editMethod := result.oclAsType(FeatureLabelModelFacet).editMethod;
- } endif;
- parser := p;
+ parser := if self.isEnumLabelMapping() then self.getOrCreateEnumParser() else self.getOrCreatePredefinedParser() endif;
}
mapping GMFMAP::DesignLabelMapping::createDesignLabelModelFacet(node: NeedsContainment) : GMFGEN::DesignLabelModelFacet {
- if designLabelParser = null then
- designLabelParser := object GMFGEN::ExternalParser {}
- endif;
- parser := designLabelParser;
+-- if designLabelParser = null then
+-- designLabelParser := object GMFGEN::ExternalParser {}
+-- endif;
+-- parser := designLabelParser;
+ parser := self.map createExternalParser();
}
mapping GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet(node: NeedsContainment): GMFGEN::ExpressionLabelModelFacet {
- parser := object ExpressionLabelParser {
- expressionContext := GENMODEL::GenClass.allInstances()->any(e | e.ecoreClass = self.mapEntry.getDomainContext());
- viewExpression := if not self.viewExpression.oclIsUndefined() then self.viewExpression.map createValueExpression() endif;
- editExpression := if not self.editExpression.oclIsUndefined() then self.editExpression.map createValueExpression() endif;
- validateExpression := if not self.validateExpression.oclIsUndefined() then self.validateExpression.map createConstraint() endif;
- };
+ parser := self.map createExpressionLabelParser();
}
mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet(node: NeedsContainment): GMFGEN::FeatureLabelModelFacet {
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto
index 9ce7819..ff331e4 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto
@@ -5,24 +5,38 @@ import ValueExpressions;
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
--
-- Parsers
--
-property designLabelParser: GenParserImplementation = null;
-property auxParser: GenParserImplementation = null;
-
mapping GMFMAP::Mapping::createGenParsers(): GenParsers {
- implementations += GMFGEN::GenParserImplementation.allInstances();
extensibleViaService := true;
+}
+
+mapping GMFMAP::LabelMapping::createExternalParser(): ExternalParser {
+ init {
+ var parser := GMFGEN::ExternalParser.allInstances()![ExternalParser];
+ result := if parser.oclIsUndefined() then object ExternalParser {} else parser endif;
+ }
- if this.designLabelParser <> null then
- implementations += this.designLabelParser
- endif;
- if this.auxParser <> null then
- implementations += this.auxParser
- endif;
+ if parser.oclIsUndefined() then
+ GMFMAP::Mapping.allInstances()![Mapping].map createGenParsers().implementations += result
+ endif
+}
+
+mapping GMFMAP::ExpressionLabelMapping::createExpressionLabelParser(): GMFGEN::ExpressionLabelParser {
+ init {
+ result := object GMFGEN::ExpressionLabelParser {
+ expressionContext := GENMODEL::GenClass.allInstances()->any(e | e.ecoreClass = self.mapEntry.getDomainContext());
+ viewExpression := if not self.viewExpression.oclIsUndefined() then self.viewExpression.map createValueExpression() endif;
+ editExpression := if not self.editExpression.oclIsUndefined() then self.editExpression.map createValueExpression() endif;
+ validateExpression := if not self.validateExpression.oclIsUndefined() then self.validateExpression.map createConstraint() endif;
+ }
+ }
+
+ GMFMAP::Mapping.allInstances()![Mapping].map createGenParsers().implementations += result;
}
mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceParser(): GMFGEN::OclChoiceParser {
@@ -33,9 +47,56 @@ mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceParser(): GMFGEN::OclChoic
result.showExpression := self.showExpression.map createValueExpression()
endif;
- GenEditorGenerator.allInstances()->asSequence()->first().labelParsers.implementations += result;
+ GMFMAP::Mapping.allInstances()![Mapping].map createGenParsers().implementations += result;
}
+helper GMFMAP::FeatureLabelMapping::getOrCreateEnumParser(): GMFGEN::PredefinedEnumParser =
+ let enumParser = findPredefinedEnumParser() in
+ if enumParser.oclIsUndefined() then
+ createPredefinedEnumParser()
+ else
+ enumParser
+ endif;
+
+helper findPredefinedEnumParser(): GMFGEN::PredefinedEnumParser =
+ GMFGEN::GenParserImplementation.allInstances()![GMFGEN::PredefinedEnumParser];
+
+helper createPredefinedEnumParser(): GMFGEN::PredefinedEnumParser {
+ var parser := object GMFGEN::PredefinedEnumParser {};
+ GMFMAP::Mapping.allInstances()![Mapping].map createGenParsers().implementations += parser;
+
+ return parser;
+}
+
+helper GMFMAP::FeatureLabelMapping::getOrCreatePredefinedParser(): GMFGEN::PredefinedParser =
+ let editMethod = self.editMethod.get() in
+ let viewMethod = self.viewMethod.get() in
+ let parser = findPredefinedParser(editMethod, viewMethod) in
+ if parser.oclIsUndefined() then
+ createPredefinedParser(editMethod, viewMethod)
+ else parser endif;
+
+helper findPredefinedParser(editMethod: GMFGEN::LabelTextAccessMethod, viewMethod: GMFGEN::LabelTextAccessMethod): GMFGEN::PredefinedParser =
+ GMFGEN::GenParserImplementation.allInstances()[GMFGEN::PredefinedParser]->any(e | e.editMethod = editMethod and e.viewMethod = viewMethod);
+
+helper createPredefinedParser(editMethod: GMFGEN::LabelTextAccessMethod, viewMethod: GMFGEN::LabelTextAccessMethod): GMFGEN::PredefinedParser {
+ var parser := object GMFGEN::PredefinedParser {};
+ parser.editMethod := editMethod;
+ parser.viewMethod := viewMethod;
+
+ GMFMAP::Mapping.allInstances()![Mapping].map createGenParsers().implementations += parser;
+
+ return parser;
+}
+
+helper GMFMAP::LabelTextAccessMethod::get(): GMFGEN::LabelTextAccessMethod =
+ switch {
+ case (self = GMFMAP::LabelTextAccessMethod::MESSAGE_FORMAT) GMFGEN::LabelTextAccessMethod::MESSAGE_FORMAT;
+ case (self = GMFMAP::LabelTextAccessMethod::NATIVE) GMFGEN::LabelTextAccessMethod::NATIVE;
+ case (self = GMFMAP::LabelTextAccessMethod::REGEXP) GMFGEN::LabelTextAccessMethod::REGEXP;
+ case (self = GMFMAP::LabelTextAccessMethod::PRINTF) GMFGEN::LabelTextAccessMethod::PRINTF;
+ };
+
helper GMFMAP::FeatureLabelMapping::isEnumLabelMapping(): Boolean =
if self.features->size() <> 1 then false else
if self.editableFeatures->isEmpty() or self.editableFeatures->size() > self.features->size() then false else