[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] Re: [ATL]How to add a binding in if-else statement

Hello,

You can try this solution (assuming that p.getName() returns a Sequence):

rule ParticipantToComponent {
  from
	p : UML!Participant
  to
	c : CLASS!Component (
		name<-p.name,
		service <- if (not p.getName().isEmpty())
				then s
				else OclUndefined
			    endif
	),
        s : CLASS!Service (
		provide<-prList
	),
      prList :distinct DS!Tprovide foreach(prName in p.getName())(
		name<-prName
	)
 }

Best regards,

William

Rajalaxmi a écrit :
Hi All,

I have the following grammar rule.
module UMLToCLASS; -- Module Template
create OUT : CLASS from IN : UML;

helper context UML!Participant def: getName(): Set(String) = self.bind->collect(e|e.name).asSet();
rule ParticipantToComponent
{
from p :UML!Participant
to c :CLASS!Component(name<-p.name),
s :CLASS!Service(provide<-prList),
prList:distinct DS!Tprovide foreach(prName in p.getName())
(name<-prName)
-- if (not prList.isEmpty()) then
-- do
-- {
-- c.service<-s;
-- } -- else
-- false
-- endif
}



I am transforming Participant to Component.
I would like to add the binding c.service<-s if prList isNotEmpty else i should not add this binding. (Something similar to the commented lines, however this code does not work because i dont know what the return value should be. Can anyone please suggest how i can write this binding rule here.


Thank you very much

Kind Regards

Rajalaxmi