QVTO applyStereotype() issue ! is it a bug?!! [message #1245968] |
Fri, 14 February 2014 09:30  |
Eclipse User |
|
|
|
Hi,
In a simple transformation example I need to refactor one model by copying stereotyped element from second input model. I'm using recent update 3.5 (25 Jan, 2014) it was successfully applying Stereotype using applyStereotype() and I verify it using getAppliedStereotypes() during transformation execution.
In fact, when I check the output xmi file the stereotype is added but not linked/referenced (applied) to the copied model element. Moreover, when I run getAppliedStereotypes() from another transformation on the refactored model I found no applied stereotype!
I do not why this behaviour.!!
Note that : this question also posted in QVTO forum but no response yet!
http://www.eclipse.org/forums/index.php/t/642760/
the following is my example code !
modeltype UML uses 'http://www.eclipse.org/uml2/2.1.0/UML';
transformation ApplyingStereotype(inout src : UML , in stereotypedModel : UML);
/**
This transformation will take two input models.
First one (src) is the model that we need to refactor it.
The second model has stereotyped states that we need just
copy it with its applied stereotypes to the scr model (refactored model - inout model)
**/
main() {
src.rootObjects()[Model]->toModel();
// according to http://www.eclipse.org/forums/index.php/t/530322/
// apply stereotypes after adding new state from stereotypedModel
src.objectsOfType(State)->copyStereotypes();
//after adding new state we list all applied stereotypes for the recent added state
src.objectsOfType(State)[name = "TestState"]->listAllAppliedStereoyes();
/**
It seems running since we will get the correct results,
but when we check the output xmi file there is no stereotype applied
to that state ! but the stereotype it self is added but not linked/referenced to the
corresponding state (the state copied from the second input model)
You can execute ListAllAppliedStereotype.qvto for verification
**/
}
mapping inout Model::toModel(){
-- note that the profile is already applied !
// for nesting models
src.objectsOfType(Model)->toModel();
src.objectsOfType(StateMachine)->toStateMachine();
}
mapping inout StateMachine::toStateMachine(){
src.objectsOfType(Region)->toRegion();
}
mapping inout Region::toRegion(){
// add new state to src model (refactored model --inout)
self.subvertex += stereotypedModel.objectsOfType(State)->selectOne(S : State | S.name = "TestState");
}
// in the context of src model
mapping inout State::copyStereotypes() when {self.name = "TestState"}
{
// select matching stereotyped state from stereotypedModel
var stereotypedState : State;
stereotypedState := stereotypedModel.objectsOfType(State)->selectOne(S : State | S.name = self.name);
var stereotypSet : Set(Stereotype);
stereotypSet := stereotypedState.getAppliedStereotypes();
// applyStereotype to the recent added state in the src model.
stereotypSet->forEach(stereotyp){
self.applyStereotype(stereotyp);
}
}
query State::listAllAppliedStereoyes() : Void{
var value : String ;
self.getAppliedStereotypes()->forEach(appliedStereoType){
log("New added State Name is : " + self.name);
log("Applied Stereotype is : " + appliedStereoType.name);
appliedStereoType.attribute->forEach(attr){
value := self.getValue(appliedStereoType, attr.name).toString();
log("attribute name is : " + attr.name + " and value is : " + value);
}
}
}
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08929 seconds