blob: ebda7c7cac84c572194ffb2267feeb7d8525c2c7 [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 Utils;
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');
modeltype GMFGEN uses gmfgen('http://www.eclipse.org/gmf/2009/GenModel');
--
-- Properties
--
property useModeledViewmaps: Boolean = false;
property allChildReferences: Sequence(ChildReference) = Sequence{};
property childReferences: Sequence(ChildReference) = Sequence{};
property equivalentChild: Dict(ChildReference, Sequence(ChildReference)) = Dict{};
property genModel: GENMODEL::GenModel = null;
property processedNodeMappings: Sequence(NodeMapping) = Sequence{};
--
-- Helpers
--
helper GMFMAP::ChildReference::matchChildReferenceFeatures(node: GMFMAP::ChildReference) : Boolean {
var containmentFeatureMatch : Boolean;
var childrenFeatureMatch : Boolean;
var childMatch: Boolean;
if node.containmentFeature.oclIsUndefined() then
containmentFeatureMatch := self.containmentFeature.oclIsUndefined()
else {
containmentFeatureMatch := self.containmentFeature = node.containmentFeature
} endif;
if node.childrenFeature.oclIsUndefined() then
childrenFeatureMatch := self.childrenFeature.oclIsUndefined()
else
if self.childrenFeature.oclIsUndefined() then
childrenFeatureMatch := node.childrenFeature = node.containmentFeature
else
childrenFeatureMatch := node.childrenFeature = self.childrenFeature
endif
endif;
childMatch := node.referencedChild = self.child or node.child = self.child;
return containmentFeatureMatch and childrenFeatureMatch and childMatch;
}
--
-- 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
}
query GMFMAP::ChildReference::findProcessableChildReference(): ChildReference =
if childReferences->includes(self) then
self
else
equivalentChild->keys()->selectOne(e | equivalentChild->get(e)->includes(self))
endif;
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::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)
this.genModel.genPackages->union(
this.genModel.usedGenPackages)->select(gp |
gp.ecorePackage.nsURI = self.nsURI)->asSequence()->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;