aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorghillairet2012-05-09 10:04:41 (EDT)
committermgolubev2012-05-09 10:04:41 (EDT)
commit9416caef7b3e7a6ed0b583880367a4b1acdc0d8f (patch)
treea72065fd6b67f0e65f284e4cbf7668cd69476dc3
parent79a451c9d5e5e33e8e465bc634b4d3805625efdb (diff)
downloadorg.eclipse.gmf-tooling-9416caef7b3e7a6ed0b583880367a4b1acdc0d8f.zip
org.eclipse.gmf-tooling-9416caef7b3e7a6ed0b583880367a4b1acdc0d8f.tar.gz
org.eclipse.gmf-tooling-9416caef7b3e7a6ed0b583880367a4b1acdc0d8f.tar.bz2
Refactoring qvto bridge, modularize transformations by using libraries.
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Audits.qvto169
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/DiagramRunTimeModel.qvto4
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto2
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto158
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto722
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Map2GenUtil.qvto180
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Mappings.qvto271
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto215
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/ModeledViewmaps.qvto16
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Palette.qvto137
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto46
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/ValueExpressions.qvto76
-rw-r--r--plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto27
13 files changed, 1051 insertions, 972 deletions
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Audits.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Audits.qvto
new file mode 100644
index 0000000..ce46812
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Audits.qvto
@@ -0,0 +1,169 @@
+/**
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
+library Audits;
+
+import Map2GenUtil;
+import Mappings;
+import gmf.GenModelAccess;
+
+modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
+modeltype GMFTOOL uses tooldef('http://www.eclipse.org/gmf/2005/ToolDefinition');
+modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
+modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition');
+modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
+
+--
+-- Audits
+--
+
+mapping GMFMAP::AuditContainer::audits() : GMFGEN::GenAuditRoot {
+ result.categories += self.allContainers().map category();
+ result.rules += self.allContainers().audits.map rule();
+
+ var allRulesWithContext := result.rules->select(not target.oclIsUndefined());
+ var rulesWithDiagramElementTarget := allRulesWithContext->select(target.oclIsTypeOf(GMFGEN::GenDiagramElementTarget));
+ rulesWithDiagramElementTarget.target[GMFGEN::GenDiagramElementTarget]->forEach(t) {
+ -- Basically, all rules with targets != null
+ -- get a context (emf.validation), which is a scope or set of elements audit is evaluated against.
+ -- For certain cases, e.g. diagram elements as audit targets, special logic to select these
+ -- elements should get generated - to filter diagram views by visualID, and hence
+ -- there's another implementation of IClientSelector and dedicated context.
+ var ctx : GMFGEN::GenAuditContext;
+ -- use of exists seems to be sufficient, as all ruleTargets for a given context should get same elements
+ -- by the nature of construction. However, more honest way would be to use forAll, accompanied with not isEmpty():
+ -- not cc.ruleTargets[GMFGEN::GenDiagramElementTarget]->isEmpty() and cc.ruleTargets[...]->forAll(element = t.element)
+ ctx := result.clientContexts->selectOne(cc | cc.ruleTargets[GMFGEN::GenDiagramElementTarget]->exists(element = t.element));
+ -- there might be already a context to pick same elements this target has
+ if ctx.oclIsUndefined() then {
+ ctx := object GMFGEN::GenAuditContext {
+ id := t.element.visualID.repr()->asList()->joinfields('_','Ctx_','')
+ };
+ result.clientContexts += ctx;
+ } endif;
+ t.contextSelector := ctx;
+ };
+ var defaultAuditContext := object GMFGEN::GenAuditContext {};
+ result.clientContexts += defaultAuditContext;
+ (allRulesWithContext - rulesWithDiagramElementTarget).target->forEach(t) { t.contextSelector := defaultAuditContext };
+}
+
+mapping GMFMAP::AuditContainer::category() : GMFGEN::GenAuditContainer {
+ id := self.id;
+ name := self.name;
+ description := self.description;
+ path += self.parentContainer.resolveone(GMFGEN::GenAuditContainer).path;
+ -- alternative, not sure which one is better:
+ -- path += self.parentContainer.map category().path;
+ path += result;
+}
+
+mapping GMFMAP::AuditRule::rule() : GMFGEN::GenAuditRule {
+ id := self.id;
+ name := self.name;
+ message := self.message;
+ description := self.description;
+ useInLiveMode := self.useInLiveMode;
+ target := self.target.map auditTarget();
+ rule := self.rule.map createConstraint();
+ severity := self.severity.severity();
+ category := self.container.map category();
+}
+
+mapping GMFMAP::Auditable::auditTarget() : GMFGEN::GenAuditable
+ disjuncts
+ GMFMAP::DomainElementTarget::ruleTarget,
+ GMFMAP::NotationElementTarget::ruleTarget,
+ GMFMAP::DiagramElementTarget::ruleTarget,
+ GMFMAP::AuditedMetricTarget::ruleTarget,
+ GMFMAP::DomainAttributeTarget::ruleTarget
+ {} --assert (false) with log ('Unknown rule target', self);
+
+mapping GMFMAP::DomainElementTarget::ruleTarget() : GMFGEN::GenDomainElementTarget {
+ element := self.element.findGenClass();
+}
+
+mapping GMFMAP::NotationElementTarget::ruleTarget() : GMFGEN::GenNotationElementTarget {
+ element := self.element.findGenClass(); -- XXX double-check if domain's genmodel should be consulted here, not notation's
+}
+
+mapping GMFMAP::DiagramElementTarget::ruleTarget() : GMFGEN::GenDiagramElementTarget {
+ -- alternatives:
+ if self.element.oclIsKindOf(LinkMapping) then {
+ element += self.element.oclAsType(LinkMapping).map structure();
+ } else if self.element.oclIsKindOf(NodeMapping) then {
+ var el := self.element.container();
+ if el.oclIsKindOf(TopNodeReference) then
+ element += el.oclAsType(TopNodeReference).map structure()
+ else
+ element += el.oclAsType(ChildReference).map structure(self.element.oclAsType(NodeMapping))
+ endif
+ } endif
+ endif;
+-- element += self.element.resolveIn(GMFMAP::NodeMapping::structure, GMFGEN::GenCommonBase);
+-- element += self.element.resolveIn(GMFMAP::LinkMapping::structure, GMFGEN::GenCommonBase);
+-- element += self.element.resolveIn(GMFMAP::TopNodeReference::structure, GMFGEN::GenCommonBase);
+-- element += self.element.resolve(GMFGEN::GenCommonBase);
+}
+
+mapping GMFMAP::AuditedMetricTarget::ruleTarget() : GMFGEN::GenAuditedMetricTarget {
+ result.metric := self.metric.map rule();
+ var resultClassifier := loadEcoreGenModel().genPackages->first().genClassifiers[GENMODEL::GenDataType]->selectOne(ecoreDataType.name='EDoubleObject');
+ assert (not resultClassifier.oclIsUndefined()) with log ('Troubles loading ecore.genmodel and accessing EDoubleObject');
+ result.metricValueContext := resultClassifier;
+}
+
+mapping GMFMAP::DomainAttributeTarget::ruleTarget() : GMFGEN::GenDomainAttributeTarget {
+ attribute := self.attribute.findGenFeature();
+ nullAsError := self.nullAsError;
+}
+
+--
+-- Metrics
+--
+
+mapping GMFMAP::MetricContainer::metrics() : GMFGEN::GenMetricContainer {
+ metrics += self.metrics.map rule();
+}
+
+mapping GMFMAP::MetricRule::rule() : GMFGEN::GenMetricRule {
+ key := self.key;
+ name := self.name;
+ description := self.description;
+ lowLimit := self.lowLimit;
+ highLimit := self.highLimit;
+ rule := self.rule.map createValueExpression();
+ target := self.target.map metricTarget();
+}
+
+mapping GMFMAP::Measurable::metricTarget() : GMFGEN::GenMeasurable
+ disjuncts
+ GMFMAP::DomainElementTarget::ruleTarget,
+ GMFMAP::NotationElementTarget::ruleTarget,
+ GMFMAP::DiagramElementTarget::ruleTarget
+ {} --assert (false) with log ('Unknown rule target', self);
+
+--
+-- Queries
+--
+
+query GMFMAP::AuditContainer::allContainers() : Sequence(GMFMAP::AuditContainer) =
+ self.childContainers.allContainers()->flatten()->prepend(self);
+
+query GMFMAP::Severity::severity() : GMFGEN::GenSeverity =
+ switch {
+ case (self = GMFMAP::Severity::INFO) return GMFGEN::GenSeverity::INFO;
+ case (self = GMFMAP::Severity::WARNING) return GMFGEN::GenSeverity::WARNING;
+ case (self = GMFMAP::Severity::ERROR) return GMFGEN::GenSeverity::ERROR;
+ else return null;
+ };
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/DiagramRunTimeModel.qvto b/plugins/org.eclipse.gmf.bridge/transforms/DiagramRunTimeModel.qvto
index e69055f..259a060 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/DiagramRunTimeModel.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/DiagramRunTimeModel.qvto
@@ -18,13 +18,13 @@ transformation DiagramRunTimeModel(in diagramRuntimeGenModel : GENMODEL, inout g
main() {
var genModel = diagramRuntimeGenModel.rootObjects()![GENMODEL::GenModel];
var genEditor = gmfgenModel.rootObjects()![GMFGEN::GenEditorGenerator];
- --
+
var notationPackage = genModel.genPackages[ecorePackage.name = 'notation'];
var nodeClass : GENMODEL::GenClass = notationPackage.genClasses![ecoreClass.name = 'Node'];
var linkClass : GENMODEL::GenClass = notationPackage.genClasses![ecoreClass.name = 'Edge'];
var diagramClass : GENMODEL::GenClass = notationPackage.genClasses![ecoreClass.name = 'Diagram'];
var labelClass : GENMODEL::GenClass = nodeClass;
- --
+
var gd = genEditor.diagram;
gd.diagramRunTimeClass := diagramClass;-- Notation.Diagram;
genEditor.diagram.getAllNodes()->forEach(n) { n.diagramRunTimeClass := nodeClass };
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
index 282379c..257025d 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Identity.qvto
@@ -10,7 +10,7 @@
* Artem Tikhomirov (Borland) - initial API and implementation
* Guillaume Hillairet (Montages A.G.)
*/
-import Map2GenMappings;
+import Mappings;
import gmf.VisualIdentifierDispenser;
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
index 04660b9..dec9086 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Map2Gen.qvto
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2009 Borland Software Corporation & others
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,7 +11,7 @@
* Guillaume Hillairet (Montages A.G.)
*/
import Map2GenUtil;
-import Map2GenMappings;
+import Mappings;
import DiagramRunTimeModel;
import PropertySheet;
import PreferencePages;
@@ -21,7 +21,8 @@ import RichClientPlatformApp;
import Viewmaps;
import ModeledViewmaps;
import Identity;
-
+import Audits;
+import Parsers;
import gmf.GenModelAccess;
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
@@ -31,34 +32,37 @@ modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefin
modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
-transformation Map2Gen(in mapModel: GMFMAP, in domainGenModel: GENMODEL, in diagramRuntimeGenModel: GENMODEL, out gmfgenModel: GMFGEN)
-access Map2GenUtil;
+transformation Map2Gen(
+ in mapModel: GMFMAP,
+ in domainGenModel: GENMODEL,
+ in diagramRuntimeGenModel: GENMODEL,
+ out gmfgenModel: GMFGEN);
-configuration property rcp : Boolean;
-configuration property useMapMode : Boolean;
-configuration property useFullRunTime : Boolean;
-configuration property useInTransformationCodeGen : Boolean;
+configuration property rcp: Boolean;
+configuration property useMapMode: Boolean;
+configuration property useFullRunTime: Boolean;
+configuration property useInTransformationCodeGen: Boolean;
main() {
- mapRoot := mapModel.rootObjects()![GMFMAP::Mapping];
+ var mapRoot := mapModel.rootObjects()![GMFMAP::Mapping];
genModel := domainGenModel.rootObjects()![GENMODEL::GenModel];
childReferences := mapRoot.getChildReferences();
Viewmaps::setMapMode(useMapMode);
var genEditor := mapRoot.map structure();
-
genEditor.diagram.palette := mapRoot.diagram.map palette();
genEditor.domainGenModel := mapRoot.diagram.domainModel.findGenPackage().genModel;
-
genEditor.plugin := mapRoot.map editorPlugin();
genEditor.editor := object GenEditorView {};
mapRoot.visualIdentity(); -- generate visual IDs for each node.
+
if useInTransformationCodeGen then
Viewmaps::viewmaps(mapRoot, genEditor.diagram) -- adds viewmaps to each nodes.
else
ModeledViewmaps::viewmaps(mapRoot, genEditor.diagram) -- adds modeledViewmaps to each nodes.
endif;
+
genEditor.diagramUpdater := object GenDiagramUpdater {};
genEditor.audits := mapRoot.audits.map audits(); -- these two should go before expression providers collection
genEditor.metrics := mapRoot.metrics.map metrics();
@@ -78,135 +82,9 @@ main() {
if rcp then new RichClientPlatformApp(mapModel, gmfgenModel).transform() endif;
}
--- *************************************************************************************
--- Audits
--- *************************************************************************************
-mapping GMFMAP::AuditContainer::audits() : GMFGEN::GenAuditRoot {
- result.categories += self.allContainers().map category();
- result.rules += self.allContainers().audits.map rule();
-
- var allRulesWithContext := result.rules->select(not target.oclIsUndefined());
- var rulesWithDiagramElementTarget := allRulesWithContext->select(target.oclIsTypeOf(GMFGEN::GenDiagramElementTarget));
- rulesWithDiagramElementTarget.target[GMFGEN::GenDiagramElementTarget]->forEach(t) {
- -- Basically, all rules with targets != null
- -- get a context (emf.validation), which is a scope or set of elements audit is evaluated against.
- -- For certain cases, e.g. diagram elements as audit targets, special logic to select these
- -- elements should get generated - to filter diagram views by visualID, and hence
- -- there's another implementation of IClientSelector and dedicated context.
- var ctx : GMFGEN::GenAuditContext;
- -- use of exists seems to be sufficient, as all ruleTargets for a given context should get same elements
- -- by the nature of construction. However, more honest way would be to use forAll, accompanied with not isEmpty():
- -- not cc.ruleTargets[GMFGEN::GenDiagramElementTarget]->isEmpty() and cc.ruleTargets[...]->forAll(element = t.element)
- ctx := result.clientContexts->selectOne(cc | cc.ruleTargets[GMFGEN::GenDiagramElementTarget]->exists(element = t.element));
- -- there might be already a context to pick same elements this target has
- if ctx.oclIsUndefined() then {
- ctx := object GMFGEN::GenAuditContext {
- id := t.element.visualID.repr()->asList()->joinfields('_','Ctx_','')
- };
- result.clientContexts += ctx;
- } endif;
- t.contextSelector := ctx;
- };
- var defaultAuditContext := object GMFGEN::GenAuditContext {};
- result.clientContexts += defaultAuditContext;
- (allRulesWithContext - rulesWithDiagramElementTarget).target->forEach(t) { t.contextSelector := defaultAuditContext };
-
-}
-query GMFMAP::AuditContainer::allContainers() : Sequence(GMFMAP::AuditContainer) {
- var nested := self.childContainers.allContainers()->flatten();
- return nested->prepend(self);
-}
-mapping GMFMAP::AuditContainer::category() : GMFGEN::GenAuditContainer {
- id := self.id;
- name := self.name;
- description := self.description;
- path += self.parentContainer.resolveone(GMFGEN::GenAuditContainer).path;
- -- alternative, not sure which one is better:
- -- path += self.parentContainer.map category().path;
- path += result;
-}
-mapping GMFMAP::AuditRule::rule() : GMFGEN::GenAuditRule {
- id := self.id;
- name := self.name;
- message := self.message;
- description := self.description;
- useInLiveMode := self.useInLiveMode;
- target := self.target.map auditTarget();
- rule := self.rule.map createConstraint();
- severity := self.severity.severity();
- category := self.container.map category();
-}
-mapping GMFMAP::Auditable::auditTarget() : GMFGEN::GenAuditable
- disjuncts GMFMAP::DomainElementTarget::ruleTarget, GMFMAP::NotationElementTarget::ruleTarget, GMFMAP::DiagramElementTarget::ruleTarget,
- GMFMAP::AuditedMetricTarget::ruleTarget, GMFMAP::DomainAttributeTarget::ruleTarget
- {} --assert (false) with log ('Unknown rule target', self);
-mapping GMFMAP::DomainElementTarget::ruleTarget() : GMFGEN::GenDomainElementTarget {
- element := self.element.findGenClass();
-}
-mapping GMFMAP::NotationElementTarget::ruleTarget() : GMFGEN::GenNotationElementTarget {
- element := self.element.findGenClass(); -- XXX double-check if domain's genmodel should be consulted here, not notation's
-}
-mapping GMFMAP::DiagramElementTarget::ruleTarget() : GMFGEN::GenDiagramElementTarget {
- -- alternatives:
- if self.element.oclIsKindOf(LinkMapping) then {
- element += self.element.oclAsType(LinkMapping).map structure();
- } else if self.element.oclIsKindOf(NodeMapping) then {
- var el := self.element.container();
- if el.oclIsKindOf(TopNodeReference) then
- element += el.oclAsType(TopNodeReference).map structure()
- else
- element += el.oclAsType(ChildReference).map structure(self.element.oclAsType(NodeMapping))
- endif
- } endif
- endif;
--- element += self.element.resolveIn(GMFMAP::NodeMapping::structure, GMFGEN::GenCommonBase);
--- element += self.element.resolveIn(GMFMAP::LinkMapping::structure, GMFGEN::GenCommonBase);
--- element += self.element.resolveIn(GMFMAP::TopNodeReference::structure, GMFGEN::GenCommonBase);
--- element += self.element.resolve(GMFGEN::GenCommonBase);
-}
-mapping GMFMAP::AuditedMetricTarget::ruleTarget() : GMFGEN::GenAuditedMetricTarget {
- result.metric := self.metric.map rule();
- var resultClassifier := loadEcoreGenModel().genPackages->first().genClassifiers[GENMODEL::GenDataType]->selectOne(ecoreDataType.name='EDoubleObject');
- assert (not resultClassifier.oclIsUndefined()) with log ('Troubles loading ecore.genmodel and accessing EDoubleObject');
- result.metricValueContext := resultClassifier;
-}
-mapping GMFMAP::DomainAttributeTarget::ruleTarget() : GMFGEN::GenDomainAttributeTarget {
- attribute := self.attribute.findGenFeature();
- nullAsError := self.nullAsError;
-}
-
-query GMFMAP::Severity::severity() : GMFGEN::GenSeverity {
- switch {
- case (self = GMFMAP::Severity::INFO) return GMFGEN::GenSeverity::INFO;
- case (self = GMFMAP::Severity::WARNING) return GMFGEN::GenSeverity::WARNING;
- case (self = GMFMAP::Severity::ERROR) return GMFGEN::GenSeverity::ERROR;
- };
- assert (false) with log ('Unrecognized Severity::* value', self);
- return null;
-}
-
--- *************************************************************************************
--- Metrics
--- *************************************************************************************
-mapping GMFMAP::MetricContainer::metrics() : GMFGEN::GenMetricContainer {
- metrics += self.metrics.map rule();
-}
-mapping GMFMAP::MetricRule::rule() : GMFGEN::GenMetricRule {
- key := self.key;
- name := self.name;
- description := self.description;
- lowLimit := self.lowLimit;
- highLimit := self.highLimit;
- rule := self.rule.map createValueExpression();
- target := self.target.map metricTarget();
-}
-mapping GMFMAP::Measurable::metricTarget() : GMFGEN::GenMeasurable
- disjuncts GMFMAP::DomainElementTarget::ruleTarget, GMFMAP::NotationElementTarget::ruleTarget, GMFMAP::DiagramElementTarget::ruleTarget
- {} --assert (false) with log ('Unknown rule target', self);
-
--- *************************************************************************************
+--
-- Editor Plugin
--- *************************************************************************************
+--
mapping GMFMAP::Mapping::editorPlugin() : GMFGEN::GenPlugin {
requiredPlugins := Set{'org.eclipse.draw2d'};
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto
deleted file mode 100644
index 1a2bc09..0000000
--- a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenMappings.qvto
+++ /dev/null
@@ -1,722 +0,0 @@
-/**
- * Copyright (c) 2009 Borland Software Corporation & 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
- * Guillaume Hillairet (Montages A.G.)
- */
-import Map2GenUtil;
-
-library Map2GenMappings;
-
-modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
-modeltype GMFTOOL uses tooldef('http://www.eclipse.org/gmf/2005/ToolDefinition');
-modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
-modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition');
-modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
-modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
-
-property mapRoot : GMFMAP::Mapping = null;
-
-mapping GMFMAP::Mapping::structure() : GMFGEN::GenEditorGenerator {
- diagram := self.diagram.map structure();
-
- diagram.topLevelNodes += self.nodes->map structure()->asOrderedSet();
- childReferences->forEach(c) { diagram.childNodes += c.map structure(c.child); };
-
- diagram.links := self.links->map structure()->asOrderedSet();
- self.getCompartments()->forEach(e) { diagram.compartments += e.c.map structure(e.n, e.r); };
-
- diagram.getAllNodes()->forEach(n) { setupElementType(n) };
- diagram.links->forEach(l) { setupElementType(l) };
-
- if self.expressionsByLanguages()->notEmpty() then
- expressionProviders := self.map createProviderContainer()
- endif;
-}
-
-query GMFMAP::Mapping::expressionsByLanguages(): Sequence(ValueExpression) {
- return GMFMAP::ValueExpression.allInstances()->iterate(it; res: Sequence(ValueExpression) = Sequence{} |
- if res->exists(e | e.language = it.language) then res else res->including(it) endif
- )
-}
-mapping GMFMAP::Mapping::createProviderContainer(): GMFGEN::GenExpressionProviderContainer {
- self.expressionsByLanguages()->forEach(e) {
- providers += e.map createExpressionProvider()
- }
-}
-
-mapping GMFMAP::CanvasMapping::structure() : GMFGEN::GenDiagram {
- domainDiagramElement := self.domainMetaElement.findGenClass();
- iconProviderPriority := GMFGEN::ProviderPriority::Low;
- validationProviderPriority := GMFGEN::ProviderPriority::Low;
-
- if result.domainDiagramElement.oclIsUndefined() then
- result.elementType := object GMFGEN::NotationType {}
- else
- result.elementType := result.domainDiagramElement.getOrCreateRuntimeMetamodelType()
- endif;
-}
-
--- *************************************************************************************
--- TopLevelNode
--- *************************************************************************************
-
-mapping GMFMAP::TopNodeReference::structure() : GMFGEN::GenTopLevelNode {
- modelFacet := self.createModelFacet();
- self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
-
- self.child.children->select(e | e.compartment.oclIsUndefined())->forEach(c) {
- var node := c.findProcessableChildReference();
- childNodes += node.map structure(node.child);
- };
-
- labels += self.child.labelMappings->map createNodeLabel(self);
-
--- viewmap := self.child.diagramNode.viewmap();
- behaviour += self.child.relatedDiagrams.handleRelatedDiagram(self.child);
-}
-
--- *************************************************************************************
--- GenChildNode
--- *************************************************************************************
-
-mapping GMFMAP::ChildReference::structure(node: GMFMAP::NodeMapping) : GMFGEN::GenChildNode
- disjuncts
- GMFMAP::ChildReference::createGenChildLabelNode,
- GMFMAP::ChildReference::createGenChildSideAffixedNode,
- GMFMAP::ChildReference::createGenChildNode
-{}
-
-mapping GMFMAP::ChildReference::createGenChildLabelNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildLabelNode
- when { node.isPureLabelNode() } {
-
- var soleLabel := node.labelMappings->first();
- labelModelFacet := soleLabel.map createLabelModelFacet(self);
- labelReadOnly := soleLabel.readOnly;
- labelElementIcon := soleLabel.diagramLabel.elementIcon;
--- viewmap := soleLabel.diagramLabel.viewmap();
-
- self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
- var node := c.findProcessableChildReference();
- childNodes += node.map structure(node.child);
- };
-
- modelFacet := self.createModelFacet();
-
- self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
-}
-mapping GMFMAP::ChildReference::createGenChildSideAffixedNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildSideAffixedNode
- when { node.diagramNode.affixedParentSide <> GMFGRAPH::Direction::NONE} {
-
--- viewmap := node.diagramNode.viewmap();
- preferredSideName := node.diagramNode.getAffixedSideAsPositionConstantsName();
-
- labels += node.labelMappings->map createNodeLabel(self);
-
- self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
- var node := c.findProcessableChildReference();
- childNodes += node.map structure(node.child);
- };
-
- behaviour += node.relatedDiagrams.handleRelatedDiagram(node);
- modelFacet := self.createModelFacet();
- self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
-}
-mapping GMFMAP::ChildReference::createGenChildNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildNode {
--- viewmap := node.diagramNode.viewmap();
-
- labels += node.labelMappings->map createNodeLabel(self);
-
- self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
- var node := c.findProcessableChildReference();
- childNodes += node.map structure(node.child);
- };
-
- behaviour += node.relatedDiagrams.handleRelatedDiagram(node);
- modelFacet := self.createModelFacet();
-
- self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
-
- behaviour += node.visualEffects->map createVisualEffects(result, _node);
-}
-
-helper GMFGRAPH::DiagramElement::getOperationName(pin: GMFGRAPH::Pin): String =
- if not self.figure.actualFigure.hasFigurePin(pin) then
- let graphChildAccess = self.figure.accessors->any(_ | _.figure.hasFigurePin(pin)) in
- if graphChildAccess.oclIsUndefined() then
- pin.getOperationName()
- else
- graphChildAccess.accessor + "()." + pin.getOperationName()
- endif
- else pin.getOperationName() endif;
-
-helper GMFGRAPH::Figure::hasFigurePin(pin: GMFGRAPH::Pin): Boolean =
- let realFigure =
- if self.oclIsTypeOf(FigureRef) then
- self.oclAsType(FigureRef).figure
- else self.oclAsType(RealFigure) endif
- in realFigure.pins->includes(pin);
-
-mapping GMFMAP::VisualEffectMapping::createVisualEffects(parent: GMFGEN::GenNode, _mapping: GMFMAP::NodeMapping): GMFGEN::GenVisualEffect {
- name := self.diagramPin.name;
- pinKind := self.diagramPin.oclAsType(EObject).eClass().name;
- operationName := self.diagramPin.getOperationName();
- operationType := self.diagramPin.getOperationType();
- oclExpression := self.oclExpression;
-
- -- TODO: need visualID
--- editPolicyQualifiedClassName := parent.getDiagram().editPoliciesPackageName + '.' +
--- self.diagramPin.name.firstToUpper() +
--- key :=
-}
-
-mapping GMFMAP::LinkMapping::structure() : GMFGEN::GenLink {
- assert(not self.diagramLink.oclIsUndefined()) with log("link diagram link cannot be null");
- if not self.domainMetaElement.oclIsUndefined() then
- assert(not self.linkMetaFeature.oclIsUndefined()) with log("linkMetaFeature cannot be null")
- endif;
-
- -- model facet
- if not (self.domainMetaElement.oclIsUndefined() and self.linkMetaFeature.oclIsUndefined()) then
- modelFacet := self.map createModelFacet()
- endif;
-
- -- labels
- labels += self.labelMappings->map structure(self);
-
- self.tool.map paletteEntry().oclAsType(ToolEntry).genLinks += result;
- -- setupElementType(result);
--- result.viewmap := self.diagramLink.viewmap();
- result.creationConstraints := self.creationConstraints.map structure();
-}
-
-mapping LabelMapping::structure(link: GMFMAP::LinkMapping): GenLinkLabel {
- readOnly := self.readOnly;
- elementIcon := self.diagramLabel.elementIcon;
- modelFacet := self.map createLabelModelFacet(link);
- var alignmentFacet := self.diagramLabel.findAlignmentFacet();
- if not alignmentFacet.oclIsUndefined() then
- alignment := switch {
- case (alignmentFacet.alignment = GMFGRAPH::Alignment::BEGINNING) LinkLabelAlignment::SOURCE;
- case (alignmentFacet.alignment = GMFGRAPH::Alignment::CENTER) LinkLabelAlignment::MIDDLE;
- case (alignmentFacet.alignment = GMFGRAPH::Alignment::END) LinkLabelAlignment::TARGET;
- else LinkLabelAlignment::MIDDLE;
- }
- endif;
--- viewmap := self.diagramLabel.viewmap();
--- viewmap.attributes += object LabelOffsetAttributes {
--- var offsetFacet := self.diagramLabel.findOffsetFacet();
--- if not offsetFacet.oclIsUndefined() then {
--- x := offsetFacet.x;
--- y := offsetFacet.y;
--- } else {
--- y := (link.labelMappings->indexOf(self) + 1) * 20;
--- } endif;
--- }
-}
-
--- *************************************************************************************
--- Compartment
--- *************************************************************************************
-
-mapping GMFMAP::CompartmentMapping::structure(_mapping: GMFMAP::NodeMapping, container: GMFMAP::NodeReference): GMFGEN::GenCompartment {
- init {
- result := object GMFGEN::GenCompartment {
- canCollapse := self.compartment.collapsible;
- needsTitle := self.compartment.needsTitle;
- title := self.compartment.name;
--- viewmap := self.compartment.viewmap();
- };
- }
-
- if container.oclIsKindOf(GMFMAP::TopNodeReference) then
- container.resolveone(GMFGEN::GenNode).compartments += result
- else {
- var node := container.oclAsType(ChildReference).findProcessableChildReference();
- if not node.oclIsUndefined() then
- node.map structure(node.child).compartments += result
- endif
- } endif;
-
- allChildReferences->select(e | e.compartment = self)->forEach(c) {
- if c.child.children->size() > 0 then
- listLayout := false
- endif;
- var node := c.findProcessableChildReference();
- -- if equivalentChild->hasKey(c) then c else
- -- equivalentChild->keys()->selectOne(e | equivalentChild->get(e)->includes(c)) endif;
- childNodes += node.map structure(node.child);
- }
-}
-
-helper GMFMAP::NodeReference::createModelFacet() : GMFGEN::TypeModelFacet {
- if self.child.domainMetaElement.oclIsUndefined() then return null endif;
- var mf := object TypeModelFacet {};
-
- mf.metaClass := self.child.domainMetaElement.findGenClass();
- mf.containmentMetaFeature := self.containmentFeature.findGenFeature();
-
- if self.childrenFeature.oclIsUndefined() then
- mf.childMetaFeature := mf.containmentMetaFeature
- else
- mf.childMetaFeature := self.childrenFeature.findGenFeature()
- endif;
-
- mf.modelElementSelector := self.child.domainSpecialization.map createConstraint();
- mf.modelElementInitializer := self.child.domainInitializer.map structure();
- return mf;
-}
-
--- *************************************************************************************
--- Link
--- *************************************************************************************
-
-mapping GMFMAP::LinkMapping::createModelFacet(): GMFGEN::LinkModelFacet
- disjuncts
- GMFMAP::LinkMapping::createFeatureLinkModelFacet,
- GMFMAP::LinkMapping::createTypeLinkModelFacet
- {}
-
-mapping GMFMAP::LinkMapping::createFeatureLinkModelFacet() : GMFGEN::FeatureLinkModelFacet when {
- self.domainMetaElement.oclIsUndefined() and not self.linkMetaFeature.oclIsUndefined()} {
-
- metaFeature := self.linkMetaFeature.findGenFeature();
-}
-mapping GMFMAP::LinkMapping::createTypeLinkModelFacet() : GMFGEN::TypeLinkModelFacet when {
- not self.domainMetaElement.oclIsUndefined()} {
-
- metaClass := self.domainMetaElement.findGenClass();
- containmentMetaFeature := self.containmentFeature.findGenFeature();
- childMetaFeature := containmentMetaFeature;
- sourceMetaFeature := self.sourceMetaFeature.findGenFeature();
- targetMetaFeature := self.linkMetaFeature.findGenFeature();
- modelElementSelector := self.domainSpecialization.map createConstraint(); -- ALTERNATIVE: if not self.domainSpecialization.oclIsUndefined() then modelElementSelector := self.domainSpecialization.map structure() endif;
- modelElementInitializer := self.domainInitializer.map structure();
-}
-
-query DiagramElement::findOffsetFacet(): LabelOffsetFacet {
- return self.facets->selectOne(e | e.oclIsKindOf(LabelOffsetFacet)).oclAsType(LabelOffsetFacet)
-}
-query DiagramElement::findAlignmentFacet(): AlignmentFacet {
- return self.facets->selectOne(e | e.oclIsKindOf(AlignmentFacet)).oclAsType(AlignmentFacet)
-}
-query GMFMAP::NodeMapping::isPureLabelNode() : Boolean {
- return self.labelMappings->size() = 1 and self.children->isEmpty() and self.labelMappings->first().diagramLabel = self.diagramNode;
-}
-query GMFGRAPH::Node::getAffixedSideAsPositionConstantsName() : String {
- switch {
- case (self.affixedParentSide = GMFGRAPH::Direction::NONE) assert (false) with log('DiagramNode is not side-affixed', self);
- case (self.affixedParentSide = GMFGRAPH::Direction::EAST) return 'EAST';
- case (self.affixedParentSide = GMFGRAPH::Direction::WEST) return 'WEST';
- case (self.affixedParentSide = GMFGRAPH::Direction::NORTH) return 'NORTH';
- case (self.affixedParentSide = GMFGRAPH::Direction::SOUTH) return 'SOUTH';
- case (self.affixedParentSide = GMFGRAPH::Direction::NSEW) return 'NONE'; -- any side
- --else return 'NONE'; -- any side
- };
- return 'NONE'; -- any side
-}
-helper GMFMAP::CanvasMapping::handleRelatedDiagram(in mapElement : GMFMAP::MappingEntry) : GMFGEN::OpenDiagramBehaviour {
- var rv = object GMFGEN::OpenDiagramBehaviour {};
- -- XXX alternative approach to tell whether related diagram is the same we are processing now,
- -- originally self.eResource() != mapElement.eResource()
- if self <> mapElement.container() then {
- rv.diagramKind := 'FIXME put GenEditorGenerator.modelID value here';
- rv.editorID := 'FIXME put GenEditorView.id value here';
- } endif;
- return rv;
-}
-
--- *************************************************************************************
--- NodeLabel
--- *************************************************************************************
-
-mapping GMFMAP::LabelMapping::createNodeLabel(node: NodeReference) : GMFGEN::GenNodeLabel {
- init {
- if self.diagramLabel.external then
- result := object GenExternalNodeLabel {}
- else
- result := object GenNodeLabel {}
- endif
- }
-
- result.modelFacet := self.map createLabelModelFacet(node);
- result.readOnly := self.readOnly;
- result.elementIcon := self.diagramLabel.elementIcon;
--- result.viewmap := self.diagramLabel.viewmap();
-}
-
--- XXX perhaps, can replace with mapping WTF::auxParser() and WTF::externalParser, to use QVTO to create instances when
--- neccessary, the problem is finding a proper WTF (labelMapping knows it's MappingEntry, but latter doesn't keep track of CanvasMapping or similar)
-property designLabelParser : GMFGEN::ExternalParser = null;
-property auxParser : GMFGEN::ExternalParser = null;
-
--- DGMT#createLabelModelFacet
-mapping GMFMAP::LabelMapping::createLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet
- disjuncts
- GMFMAP::LabelMapping::createDefaultLabelModelFacet,
- GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet,
- GMFMAP::DesignLabelMapping::createDesignLabelModelFacet,
- GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet,
- GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet
- {}
-mapping GMFMAP::LabelMapping::createDefaultLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet
- when {self.oclIsTypeOf(LabelMapping)} {
- init {
- if this.auxParser = null then
- this.auxParser := object GMFGEN::ExternalParser {}
- endif;
- }
- parser := this.auxParser;
-}
-mapping GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet(node: NeedsContainment) : GMFGEN::FeatureLabelModelFacet {
--- init {
--- result := object FeatureLabelModelFacet {
- metaFeatures += self.features.findGenFeature();
- editableMetaFeatures += self.editableFeatures.findGenFeature();
- viewPattern := self.viewPattern;
- editPattern := self.editPattern;
- 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;
--- return r;
-}
-mapping GMFMAP::DesignLabelMapping::createDesignLabelModelFacet(node: NeedsContainment) : GMFGEN::DesignLabelModelFacet {
--- init {
--- result := object DesignLabelModelFacet {}
--- }
- if this.designLabelParser = null then
- this.designLabelParser := object GMFGEN::ExternalParser {}
- endif;
- parser := this.designLabelParser;
-
-}
-mapping GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet(node: NeedsContainment): GMFGEN::ExpressionLabelModelFacet {
--- init {
--- result := object 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;
- };
-
--- }
--- }
-}
-mapping GMFMAP::ValueExpression::createValueExpression(): GMFGEN::ValueExpression
- disjuncts GMFMAP::ValueExpression::createGenValueExpression, GMFMAP::Constraint::createConstraint
-{}
-mapping GMFMAP::ValueExpression::createGenValueExpression(): GMFGEN::ValueExpression
- when {self.oclIsTypeOf(ValueExpression)}{
- body := self.body;
-}
-mapping GMFMAP::Constraint::createConstraint(): GMFGEN::GenConstraint {
- body := self.body;
-}
-mapping GMFMAP::ValueExpression::createExpressionProvider(): GenExpressionProviderBase {
- init {
- switch {
- case (self.language = Language::java) { result := object GenJavaExpressionProvider {} };
- case (self.language = Language::ocl) { result := object GenExpressionInterpreter { language := self.language() } };
- case (self.language = Language::regexp) { result := object GenExpressionInterpreter { language := self.language() } };
- case (self.language = Language::nregexp) { result := object GenExpressionInterpreter { language := self.language() } };
- case (self.language = GenLanguage::_literal) { result := object GenLiteralExpressionProvider {} };
- else { result := object GenExpressionInterpreter {}; }
- };
- }
-
- expressions += ValueExpression.allInstances()->select(e | e.language = self.language)->map createValueExpression();
-}
-helper GMFMAP::ValueExpression::language(): GenLanguage {
- return switch {
- case (self.language = Language::java) GenLanguage::java;
- case (self.language = Language::ocl) GenLanguage::ocl;
- case (self.language = Language::regexp) GenLanguage::regexp;
- case (self.language = Language::nregexp) GenLanguage::nregexp;
- case (self.language = Language::_literal) return GenLanguage::_literal;
- else GenLanguage::ocl;
- }
-}
-query GMFMAP::ValueExpression::selectProvider(): GenExpressionProviderBase {
- return this.mapRoot->resolveone(GMFGEN::GenExpressionProviderContainer).providers->any(e | e.getLanguage() = self.language)
-}
-query GMFMAP::LabelTextAccessMethod::convertLabelTextAccessMethod() : GMFGEN::LabelTextAccessMethod {
- switch {
- case (self = GMFMAP::LabelTextAccessMethod::NATIVE) return GMFGEN::LabelTextAccessMethod::NATIVE;
- case (self = GMFMAP::LabelTextAccessMethod::REGEXP) return GMFGEN::LabelTextAccessMethod::REGEXP;
- case (self = GMFMAP::LabelTextAccessMethod::PRINTF) return GMFGEN::LabelTextAccessMethod::PRINTF;
- else return GMFGEN::LabelTextAccessMethod::MESSAGE_FORMAT;
- };
- return GMFGEN::LabelTextAccessMethod::MESSAGE_FORMAT;
-}
-
-mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet(node: NeedsContainment): GMFGEN::FeatureLabelModelFacet {
- var genFeature = self.feature.findGenFeature();
- metaFeatures += genFeature;
- editableMetaFeatures += genFeature;
- parser := self.map createOclChoiceParser();
-}
-
-mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceParser(): GMFGEN::OclChoiceParser {
- if not self.itemsExpression.oclIsUndefined() then
- result.itemsExpression := self.itemsExpression.map createValueExpression()
- endif;
- if not self.showExpression.oclIsUndefined() then
- result.showExpression := self.showExpression.map createValueExpression()
- endif;
-
- GenEditorGenerator.allInstances()->asSequence()->first().labelParsers.implementations += result;
-}
-
--- *************************************************************************************
--- Constraints and initializers
--- *************************************************************************************
-
-mapping GMFMAP::LinkConstraints::structure() : GMFGEN::GenLinkConstraints {
- sourceEnd := self.sourceEnd.map createConstraint();
- targetEnd := self.targetEnd.map createConstraint();
-}
-
--- note, Constraints may be reused through reuse of NodeMappings, hence need to keep track of the relation
---mapping GMFMAP::Constraint::structure() : GMFGEN::GenConstraint {
--- result._body := self._body;
--- result.bindToProvider(self);
---}
---mapping GMFMAP::ValueExpression::structure_ve() : GMFGEN::ValueExpression { --XXX think about naming, how to avoid conflict with GenConstraint::structure - disjuncts?
--- result._body := self._body;
--- result.bindToProvider(self);
---}
---helper GMFGEN::ValueExpression::bindToProvider(in expression : GMFMAP::ValueExpression) {
--- if expression.language.detectGenLanguage().oclIsUndefined() then return endif; -- XXX perhaps, don't need this line, if .map would give OclInvalid
--- expression.language.detectGenLanguage().map expressionProvider().expressions += self;
--- return;
---}
--- XXX actually, looks like I don't need GenLanguage - I can make most decisions based on
---query GMFMAP::Language::detectGenLanguage() : GMFGEN::GenLanguage {
--- switch {
--- case (self = GMFMAP::Language::ocl) return GMFGEN::GenLanguage::ocl;
--- case (self = GMFMAP::Language::java) return GMFGEN::GenLanguage::java;
--- case (self = GMFMAP::Language::regexp) return GMFGEN::GenLanguage::regexp;
--- case (self = GMFMAP::Language::nregexp) return GMFGEN::GenLanguage::nregexp;
--- case (self = GMFMAP::Language::_literal) return GMFGEN::GenLanguage::_literal;
--- else { assert (false) with log ('Unknown expression language literal', self); }
--- };
--- return GMFGEN::GenLanguage::ocl;
---}
---mapping GMFGEN::GenLanguage::expressionProvider() : GMFGEN::GenExpressionProviderBase {
--- init {
--- switch {
--- case (self = GMFGEN::GenLanguage::ocl) result := object GMFGEN::GenExpressionInterpreter { language := self };
--- case (self = GMFGEN::GenLanguage::java) result := object GMFGEN::GenJavaExpressionProvider {};
--- case (self = GMFGEN::GenLanguage::regexp) result := object GMFGEN::GenExpressionInterpreter { language := self };
--- case (self = GMFGEN::GenLanguage::nregexp) result := object GMFGEN::GenExpressionInterpreter { language := self };
--- case (self = GMFGEN::GenLanguage::_literal) result := object GMFGEN::GenLiteralExpressionProvider {};
--- else {
--- assert (false) with log ('Unknown expression language literal', self);
--- -- fake provider with no language set to fail validation (XXX perhaps, makes sense to add 'unrecognized' language?)
--- result := object GMFGEN::GenExpressionInterpreter {};
--- }
--- }
--- }
---}
-
--- *************************************************************************************
--- ElementInitializer
--- *************************************************************************************
-
-mapping GMFMAP::ElementInitializer::structure() : GMFGEN::GenElementInitializer {
- init {
- assert (false) with log ('No idea how to process ElementInitializer', self);
- }
-}
-
-mapping GMFMAP::FeatureSeqInitializer::structure() : GMFGEN::GenElementInitializer {
- init {
- result := object GenFeatureSeqInitializer {
- initializers += self.initializers.map structure();
- if not self.elementClass.oclIsUndefined() then
- elementClass := self.elementClass.findGenClass()
- endif;
- }
- }
-}
-
--- *************************************************************************************
--- GenFeatureInitializer
--- *************************************************************************************
-
-mapping GMFMAP::FeatureInitializer::structure() : GMFGEN::GenFeatureInitializer {
- init {
- assert (false) with log ('No idea how to process FeatureInitializer', self);
- }
-}
-
-mapping GMFMAP::FeatureValueSpec::structure() : GMFGEN::GenFeatureInitializer {
- init {
- result := object GenFeatureValueSpec {
- feature := self.feature.findGenFeature();
- value := self.value.map createValueExpression();
- }
- }
-}
-
-mapping GMFMAP::ReferenceNewElementSpec::structure() : GMFGEN::GenFeatureInitializer {
- init {
- result := object GenReferenceNewElementSpec {
- feature := self.feature.findGenFeature();
- -- cast to GenFeatureSeqInitializer was in the original DGMT
- newElementInitializers += self.newElementInitializers.map structure().oclAsType(GMFGEN::GenFeatureSeqInitializer);
- }
- }
-}
-
--- *************************************************************************************
--- Palette
--- *************************************************************************************
-
-mapping GMFMAP::CanvasMapping::palette() : GMFGEN::Palette
- when { not self.palette.oclIsUndefined(); } {
- --if self.palette.oclIsUndefined() return OclInvalid;
- var paletteItems : Sequence(GMFGEN::ToolGroupItem) := self.palette.tools.map paletteEntry();
- var topLevelTools := paletteItems->reject(e | e.oclIsKindOf(GMFGEN::ToolGroup));
- if topLevelTools->notEmpty() then {
- var defaultGroup := object GMFGEN::ToolGroup {
- title := 'Default';
- description := 'Holds top-level non-container tools';
- collapse := false;
- entries += topLevelTools;
- };
- result.groups := result.groups->prepend(defaultGroup);
- } endif;
-
- result.groups += paletteItems[GMFGEN::ToolGroup];
- result.flyout := true;
- if (self.palette._default <> null) then {
- var te := self.palette._default.resolveone(GMFGEN::ToolEntry);
- if te <> null then te._default := true else log ('There\'s default tool specified for palette, but can\'t find gmfgen counterpart') endif;
- } endif;
-}
-
-mapping GMFTOOL::AbstractTool::paletteEntry() : GMFGEN::ToolGroupItem {
- init {
- assert (false) with log('Can\'t dispatch paletteEntry() for ', self);
- }
-}
-
-mapping GMFTOOL::PaletteSeparator::paletteEntry() : GMFGEN::ToolGroupItem {
- init {
- result := object GMFGEN::Separator {};
- }
-}
-
-mapping GMFTOOL::CreationTool::paletteEntry() : GMFGEN::ToolGroupItem {
- init {
- var r := object GMFGEN::ToolEntry {};
- setupCommonToolEntry(self, r);
- result := r;
- }
-}
-
-mapping GMFTOOL::GenericTool::paletteEntry() : GMFGEN::ToolGroupItem
- when {not self.toolClass.oclIsUndefined() or self.toolClass->notEmpty()} {
- init {
- var r := object GMFGEN::ToolEntry {};
- r.qualifiedToolName := self.toolClass;
- setupCommonToolEntry(self, r);
- result := r;
- }
-}
-
-mapping GMFTOOL::StandardTool::paletteEntry() : GMFGEN::ToolGroupItem {
- init {
- var r := object GMFGEN::StandardEntry {};
- switch {
- case (self.toolKind = StandardToolKind::SELECT) r.kind := StandardEntryKind::SELECT;
- case (self.toolKind = StandardToolKind::MARQUEE) r.kind := StandardEntryKind::MARQUEE;
- case (self.toolKind = StandardToolKind::ZOOM_PAN) r.kind := StandardEntryKind::ZOOM;
- };
- setupCommonToolEntry(self, r);
- result := r;
- }
-}
-
-mapping GMFTOOL::ToolGroup::paletteEntry() : GMFGEN::ToolGroupItem {
- init {
- var r := object GMFGEN::ToolGroup {};
- r.stack := self.stack;
- r.collapse := self.collapsible;
- setupCommonToolEntry(self, r);
- r.entries += self.tools.map paletteEntry();
- result := r;
- }
-}
-
--- XXX or helper GMFGEN::EntryBase::setupCommonToolEntry()?
-helper setupCommonToolEntry(in tool : GMFTOOL::AbstractTool, inout genTool : GMFGEN::EntryBase){
- genTool.title := tool.title;
- genTool.description := tool.description;
- if tool.largeIcon.oclIsTypeOf(GMFTOOL::BundleImage) then
- genTool.largeIconPath := tool.largeIcon.oclAsType(GMFTOOL::BundleImage).constructIconPath()
- endif;
- if tool.smallIcon.oclIsTypeOf(GMFTOOL::BundleImage) then
- genTool.smallIconPath := tool.smallIcon.oclAsType(GMFTOOL::BundleImage).constructIconPath()
- endif;
- return null;
-}
-
--- FIXME process path (makeRelative/makeAbsolute) as in original java code
-query GMFTOOL::BundleImage::constructIconPath() : String {
- if self.path.oclIsUndefined() or self.path.trim().size() = 0 then return null endif;
- if self.bundle.oclIsUndefined() or self.bundle.trim().size() = 0 then
- return self.path.makeRelative()
- endif;
- return self.bundle.makeAbsolute() + self.path;
-}
-query String::makeRelative(): String {
- return self;
-}
-query String::makeAbsolute(): String {
- return if self.startsWith('/') or self->exists(e | e = ':') then self + '/' else '/' + self + '/' endif;
-}
-
--- *************************************************************************************
--- Parsers
--- *************************************************************************************
-
-mapping GMFMAP::Mapping::createGenParsers(): GenParsers {
--- object GenParsers {
- implementations += GMFGEN::GenParserImplementation.allInstances();
- if this.designLabelParser <> null then implementations += this.designLabelParser endif;
- if this.auxParser <> null then implementations += this.auxParser endif;
- extensibleViaService := true;
--- };
-}
-
-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
- let firstFeature = self.features->first() in
- let firstEditFeature = self.editableFeatures->first() in
- if firstFeature <> firstEditFeature then false else firstFeature.eType.oclIsKindOf(EEnum) endif
- endif
- endif;
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenUtil.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Map2GenUtil.qvto
index d2f42dd..5cabc9c 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Map2GenUtil.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Map2GenUtil.qvto
@@ -1,13 +1,15 @@
/**
-* Copyright (c) 2011, 2012 Montages A.G.
-* 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:
-* Guillaume Hillairet (Montages A.G.) : initial implementation
-*/
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
@@ -18,66 +20,16 @@ library Map2GenUtil;
property allChildReferences: Sequence(ChildReference) = Sequence{};
property childReferences: Sequence(ChildReference) = Sequence{};
property equivalentChild: Dict(ChildReference, Sequence(ChildReference)) = Dict{};
-
property genModel : GENMODEL::GenModel = null;
-
-query GMFMAP::Mapping::getChildReferences(): Sequence(ChildReference) {
- var rs : Sequence(ChildReference) := Sequence{};
-
- allChildReferences := self.nodes->collect(e | e.child.getChildReferences());
- allChildReferences->forEach(c) {
- var equi: ChildReference = equivalentChild->keys()->selectOne(e | e.matchChildReferenceFeatures(c));
- if equi.oclIsUndefined() then {
- rs += c;
- equivalentChild->put(c, Sequence{});
- } else {
- var seq := equivalentChild->get(equi);
- seq += c;
- equivalentChild->put(equi, seq);
- } endif
- };
-
- return rs
- -- ->reject(e | e.compartment.oclIsUndefined() and
- -- e.containmentFeature = e.childrenFeature and
- -- not e.referencedChild.oclIsUndefined());
-}
-
-query NodeMapping::getChildReferences(): Sequence(ChildReference) {
- processedNodeMappings += self;
- return self.children->collect(e |
- Sequence{e}->union(if processedNodeMappings->includes(e.child) then Sequence {}
- else
- e.child.getChildReferences()
- endif))
-}
property processedNodeMappings: Sequence(NodeMapping) = Sequence{};
-
property compartmentsHistory: Sequence(Tuple(c: CompartmentMapping, n: NodeMapping, r: NodeReference)) = Sequence{};
-query GMFMAP::Mapping::getCompartments(): Sequence(Tuple(c: CompartmentMapping, n: NodeMapping, r: NodeReference)) {
- return
- if compartmentsHistory->notEmpty() then compartmentsHistory else
- self.nodes->collect(e |
- if not e.child.oclIsUndefined() then
- e.child.compartments->collect(comp | comp.getSubCompartments(e.child, e)
- )->flatten()
- endif)->flatten()
- endif;
-}
-query GMFMAP::CompartmentMapping::getSubCompartments(_mapping: NodeMapping, container: NodeReference):
- Sequence(Tuple(c: CompartmentMapping, n: NodeMapping, r: NodeReference)) {
-
- compartmentsHistory += Tuple{c = self, n = _mapping, r = container};
-
- return Sequence{Tuple{c = self, n = _mapping, r = container}}->union(
- _mapping.children->collect(e |
- if not e.child.oclIsUndefined() then
- e.child.compartments->collect(c |
- if not compartmentsHistory->exists(t | t.c = c and t.n = e.child and t.r = e) then
- c.getSubCompartments(e.child, e)
- endif)
- endif))->flatten();
- }
+
+-- XXX ElementType as return value, disjunct?
+mapping GENMODEL::GenClass::gmfRuntimeMetamodelType() : GMFGEN::MetamodelType {}
+
+--
+-- Helpers
+--
helper GMFMAP::ChildReference::matchChildReferenceFeatures(node: GMFMAP::ChildReference) : Boolean {
var containmentFeatureMatch : Boolean;
@@ -105,14 +57,6 @@ helper GMFMAP::ChildReference::matchChildReferenceFeatures(node: GMFMAP::ChildRe
return containmentFeatureMatch and childrenFeatureMatch and childMatch;
}
-query ChildReference::findProcessableChildReference(): ChildReference {
- return if childReferences->includes(self) then
- self
- else
- equivalentChild->keys()->selectOne(e | equivalentChild->get(e)->includes(self))
- endif
-}
-
-- XXX review - Specialization type is created again and again - why not reuse it?
-- static, for some reasons, helpers couldn't specify 'inout' for context element
-- XXX, actually, don't need GenNode here, GenClass should be sufficient
@@ -121,6 +65,7 @@ helper setupElementType(inout genNode : GMFGEN::GenNode) {
else genNode.elementType := genNode.modelFacet.metaClass.getOrCreateRuntimeMetamodelType() endif;
return;
}
+
helper setupElementType(inout genLink : GMFGEN::GenLink) {
if genLink.modelFacet.oclIsUndefined() then genLink.elementType := object GMFGEN::NotationType {}
else if genLink.modelFacet.oclIsKindOf(GMFGEN::TypeModelFacet) then
@@ -132,6 +77,41 @@ helper setupElementType(inout genLink : GMFGEN::GenLink) {
endif;
return;
}
+
+--
+-- Queries
+--
+
+query GMFMAP::Mapping::getChildReferences(): Sequence(ChildReference) {
+ var rs : Sequence(ChildReference) := Sequence{};
+
+ allChildReferences := self.nodes->collect(e | e.child.getChildReferences());
+ allChildReferences->forEach(c) {
+ var equi: ChildReference = equivalentChild->keys()->selectOne(e | e.matchChildReferenceFeatures(c));
+ if equi.oclIsUndefined() then {
+ rs += c;
+ equivalentChild->put(c, Sequence{});
+ } else {
+ var seq := equivalentChild->get(equi);
+ seq += c;
+ equivalentChild->put(equi, seq);
+ } endif
+ };
+
+ return rs
+ -- ->reject(e | e.compartment.oclIsUndefined() and
+ -- e.containmentFeature = e.childrenFeature and
+ -- not e.referencedChild.oclIsUndefined());
+}
+
+query GMFMAP::ChildReference::findProcessableChildReference(): ChildReference {
+ return if childReferences->includes(self) then
+ self
+ else
+ equivalentChild->keys()->selectOne(e | equivalentChild->get(e)->includes(self))
+ endif
+}
+
query GENMODEL::GenClass::getOrCreateRuntimeMetamodelType() : GMFGEN::ElementType {
var mmt = self.resolveoneIn(GENMODEL::GenClass::gmfRuntimeMetamodelType, GMFGEN::MetamodelType);
if mmt.oclIsUndefined() then
@@ -139,20 +119,52 @@ query GENMODEL::GenClass::getOrCreateRuntimeMetamodelType() : GMFGEN::ElementTyp
endif;
return object GMFGEN::SpecializationType { metamodelType := mmt }
}
--- XXX ElementType as return value, disjunct?
-mapping GENMODEL::GenClass::gmfRuntimeMetamodelType() : GMFGEN::MetamodelType {}
-query ECORE::EClass::findGenClass() : GENMODEL::GenClass {
- return self.ePackage.findGenPackage().genClassifiers[GenClass]->select(gc | gc.ecoreClass.name = self.name)->first();
+query NodeMapping::getChildReferences(): Sequence(ChildReference) {
+ processedNodeMappings += self;
+ return self.children->collect(e |
+ Sequence{e}->union(if processedNodeMappings->includes(e.child) then Sequence {}
+ else
+ e.child.getChildReferences()
+ endif))
}
-query ECORE::EPackage::findGenPackage() : GENMODEL::GenPackage {
+
+query GMFMAP::Mapping::getCompartments(): Sequence(Tuple(c: CompartmentMapping, n: NodeMapping, r: NodeReference)) {
+ return
+ if compartmentsHistory->notEmpty() then compartmentsHistory else
+ self.nodes->collect(e |
+ if not e.child.oclIsUndefined() then
+ e.child.compartments->collect(comp | comp.getSubCompartments(e.child, e)
+ )->flatten()
+ endif)->flatten()
+ endif;
+}
+
+query GMFMAP::CompartmentMapping::getSubCompartments(_mapping: NodeMapping, container: NodeReference): Sequence(Tuple(c: CompartmentMapping, n: NodeMapping, r: NodeReference)) {
+ compartmentsHistory += Tuple{c = self, n = _mapping, r = container};
+
+ return Sequence{Tuple{c = self, n = _mapping, r = container}}->union(
+ _mapping.children->collect(e |
+ if not e.child.oclIsUndefined() then
+ e.child.compartments->collect(c |
+ if not compartmentsHistory->exists(t | t.c = c and t.n = e.child and t.r = e) then
+ c.getSubCompartments(e.child, e)
+ endif)
+ endif))->flatten();
+}
+
+query ECORE::EClass::findGenClass() : GENMODEL::GenClass =
+ self.ePackage.findGenPackage().genClassifiers[GenClass]->select(gc | gc.ecoreClass.name = self.name)->first();
+
+query ECORE::EPackage::findGenPackage() : GENMODEL::GenPackage =
-- XXX GenModel.findGenPackage does more than this (staticGenPackage and nestedGenPackages). FIXME
-- ->union(genModel.staticGenPackages)
- return this.genModel.genPackages->union(
+ this.genModel.genPackages->union(
this.genModel.usedGenPackages)->select(gp |
gp.ecorePackage.nsURI = self.nsURI)->asSequence()->first();
-}
-query ECORE::EStructuralFeature::findGenFeature() : GENMODEL::GenFeature {
- return self.eContainingClass.findGenClass().genFeatures->select(f | f.ecoreFeature = self)->first();
-}
+query ECORE::EStructuralFeature::findGenFeature() : GENMODEL::GenFeature =
+ self.eContainingClass.findGenClass().genFeatures->select(f | f.ecoreFeature = self)->first();
+
+query GMFMAP::NodeMapping::isPureLabelNode() : Boolean =
+ self.labelMappings->size() = 1 and self.children->isEmpty() and self.labelMappings->first().diagramLabel = self.diagramNode;
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Mappings.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Mappings.qvto
new file mode 100644
index 0000000..6a21f22
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Mappings.qvto
@@ -0,0 +1,271 @@
+/**
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
+library Mappings;
+
+import Map2GenUtil;
+import ModelFacets;
+import Palette;
+
+modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
+modeltype GMFTOOL uses tooldef('http://www.eclipse.org/gmf/2005/ToolDefinition');
+modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
+modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition');
+modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
+
+
+mapping GMFMAP::Mapping::structure() : GMFGEN::GenEditorGenerator {
+ diagram := self.diagram.map structure();
+
+ diagram.topLevelNodes += self.nodes->map structure()->asOrderedSet();
+ childReferences->forEach(c) { diagram.childNodes += c.map structure(c.child); };
+
+ diagram.links := self.links->map structure()->asOrderedSet();
+ self.getCompartments()->forEach(e) { diagram.compartments += e.c.map structure(e.n, e.r); };
+
+ diagram.getAllNodes()->forEach(n) { setupElementType(n) };
+ diagram.links->forEach(l) { setupElementType(l) };
+
+ if self.expressionsByLanguages()->notEmpty() then
+ expressionProviders := self.map createProviderContainer()
+ endif;
+}
+
+mapping GMFMAP::Mapping::createProviderContainer(): GMFGEN::GenExpressionProviderContainer {
+ self.expressionsByLanguages()->forEach(e) {
+ providers += e.map createExpressionProvider()
+ }
+}
+
+mapping GMFMAP::CanvasMapping::structure() : GMFGEN::GenDiagram {
+ domainDiagramElement := self.domainMetaElement.findGenClass();
+ iconProviderPriority := GMFGEN::ProviderPriority::Low;
+ validationProviderPriority := GMFGEN::ProviderPriority::Low;
+
+ if result.domainDiagramElement.oclIsUndefined() then
+ result.elementType := object GMFGEN::NotationType {}
+ else
+ result.elementType := result.domainDiagramElement.getOrCreateRuntimeMetamodelType()
+ endif;
+}
+
+--
+-- TopLevelNode
+--
+
+mapping GMFMAP::TopNodeReference::structure() : GMFGEN::GenTopLevelNode {
+ modelFacet := self.createModelFacet();
+ self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
+
+ self.child.children->select(e | e.compartment.oclIsUndefined())->forEach(c) {
+ var node := c.findProcessableChildReference();
+ childNodes += node.map structure(node.child);
+ };
+
+ labels += self.child.labelMappings->map createNodeLabel(self);
+
+-- viewmap := self.child.diagramNode.viewmap();
+ behaviour += self.child.relatedDiagrams.handleRelatedDiagram(self.child);
+}
+
+--
+-- GenChildNode
+--
+
+mapping GMFMAP::ChildReference::structure(node: GMFMAP::NodeMapping) : GMFGEN::GenChildNode
+ disjuncts
+ GMFMAP::ChildReference::createGenChildLabelNode,
+ GMFMAP::ChildReference::createGenChildSideAffixedNode,
+ GMFMAP::ChildReference::createGenChildNode
+ {}
+
+mapping GMFMAP::ChildReference::createGenChildLabelNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildLabelNode
+when {
+ node.isPureLabelNode()
+}
+{
+ modelFacet := self.createModelFacet();
+
+ var soleLabel := node.labelMappings->first();
+ labelModelFacet := soleLabel.map createLabelModelFacet(self);
+ labelReadOnly := soleLabel.readOnly;
+ labelElementIcon := soleLabel.diagramLabel.elementIcon;
+-- viewmap := soleLabel.diagramLabel.viewmap();
+ self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
+
+ self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
+ var node := c.findProcessableChildReference();
+ childNodes += node.map structure(node.child);
+ };
+}
+
+mapping GMFMAP::ChildReference::createGenChildSideAffixedNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildSideAffixedNode
+when {
+ node.diagramNode.affixedParentSide <> GMFGRAPH::Direction::NONE
+}
+{
+-- viewmap := node.diagramNode.viewmap();
+ modelFacet := self.createModelFacet();
+ preferredSideName := node.diagramNode.getAffixedSideAsPositionConstantsName();
+
+ labels += node.labelMappings->map createNodeLabel(self);
+ self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
+
+ self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
+ var node := c.findProcessableChildReference();
+ childNodes += node.map structure(node.child);
+ };
+
+ behaviour += node.relatedDiagrams.handleRelatedDiagram(node);
+}
+
+mapping GMFMAP::ChildReference::createGenChildNode(node: GMFMAP::NodeMapping) : GMFGEN::GenChildNode {
+-- viewmap := node.diagramNode.viewmap();
+ modelFacet := self.createModelFacet();
+ labels += node.labelMappings->map createNodeLabel(self);
+ self.child.tool.map paletteEntry().oclAsType(ToolEntry).genNodes += result;
+
+ self.child.children[ChildReference]->select(e | e.compartment.oclIsUndefined())->forEach(c) {
+ var node := c.findProcessableChildReference();
+ childNodes += node.map structure(node.child);
+ };
+
+ behaviour += node.relatedDiagrams.handleRelatedDiagram(node);
+ -- behaviour += node.visualEffects->map createVisualEffects(result, _node);
+}
+
+--
+-- NodeLabel
+--
+
+mapping GMFMAP::LabelMapping::createNodeLabel(node: NodeReference) : GMFGEN::GenNodeLabel {
+ init {
+ if self.diagramLabel.external then
+ result := object GenExternalNodeLabel {}
+ else
+ result := object GenNodeLabel {}
+ endif
+ }
+
+ result.modelFacet := self.map createLabelModelFacet(node);
+ result.readOnly := self.readOnly;
+ result.elementIcon := self.diagramLabel.elementIcon;
+-- result.viewmap := self.diagramLabel.viewmap();
+}
+
+mapping GMFMAP::LinkMapping::structure() : GMFGEN::GenLink {
+ assert(not self.diagramLink.oclIsUndefined()) with log("link diagram link cannot be null");
+ if not self.domainMetaElement.oclIsUndefined() then
+ assert(not self.linkMetaFeature.oclIsUndefined()) with log("linkMetaFeature cannot be null")
+ endif;
+
+ -- model facet
+ if not (self.domainMetaElement.oclIsUndefined() and self.linkMetaFeature.oclIsUndefined()) then
+ modelFacet := self.map createModelFacet()
+ endif;
+
+ -- labels
+ labels += self.labelMappings->map structure(self);
+
+ self.tool.map paletteEntry().oclAsType(ToolEntry).genLinks += result;
+ -- setupElementType(result);
+-- result.viewmap := self.diagramLink.viewmap();
+ result.creationConstraints := self.creationConstraints.map structure();
+}
+
+--
+-- Compartment
+--
+
+mapping GMFMAP::CompartmentMapping::structure(_mapping: GMFMAP::NodeMapping, container: GMFMAP::NodeReference): GMFGEN::GenCompartment {
+ init {
+ result := object GMFGEN::GenCompartment {
+ canCollapse := self.compartment.collapsible;
+ needsTitle := self.compartment.needsTitle;
+ title := self.compartment.name;
+-- viewmap := self.compartment.viewmap();
+ };
+ }
+
+ if container.oclIsKindOf(GMFMAP::TopNodeReference) then {
+ container.resolveone(GMFGEN::GenNode).compartments += result
+ } else {
+ var node := container.oclAsType(ChildReference).findProcessableChildReference();
+ if not node.oclIsUndefined() then
+ node.map structure(node.child).compartments += result
+ endif
+ } endif;
+
+ allChildReferences->select(e | e.compartment = self)->forEach(c) {
+ if c.child.children->size() > 0 then
+ listLayout := false
+ endif;
+ var node := c.findProcessableChildReference();
+ -- if equivalentChild->hasKey(c) then c else
+ -- equivalentChild->keys()->selectOne(e | equivalentChild->get(e)->includes(c)) endif;
+ childNodes += node.map structure(node.child);
+ }
+}
+
+mapping LabelMapping::structure(link: GMFMAP::LinkMapping): GenLinkLabel {
+ readOnly := self.readOnly;
+ elementIcon := self.diagramLabel.elementIcon;
+ modelFacet := self.map createLabelModelFacet(link);
+
+ var alignmentFacet := self.diagramLabel.findAlignmentFacet();
+ if not alignmentFacet.oclIsUndefined() then
+ alignment := switch {
+ case (alignmentFacet.alignment = GMFGRAPH::Alignment::BEGINNING) LinkLabelAlignment::SOURCE;
+ case (alignmentFacet.alignment = GMFGRAPH::Alignment::CENTER) LinkLabelAlignment::MIDDLE;
+ case (alignmentFacet.alignment = GMFGRAPH::Alignment::END) LinkLabelAlignment::TARGET;
+ else LinkLabelAlignment::MIDDLE;
+ }
+ endif;
+}
+
+--
+-- Helpers
+--
+
+helper GMFMAP::CanvasMapping::handleRelatedDiagram(in mapElement : GMFMAP::MappingEntry) : GMFGEN::OpenDiagramBehaviour =
+ object GMFGEN::OpenDiagramBehaviour {
+ -- XXX alternative approach to tell whether related diagram is the same we are processing now,
+ -- originally self.eResource() != mapElement.eResource()
+ if self <> mapElement.container() then {
+ diagramKind := 'FIXME put GenEditorGenerator.modelID value here';
+ editorID := 'FIXME put GenEditorView.id value here';
+ } endif;
+ };
+
+--
+-- Queries
+--
+
+query GMFMAP::Mapping::expressionsByLanguages(): Sequence(ValueExpression) =
+ GMFMAP::ValueExpression.allInstances()->iterate(it; res: Sequence(ValueExpression) = Sequence{} |
+ if res->exists(e | e.language = it.language) then res else res->including(it) endif
+ );
+
+query GMFGRAPH::Node::getAffixedSideAsPositionConstantsName() : String =
+ switch {
+ case (self.affixedParentSide = GMFGRAPH::Direction::NONE) assert (false) with log('DiagramNode is not side-affixed', self);
+ case (self.affixedParentSide = GMFGRAPH::Direction::EAST) return 'EAST';
+ case (self.affixedParentSide = GMFGRAPH::Direction::WEST) return 'WEST';
+ case (self.affixedParentSide = GMFGRAPH::Direction::NORTH) return 'NORTH';
+ case (self.affixedParentSide = GMFGRAPH::Direction::SOUTH) return 'SOUTH';
+ case (self.affixedParentSide = GMFGRAPH::Direction::NSEW) return 'NONE'; -- any side
+ else return 'NONE'; -- any side
+ };
+
+query DiagramElement::findAlignmentFacet(): AlignmentFacet =
+ self.facets->selectOne(e | e.oclIsKindOf(AlignmentFacet)).oclAsType(AlignmentFacet);
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto b/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto
new file mode 100644
index 0000000..6b6774b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/ModelFacets.qvto
@@ -0,0 +1,215 @@
+/**
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
+library ModelFacets;
+
+import Map2GenUtil;
+import ValueExpressions;
+import Parsers;
+
+modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
+modeltype GMFTOOL uses tooldef('http://www.eclipse.org/gmf/2005/ToolDefinition');
+modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
+modeltype GMFGRAPH uses gmfgraph('http://www.eclipse.org/gmf/2006/GraphicalDefinition');
+modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
+
+--
+-- TypeModelFacet
+--
+
+helper GMFMAP::NodeReference::createModelFacet() : GMFGEN::TypeModelFacet {
+ if self.child.domainMetaElement.oclIsUndefined() then return null endif;
+ var mf := object TypeModelFacet {};
+
+ mf.metaClass := self.child.domainMetaElement.findGenClass();
+ mf.containmentMetaFeature := self.containmentFeature.findGenFeature();
+
+ if self.childrenFeature.oclIsUndefined() then
+ mf.childMetaFeature := mf.containmentMetaFeature
+ else
+ mf.childMetaFeature := self.childrenFeature.findGenFeature()
+ endif;
+
+ mf.modelElementSelector := self.child.domainSpecialization.map createConstraint();
+ mf.modelElementInitializer := self.child.domainInitializer.map structure();
+ return mf;
+}
+
+--
+-- LinkModelFacet
+--
+
+mapping GMFMAP::LinkMapping::createModelFacet(): GMFGEN::LinkModelFacet
+ disjuncts
+ GMFMAP::LinkMapping::createFeatureLinkModelFacet,
+ GMFMAP::LinkMapping::createTypeLinkModelFacet
+ {}
+
+mapping GMFMAP::LinkMapping::createFeatureLinkModelFacet() : GMFGEN::FeatureLinkModelFacet
+when {
+ self.domainMetaElement.oclIsUndefined() and not self.linkMetaFeature.oclIsUndefined()
+}
+{
+ metaFeature := self.linkMetaFeature.findGenFeature();
+}
+
+mapping GMFMAP::LinkMapping::createTypeLinkModelFacet() : GMFGEN::TypeLinkModelFacet
+when {
+ not self.domainMetaElement.oclIsUndefined()
+}
+{
+ metaClass := self.domainMetaElement.findGenClass();
+ containmentMetaFeature := self.containmentFeature.findGenFeature();
+ childMetaFeature := containmentMetaFeature;
+ sourceMetaFeature := self.sourceMetaFeature.findGenFeature();
+ targetMetaFeature := self.linkMetaFeature.findGenFeature();
+ modelElementSelector := self.domainSpecialization.map createConstraint(); -- ALTERNATIVE: if not self.domainSpecialization.oclIsUndefined() then modelElementSelector := self.domainSpecialization.map structure() endif;
+ modelElementInitializer := self.domainInitializer.map structure();
+}
+
+--
+-- LabelModelFacet
+--
+
+mapping GMFMAP::LabelMapping::createLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet
+ disjuncts
+ GMFMAP::LabelMapping::createDefaultLabelModelFacet,
+ GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet,
+ GMFMAP::DesignLabelMapping::createDesignLabelModelFacet,
+ GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet,
+ GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet
+ {}
+
+mapping GMFMAP::LabelMapping::createDefaultLabelModelFacet(node: NeedsContainment) : GMFGEN::LabelModelFacet
+ when {self.oclIsTypeOf(LabelMapping)}
+{
+ init {
+ if auxParser = null then
+ auxParser := object GMFGEN::ExternalParser {}
+ endif;
+ }
+ parser := auxParser;
+}
+
+mapping GMFMAP::FeatureLabelMapping::createFeatureLabelModelFacet(node: NeedsContainment) : GMFGEN::FeatureLabelModelFacet {
+ metaFeatures += self.features.findGenFeature();
+ editableMetaFeatures += self.editableFeatures.findGenFeature();
+ viewPattern := self.viewPattern;
+ editPattern := self.editPattern;
+ 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;
+}
+
+mapping GMFMAP::DesignLabelMapping::createDesignLabelModelFacet(node: NeedsContainment) : GMFGEN::DesignLabelModelFacet {
+ if designLabelParser = null then
+ designLabelParser := object GMFGEN::ExternalParser {}
+ endif;
+ parser := designLabelParser;
+}
+
+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;
+ };
+}
+
+mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceLabelModelFacet(node: NeedsContainment): GMFGEN::FeatureLabelModelFacet {
+ var genFeature = self.feature.findGenFeature();
+ metaFeatures += genFeature;
+ editableMetaFeatures += genFeature;
+ parser := self.map createOclChoiceParser();
+}
+
+--
+-- FeatureInitializer
+--
+
+mapping GMFMAP::FeatureInitializer::structure() : GMFGEN::GenFeatureInitializer {
+ init {
+ assert (false) with log ('No idea how to process FeatureInitializer', self);
+ }
+}
+
+mapping GMFMAP::FeatureValueSpec::structure() : GMFGEN::GenFeatureInitializer {
+ init {
+ result := object GenFeatureValueSpec {
+ feature := self.feature.findGenFeature();
+ value := self.value.map createValueExpression();
+ }
+ }
+}
+
+mapping GMFMAP::ReferenceNewElementSpec::structure() : GMFGEN::GenFeatureInitializer {
+ init {
+ result := object GenReferenceNewElementSpec {
+ feature := self.feature.findGenFeature();
+ -- cast to GenFeatureSeqInitializer was in the original DGMT
+ newElementInitializers += self.newElementInitializers.map structure().oclAsType(GMFGEN::GenFeatureSeqInitializer);
+ }
+ }
+}
+
+--
+-- ElementInitializer
+--
+
+mapping GMFMAP::ElementInitializer::structure() : GMFGEN::GenElementInitializer {
+ init {
+ assert (false) with log ('No idea how to process ElementInitializer', self);
+ }
+}
+
+mapping GMFMAP::FeatureSeqInitializer::structure() : GMFGEN::GenElementInitializer {
+ init {
+ result := object GenFeatureSeqInitializer {
+ initializers += self.initializers.map structure();
+ if not self.elementClass.oclIsUndefined() then
+ elementClass := self.elementClass.findGenClass()
+ endif;
+ }
+ }
+}
+
+--
+-- Queries
+--
+
+query GMFMAP::ValueExpression::selectProvider(mapRoot: GMFMAP::Mapping): GenExpressionProviderBase =
+ mapRoot->resolveone(GMFGEN::GenExpressionProviderContainer).providers->any(e | e.getLanguage() = self.language);
+
+query GMFMAP::LabelTextAccessMethod::convertLabelTextAccessMethod() : GMFGEN::LabelTextAccessMethod =
+ switch {
+ case (self = GMFMAP::LabelTextAccessMethod::NATIVE) return GMFGEN::LabelTextAccessMethod::NATIVE;
+ case (self = GMFMAP::LabelTextAccessMethod::REGEXP) return GMFGEN::LabelTextAccessMethod::REGEXP;
+ case (self = GMFMAP::LabelTextAccessMethod::PRINTF) return GMFGEN::LabelTextAccessMethod::PRINTF;
+ else return GMFGEN::LabelTextAccessMethod::MESSAGE_FORMAT;
+ };
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/ModeledViewmaps.qvto b/plugins/org.eclipse.gmf.bridge/transforms/ModeledViewmaps.qvto
index fed2b43..f45c052 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/ModeledViewmaps.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/ModeledViewmaps.qvto
@@ -1,12 +1,12 @@
/**
-* Copyright (c) 2011, 2012 Montages A.G.
-* 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:
-* Guillaume Hillairet (Montages A.G.) : initial implementation
+ * Copyright (c) 2011, 2012 Montages A.G.
+ * 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:
+ * Guillaume Hillairet (Montages A.G.) : initial implementation
*/
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Palette.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Palette.qvto
new file mode 100644
index 0000000..a54c0ab
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Palette.qvto
@@ -0,0 +1,137 @@
+/**
+ * Copyright (c) 2009, 2011, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
+library Palette;
+
+modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
+modeltype GMFTOOL uses tooldef('http://www.eclipse.org/gmf/2005/ToolDefinition');
+modeltype ECORE uses ecore('http://www.eclipse.org/emf/2002/Ecore');
+modeltype GENMODEL uses genmodel('http://www.eclipse.org/emf/2002/GenModel');
+modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
+
+--
+-- Palette
+--
+
+mapping GMFMAP::CanvasMapping::palette() : GMFGEN::Palette
+when {
+ not self.palette.oclIsUndefined();
+}
+{
+ var paletteItems : Sequence(GMFGEN::ToolGroupItem) := self.palette.tools.map paletteEntry();
+ var topLevelTools := paletteItems->reject(e | e.oclIsKindOf(GMFGEN::ToolGroup));
+
+ if topLevelTools->notEmpty() then {
+ var defaultGroup := object GMFGEN::ToolGroup {
+ title := 'Default';
+ description := 'Holds top-level non-container tools';
+ collapse := false;
+ entries += topLevelTools;
+ };
+ result.groups := result.groups->prepend(defaultGroup);
+ } endif;
+
+ result.groups += paletteItems[GMFGEN::ToolGroup];
+ result.flyout := true;
+
+ if (self.palette._default <> null) then {
+ var te := self.palette._default.resolveone(GMFGEN::ToolEntry);
+ if te <> null then te._default := true else log ('There\'s default tool specified for palette, but can\'t find gmfgen counterpart') endif;
+ } endif;
+}
+
+mapping GMFTOOL::AbstractTool::paletteEntry() : GMFGEN::ToolGroupItem {
+ init {
+ assert (false) with log('Can\'t dispatch paletteEntry() for ', self);
+ }
+}
+
+mapping GMFTOOL::PaletteSeparator::paletteEntry() : GMFGEN::ToolGroupItem {
+ init {
+ result := object GMFGEN::Separator {};
+ }
+}
+
+mapping GMFTOOL::CreationTool::paletteEntry() : GMFGEN::ToolGroupItem {
+ init {
+ var r := object GMFGEN::ToolEntry {};
+ setupCommonToolEntry(self, r);
+ result := r;
+ }
+}
+
+mapping GMFTOOL::GenericTool::paletteEntry() : GMFGEN::ToolGroupItem
+when {
+ not self.toolClass.oclIsUndefined() or self.toolClass->notEmpty()
+}
+{
+ init {
+ var r := object GMFGEN::ToolEntry {};
+ r.qualifiedToolName := self.toolClass;
+ setupCommonToolEntry(self, r);
+ result := r;
+ }
+}
+
+mapping GMFTOOL::StandardTool::paletteEntry() : GMFGEN::ToolGroupItem {
+ init {
+ var r := object GMFGEN::StandardEntry {};
+ switch {
+ case (self.toolKind = StandardToolKind::SELECT) r.kind := StandardEntryKind::SELECT;
+ case (self.toolKind = StandardToolKind::MARQUEE) r.kind := StandardEntryKind::MARQUEE;
+ case (self.toolKind = StandardToolKind::ZOOM_PAN) r.kind := StandardEntryKind::ZOOM;
+ };
+ setupCommonToolEntry(self, r);
+ result := r;
+ }
+}
+
+mapping GMFTOOL::ToolGroup::paletteEntry() : GMFGEN::ToolGroupItem {
+ init {
+ var r := object GMFGEN::ToolGroup {};
+ r.stack := self.stack;
+ r.collapse := self.collapsible;
+ setupCommonToolEntry(self, r);
+ r.entries += self.tools.map paletteEntry();
+ result := r;
+ }
+}
+
+-- XXX or helper GMFGEN::EntryBase::setupCommonToolEntry()?
+helper setupCommonToolEntry(in tool : GMFTOOL::AbstractTool, inout genTool : GMFGEN::EntryBase) {
+ genTool.title := tool.title;
+ genTool.description := tool.description;
+
+ if tool.largeIcon.oclIsTypeOf(GMFTOOL::BundleImage) then
+ genTool.largeIconPath := tool.largeIcon.oclAsType(GMFTOOL::BundleImage).constructIconPath()
+ endif;
+
+ if tool.smallIcon.oclIsTypeOf(GMFTOOL::BundleImage) then
+ genTool.smallIconPath := tool.smallIcon.oclAsType(GMFTOOL::BundleImage).constructIconPath()
+ endif;
+}
+
+-- FIXME process path (makeRelative/makeAbsolute) as in original java code
+query GMFTOOL::BundleImage::constructIconPath() : String =
+ if self.path.oclIsUndefined() or self.path.trim().size() = 0 then null else
+ if self.bundle.oclIsUndefined() or self.bundle.trim().size() = 0 then
+ self.path.makeRelative()
+ else
+ self.bundle.makeAbsolute() + self.path
+ endif
+ endif;
+
+-- FIXME
+query String::makeRelative(): String = self;
+
+query String::makeAbsolute(): String =
+ if self.startsWith('/') or self->exists(e | e = ':') then self + '/' else '/' + self + '/' endif;
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto
new file mode 100644
index 0000000..9ce7819
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Parsers.qvto
@@ -0,0 +1,46 @@
+library Parsers;
+
+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');
+
+--
+-- Parsers
+--
+
+property designLabelParser: GenParserImplementation = null;
+property auxParser: GenParserImplementation = null;
+
+mapping GMFMAP::Mapping::createGenParsers(): GenParsers {
+ implementations += GMFGEN::GenParserImplementation.allInstances();
+ extensibleViaService := true;
+
+ if this.designLabelParser <> null then
+ implementations += this.designLabelParser
+ endif;
+ if this.auxParser <> null then
+ implementations += this.auxParser
+ endif;
+}
+
+mapping GMFMAP::OclChoiceLabelMapping::createOclChoiceParser(): GMFGEN::OclChoiceParser {
+ if not self.itemsExpression.oclIsUndefined() then
+ result.itemsExpression := self.itemsExpression.map createValueExpression()
+ endif;
+ if not self.showExpression.oclIsUndefined() then
+ result.showExpression := self.showExpression.map createValueExpression()
+ endif;
+
+ GenEditorGenerator.allInstances()->asSequence()->first().labelParsers.implementations += result;
+}
+
+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
+ let firstFeature = self.features->first() in
+ let firstEditFeature = self.editableFeatures->first() in
+ if firstFeature <> firstEditFeature then false else firstFeature.eType.oclIsKindOf(EEnum) endif
+ endif
+ endif;
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/ValueExpressions.qvto b/plugins/org.eclipse.gmf.bridge/transforms/ValueExpressions.qvto
new file mode 100644
index 0000000..729cc05
--- /dev/null
+++ b/plugins/org.eclipse.gmf.bridge/transforms/ValueExpressions.qvto
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2009, 2012 Borland Software Corporation & 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
+ * Guillaume Hillairet (Montages A.G.)
+ */
+library ValueExpressions;
+
+modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
+modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
+
+--
+-- ValueExpression
+--
+
+mapping GMFMAP::ValueExpression::createValueExpression(): GMFGEN::ValueExpression
+ disjuncts
+ GMFMAP::ValueExpression::createGenValueExpression, GMFMAP::Constraint::createConstraint
+ {}
+
+mapping GMFMAP::ValueExpression::createGenValueExpression(): GMFGEN::ValueExpression
+when {
+ self.oclIsTypeOf(ValueExpression)
+}
+{
+ body := self.body;
+}
+
+mapping GMFMAP::Constraint::createConstraint(): GMFGEN::GenConstraint {
+ body := self.body;
+}
+
+mapping GMFMAP::ValueExpression::createExpressionProvider(): GenExpressionProviderBase {
+ init {
+ switch {
+ case (self.language = Language::java) { result := object GenJavaExpressionProvider {} };
+ case (self.language = Language::ocl) { result := object GenExpressionInterpreter { language := self.language() } };
+ case (self.language = Language::regexp) { result := object GenExpressionInterpreter { language := self.language() } };
+ case (self.language = Language::nregexp) { result := object GenExpressionInterpreter { language := self.language() } };
+ case (self.language = GenLanguage::_literal) { result := object GenLiteralExpressionProvider {} };
+ else { result := object GenExpressionInterpreter {}; }
+ };
+ }
+
+ expressions += ValueExpression.allInstances()->select(e | e.language = self.language)->map createValueExpression();
+}
+
+--
+-- Constraints and initializers
+--
+
+mapping GMFMAP::LinkConstraints::structure() : GMFGEN::GenLinkConstraints {
+ sourceEnd := self.sourceEnd.map createConstraint();
+ targetEnd := self.targetEnd.map createConstraint();
+}
+
+--
+-- Helpers
+--
+
+helper GMFMAP::ValueExpression::language(): GenLanguage =
+ switch {
+ case (self.language = Language::java) GenLanguage::java;
+ case (self.language = Language::ocl) GenLanguage::ocl;
+ case (self.language = Language::regexp) GenLanguage::regexp;
+ case (self.language = Language::nregexp) GenLanguage::nregexp;
+ case (self.language = Language::_literal) return GenLanguage::_literal;
+ else GenLanguage::ocl;
+ };
+ \ No newline at end of file
diff --git a/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto b/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
index f58b2bd..0bf43bb 100644
--- a/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
+++ b/plugins/org.eclipse.gmf.bridge/transforms/Viewmaps.qvto
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2009 Borland Software Corporation & others
+ * Copyright (c) 2009, 2012 Borland Software Corporation & others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,7 +12,6 @@
*/
import xpt.XpandFacade;
import Map2GenUtil;
-import Map2GenMappings;
modeltype GMFMAP uses mappings('http://www.eclipse.org/gmf/2006/mappings');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
@@ -77,14 +76,12 @@ mapping GMFGRAPH::Canvas::viewmap() : GMFGEN::Viewmap when {true} {
-- ChildReference
-- =================================================================================================
-helper GMFMAP::ChildReference::viewmap(node: GMFMAP::NodeMapping) : GMFGEN::Viewmap {
- return
+helper GMFMAP::ChildReference::viewmap(node: GMFMAP::NodeMapping) : GMFGEN::Viewmap =
if node.isPureLabelNode() then
node.labelMappings->first().diagramLabel.map viewmap()
else
node.diagramNode.map viewmap()
endif;
-}
-- =================================================================================================
-- Node
@@ -100,9 +97,8 @@ helper GMFGRAPH::Node::viewmap(): GMFGEN::Viewmap {
return rs;
}
-query GMFGRAPH::Node::hasResizeConstraints(): Boolean {
- return not (self.resizeConstraint.oclIsUndefined() or (self.resizeConstraint = Direction::NSEW))
-}
+query GMFGRAPH::Node::hasResizeConstraints(): Boolean =
+ not (self.resizeConstraint.oclIsUndefined() or (self.resizeConstraint = Direction::NSEW));
query GMFGRAPH::Node::hasDefaultSize(): Boolean {
var facet : DefaultSizeFacet := self.facets[DefaultSizeFacet]->first();
@@ -203,8 +199,8 @@ helper GMFGRAPH::DiagramLabel::viewmap(): GMFGEN::Viewmap {
return rs;
}
-helper DiagramLabel::labelOffSetAttributes(position: Integer): LabelOffsetAttributes {
- return object LabelOffsetAttributes {
+helper DiagramLabel::labelOffSetAttributes(position: Integer): LabelOffsetAttributes =
+ object LabelOffsetAttributes {
var offsetFacet := self.findOffsetFacet();
if not offsetFacet.oclIsUndefined() then {
x := offsetFacet.x;
@@ -213,7 +209,6 @@ helper DiagramLabel::labelOffSetAttributes(position: Integer): LabelOffsetAttrib
y := (position + 1) * 20;
} endif;
};
-}
-- =================================================================================================
-- Figure
@@ -258,7 +253,8 @@ helper GMFGRAPH::FigureDescriptor::viewmap(childAccess : GMFGRAPH::ChildAccess)
attributes := childAccess.figure.createStyleAttributes();
};
-query GMFGRAPH::Figure::isBareInstance() : Boolean { return false; }
+query GMFGRAPH::Figure::isBareInstance() : Boolean = false;
+
query GMFGRAPH::RealFigure::isBareInstance() : Boolean {
if self.children->notEmpty() then return false endif;
if self.oclIsKindOf(GMFGRAPH::Label) then {
@@ -293,9 +289,8 @@ query GMFGRAPH::RealFigure::isBareInstance() : Boolean {
return true;
}
-query DiagramElement::findOffsetFacet(): LabelOffsetFacet {
- return self.facets->selectOne(e | e.oclIsKindOf(LabelOffsetFacet)).oclAsType(LabelOffsetFacet)
-}
+query DiagramElement::findOffsetFacet(): LabelOffsetFacet =
+ self.facets->selectOne(e | e.oclIsKindOf(LabelOffsetFacet)).oclAsType(LabelOffsetFacet);
query DiagramElement::findIndex(): Integer {
var container := self.oclAsType(EObject).eContainer();
@@ -314,6 +309,7 @@ query DiagramElement::findIndex(): Integer {
-- =================================================================================================
-- Templates
-- =================================================================================================
+
property templateRoots : Sequence(String) = Sequence {'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/'};
property mapModeTemplateRoots : String = 'platform:/plugin/org.eclipse.gmf.graphdef.codegen/templates/rt_mm/';
property useMapMode : Boolean = false;
@@ -322,5 +318,6 @@ helper setMapMode(mapMode: Boolean) {
this.useMapMode := mapMode;
return;
}
+
query templates(): Sequence(String) =
if useMapMode then this.templateRoots->prepend(this.mapModeTemplateRoots) else this.templateRoots endif;