Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Do a if else in a matched rule ( do {} )
[ATL] Do a if else in a matched rule ( do {} ) [message #102709] Wed, 01 April 2009 11:12 Go to next message
micromilua  is currently offline micromilua Friend
Messages: 20
Registered: July 2009
Junior Member
Hi:

Before my question, I read the wiki , the website is below
http://wiki.eclipse.org/ATL/User_Guide#Matched_Rules
============================================================ =====
it say:
Each matched rule is identified by its name (rule_name). A matched rule
name must be unique within an ATL transformation. An ATL matched rule is
composed of two mandatory (the from and the to parts) and two optional
(the using and the do parts) sections. Note that the different variables
that may be declared in the scope of a rule (the source and target pattern
elements and the local variables) must have a unique name.

This restriction does not apply to the OCL expressions contained by this
rule. The different sections of an ATL matched rule are detailed in the
following subsections.

so...I don't know whether as follow(does not apply to the OCL expressions
contained by this rule)
============================================================ =====
as my title
my scenario is

When I do UML2COPY
if a class has stereotype <<fruit>>
then it should re-apply the stereotype

my ATL code is below:

helper context UML2!"uml::Element" def: hasStereotype(stereotype : String)
: Boolean = self.getAppliedStereotypes() -> collect(st | st.name) ->
includes(stereotype);


do { t.applyStereotype(UML2!Stereotype.allInstances()->select(st |
st.name = 'fruit').first());
}

if I want to finish my scenario,
Can anyone give me some tip or direction?
Very Thanks

micromilua
Re: [ATL] Do a if else in a matched rule ( do {} ) [message #102763 is a reply to message #102709] Wed, 01 April 2009 12:28 Go to previous message
Max Bureck is currently offline Max BureckFriend
Messages: 72
Registered: July 2009
Member
1) you can shorten your expressions a bit:

helper context UML2!"uml::Element" def: hasStereotype(stereotype : String)
: Boolean = self.getAppliedStereotypes() -> exists(st | st.name=stereotype
);


do { t.applyStereotype( UML2!Stereotype.allInstances()->any(st | st.name
= 'fruit') );
}

2) why do you want to re-apply a stereotype? I hope you do not want to
re-apply them on the input-model, because input-models are read-only in
ATL (so the execution can be kept deterministic).
If you want to change property values of the applied stereotypes you can
do that without re-applying them (see UML2 API
org.eclipse.uml2.uml.Element#setValue(Stereotype stereotype,
java.lang.String propertyName, java.lang.Object newValue) ).
If you really want to re-apply a stereotype, you have to use the method
org.eclipse.uml2.uml.Element#unapplyStereotype(Stereotype stereotype) and
then apply it again.
Btw. I think it is better to use t.getApplicableStereotypes() than using
UML2!Stereotype.allInstances(). You might have to pass the UML2 model
containing the profile, the stereotype is defined in, as an input-model to
the transformation.

Greetings,
Max
Previous Topic:[ATL] create empty set
Next Topic:[ATL] Creating new elements recursively
Goto Forum:
  


Current Time: Thu Apr 25 03:52:52 GMT 2024

Powered by FUDForum. Page generated in 0.03121 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top