blob: 25b848702b1491f3d4e88b295dec3acebe78fc84 [file] [log] [blame]
/**
* 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 Utils;
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;
parser := self.map createExternalParser();
}
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();
parser := if self.isEnumLabelMapping() then self.getOrCreateEnumParser() else self.getOrCreatePredefinedParser() endif;
}
mapping GMFMAP::DesignLabelMapping::createDesignLabelModelFacet(node: NeedsContainment) : GMFGEN::DesignLabelModelFacet {
-- if designLabelParser = null then
-- designLabelParser := object GMFGEN::ExternalParser {}
-- endif;
-- parser := designLabelParser;
parser := self.map createExternalParser();
}
mapping GMFMAP::ExpressionLabelMapping::createExpressionLabelModelFacet(node: NeedsContainment): GMFGEN::ExpressionLabelModelFacet {
parser := self.map createExpressionLabelParser();
}
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().equals(self.language)
);
query GenLanguage::equals(lang: Language) : Boolean = self.repr() = lang.repr();
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;
};