[EMFTVM] Could resolve functions return null when no image found ? [message #1256208] |
Tue, 25 February 2014 07:49 |
EtienneB Mising name Messages: 35 Registered: June 2011 |
Member |
|
|
Dear Dennis,
I wanted to ask if it would be possible to add an option in the emftvm launcher in order to allow partial resolution of outut elements with the resolve operations (resolveTemp, resolve...). Indeed, I would like to activate or deactivate the fact that the emftvm throws an exception when resolveTemp does not manage to find the image of the source element passed as parameter.
One of the reasons for this is that I collect elements that could be produced by different rules and I don't want to repeat the condition of application of each rule variant all the time.
For instance, if I write (ATL pseudo code):
rule R1
{
from
e: IN!Element
(e.name='root')
to
r: OUT!Root
....
}
rule R2
{
from
e: IN!Element
(e.name='operation')
to
op: OUT!Operation
....
}
rule R
{
from
d_in: In!Diagram
to
d_out: OUT!Diagram
(
elements <- d_in.elements->select(e|e.name='root')
->collect(e|thisModule.resolveTemp(e, 'r'))
->union(d_in.elements->select(e|e.name='operation')
->collect(e|thisModule.resolveTemp(e, 'op'))
}
it works fine; but maintaining rule R becomes complex if I have too many way to map objects of type Element.
Instead of repeating the filter (select clause) in rule R, I would prefer to write:
rule R
{
from
d_in: In!Diagram
to
d_out: OUT!Diagram
(
elements <- d_in.elements->collect(e|thisModule.resolveTemp(e, 'r'))
->union(d_in.elements->collect(e|thisModule.resolveTemp(e, 'op'))
->excluding(OclUndefined)
)
}
The only problem here is that the EMFTVM runtime throws an exception if resolve functions do not work. Would it be possible to have an option in the emftvm launch in order to deactivate this exception, and return null (OclUndefined) instead?
I would find it more convenient to be able to control this behaviour with a simple option passed as parameter of the ExecEnv launch function or to the constructor of this class.
What is your opinion about this?
Thanks for your answer,
Etienne.
|
|
|
Re: [EMFTVM] Could resolve functions return null when no image found ? [message #1256578 is a reply to message #1256208] |
Tue, 25 February 2014 15:28 |
|
This is what we use at HealthConnect:
--- Returns the same as thisModule.resolveTemp(var : OclAny, rule_name : String, target_pattern_name : String),
--- except that it returns OclUndefined if no trace exists instead of throwing an error.
helper def : resolveIfExists(var : Sequence(OclAny), rule_name : String, target_pattern_name : String) : OclAny =
let tr : OclAny = thisModule.traces.getLinksByRule(rule_name, false) in
if tr.oclIsUndefined() then
OclUndefined
else
let sel : OclAny = tr.getUniqueSourceElements(var) in
if sel.oclIsUndefined() then
OclUndefined
else
let te : OclAny = sel.getSourceElements().get(0).getSourceOf().getTargetElement(target_pattern_name) in
if te.oclIsUndefined() then
OclUndefined
else
te.getObject()
endif
endif
endif;
You may adapt the code to use thisModule.traces.getDefaultSourceElement(var) instead. See the EMFTVM Trace metamodel for details (nsURI="http://www.eclipse.org/m2m/atl/emftvm/2011/Trace").
Cheers,
Dennis
|
|
|
|
Powered by
FUDForum. Page generated in 0.02474 seconds