Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » c:iterate and inheritance in a model
c:iterate and inheritance in a model [message #28183] Tue, 24 July 2007 10:07 Go to next message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Hi,
I'm wondering if it's possible to loop through two different classes in a
EMF model if one inherits the other. Let's say I have the two following
classes in my diagram:
Apple(name, color) <---- SpecialApple (specialAttribute)

SpecialApple inherits the name and color from the Apple class.

Now if I want to iterate through all the apples to print their names for
example in a JET2 transformation I can do two loops. One goes through all my
Apples, the other through the SpecialApples.

<c:iterate select="$currTree/apples" var="currApple">
....
</c:iterate>
<c:iterate select="$currTree/specialApples" var="currApple">
....
</c:iterate>

We can see here that the two loops are nearly the same so I was wondering
weather it's possible to merge them into only one loop just for a matter of
clarity of the code

Thanks, Tex.
Re: c:iterate and inheritance in a model [message #28373 is a reply to message #28183] Wed, 25 July 2007 12:55 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Tex:

From you examples, it appears that SpecialApple and Apple are in different
collections/features of $currTree. If they are then you could try the
following:

<c:iterate select="$currTree/apples | $currTree/specialApples"
var="currApple">
</c:iterate>

But, if Apple and SpecialApple instances are added to the same feature, say
allApples, you merely have to write:

<c:iterate select="$currTree/allApples" var="currApple">
<%-- To distinguish SpecialApple for Apple --%>
<c:if test="$currApple[self::SpecialApple]">
.... stuff only for SpecialApple. similarly, self::Apple identifies only
Apple instances (not SpecialApple)
</c:if>
</c:iterate>

Paul

"Tex Twil" <chaljan@hotmail.com> wrote in message
news:f84j0v$it6$1@build.eclipse.org...
> Hi,
> I'm wondering if it's possible to loop through two different classes in a
> EMF model if one inherits the other. Let's say I have the two following
> classes in my diagram:
> Apple(name, color) <---- SpecialApple (specialAttribute)
>
> SpecialApple inherits the name and color from the Apple class.
>
> Now if I want to iterate through all the apples to print their names for
> example in a JET2 transformation I can do two loops. One goes through all
> my Apples, the other through the SpecialApples.
>
> <c:iterate select="$currTree/apples" var="currApple">
> ....
> </c:iterate>
> <c:iterate select="$currTree/specialApples" var="currApple">
> ....
> </c:iterate>
>
> We can see here that the two loops are nearly the same so I was wondering
> weather it's possible to merge them into only one loop just for a matter
> of clarity of the code
>
> Thanks, Tex.
Re: c:iterate and inheritance in a model [message #28996 is a reply to message #28373] Thu, 26 July 2007 07:55 Go to previous message
Tex Twil is currently offline Tex TwilFriend
Messages: 179
Registered: July 2009
Senior Member
Hello Paul,

the first possibility works, thank you.

regards,
Tex

"Paul Elder" <pelder@ca.ibm.com> a écrit dans le message de
news:f87h8l$ucv$1@build.eclipse.org...
> Tex:
>
> From you examples, it appears that SpecialApple and Apple are in different
> collections/features of $currTree. If they are then you could try the
> following:
>
> <c:iterate select="$currTree/apples | $currTree/specialApples"
> var="currApple">
> </c:iterate>
>
> But, if Apple and SpecialApple instances are added to the same feature,
> say allApples, you merely have to write:
>
> <c:iterate select="$currTree/allApples" var="currApple">
> <%-- To distinguish SpecialApple for Apple --%>
> <c:if test="$currApple[self::SpecialApple]">
> ... stuff only for SpecialApple. similarly, self::Apple identifies only
> Apple instances (not SpecialApple)
> </c:if>
> </c:iterate>
>
> Paul
>
> "Tex Twil" <chaljan@hotmail.com> wrote in message
> news:f84j0v$it6$1@build.eclipse.org...
>> Hi,
>> I'm wondering if it's possible to loop through two different classes in a
>> EMF model if one inherits the other. Let's say I have the two following
>> classes in my diagram:
>> Apple(name, color) <---- SpecialApple (specialAttribute)
>>
>> SpecialApple inherits the name and color from the Apple class.
>>
>> Now if I want to iterate through all the apples to print their names for
>> example in a JET2 transformation I can do two loops. One goes through all
>> my Apples, the other through the SpecialApples.
>>
>> <c:iterate select="$currTree/apples" var="currApple">
>> ....
>> </c:iterate>
>> <c:iterate select="$currTree/specialApples" var="currApple">
>> ....
>> </c:iterate>
>>
>> We can see here that the two loops are nearly the same so I was wondering
>> weather it's possible to merge them into only one loop just for a matter
>> of clarity of the code
>>
>> Thanks, Tex.
>
>
Previous Topic:JET FAQ How do I run an individual JET template and get a string back?
Next Topic:[JET2] Re: JET2: Invalid Java source folder
Goto Forum:
  


Current Time: Sat Apr 20 00:06:35 GMT 2024

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

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

Back to the top