Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » Explicit invocation of ETL rule
Explicit invocation of ETL rule [message #490312] Thu, 08 October 2009 10:41 Go to next message
Eclipse UserFriend
Originally posted by: c.k.holmes.lboro.ac.uk

Dear All,
I have two transformation rules of the form:

rule LogAttributesType2LogAttributesSwitchType
transform logAtts1 : Source!LOGATTRIBUTESType
to switchType : Target!LogAttributesSwitchType {
guard : logAtts1.type = Source!LogAttType#CODE and
logAtts1.codeType = Source!CodeType#SWITCH
'LogAttributesType2LogAttributesSwitchType'.println();
--<blah/>
switchType.switchValues := logAtts1.cODEVAL.collect(v |
v.transformCodeVal2SwitchVal());
}

rule LogAttributesType2LogAttributesEnumType
transform logAtts1 : Source!LOGATTRIBUTESType
to enumType : Target!LogAttributesEnumType {
guard : logAtts1.type = Source!LogAttType#CODE and
logAtts1.codeType = Source!CodeType#ENUM
'LogAttributesType2LogAttributesEnumType'.println();
--<blah/>
enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
v.transformCodeVal2EnumVal());
}

The 'cODEVAL' attribute on the source class is the same in both cases,
however I want to apply different transformation rules to this attribute
depending of which transformation is currently being invoked.

I have defined the two transformation operations as:

operation Source!CODEVALType transformCodeVal2EnumVal() : Target!EnumVal {
var result : Target!EnumVal;
'transformCodeVal2EnumVal'.println();
(self.eClass().name).println();
result.value := self.value;
result.meaning := self.meaning;
return result;
}

operation Source!CODEVALType transformCodeVal2SwitchVal() :
Target!SwitchVal {
var result : Target!SwitchVal;
'transformCodeVal2SwitchVal'.println();
(self.eClass().name).println();
result.value := self.value;
result.meaning := self.meaning;
return result;
}

The execution trace shows the following error message:
transformCodeType2LogAttCodeType
transformCodeVal2EnumVal
CODEVALType
EXCEPTION: Called feature value on undefined object
(C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)

The appropriate transformation operation has been invoked
(transformCodeVal2EnumVal), and self is of the expected type
(CODEVALType), however it appears to suggest that the receiver (self) is
undefined when I try to access one of the attributes.

Using the following 'generic' transformation runs without throwing an
error (although it doesn't provide me with the flexibility of specifying
when to return an EnumVal object and when to return a SwitchVal object):

rule CodeVal2EnumVal
transform cv1 : Source!CODEVALType
to ev2 : Target!EnumVal {
ev2.value := cv1.value;
ev2.meaning := cv1.meaning;
}

So I guess I have two questions:
1. Why does self.eClass().name return the expected type (CODEVALType),
and yet on the very next line when I try to access self.value does self
appear to be undefined?
2. Is there an easier way to achieve the explicit invocation of one rule
from another?

Best Wishes
Chris
Re: Explicit invocation of ETL rule [message #490371 is a reply to message #490312] Thu, 08 October 2009 13:26 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Chris,

Please see comments below:

Chris Holmes wrote:
> Dear All,
> I have two transformation rules of the form:
>
> rule LogAttributesType2LogAttributesSwitchType
> transform logAtts1 : Source!LOGATTRIBUTESType
> to switchType : Target!LogAttributesSwitchType {
> guard : logAtts1.type = Source!LogAttType#CODE and
> logAtts1.codeType = Source!CodeType#SWITCH
> 'LogAttributesType2LogAttributesSwitchType'.println();
> --<blah/>
> switchType.switchValues := logAtts1.cODEVAL.collect(v |
> v.transformCodeVal2SwitchVal());
> }
>
> rule LogAttributesType2LogAttributesEnumType
> transform logAtts1 : Source!LOGATTRIBUTESType
> to enumType : Target!LogAttributesEnumType {
> guard : logAtts1.type = Source!LogAttType#CODE and
> logAtts1.codeType = Source!CodeType#ENUM
> 'LogAttributesType2LogAttributesEnumType'.println();
> --<blah/>
> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
> v.transformCodeVal2EnumVal());
> }
>
> The 'cODEVAL' attribute on the source class is the same in both cases,
> however I want to apply different transformation rules to this attribute
> depending of which transformation is currently being invoked.
>
> I have defined the two transformation operations as:
>
> operation Source!CODEVALType transformCodeVal2EnumVal() : Target!EnumVal {
> var result : Target!EnumVal;
> 'transformCodeVal2EnumVal'.println();
> (self.eClass().name).println();
> result.value := self.value;
> result.meaning := self.meaning;
> return result;
> }
>
> operation Source!CODEVALType transformCodeVal2SwitchVal() :
> Target!SwitchVal {
> var result : Target!SwitchVal;
> 'transformCodeVal2SwitchVal'.println();
> (self.eClass().name).println();
> result.value := self.value;
> result.meaning := self.meaning;
> return result;
> }
>
> The execution trace shows the following error message:
> transformCodeType2LogAttCodeType
> transformCodeVal2EnumVal
> CODEVALType
> EXCEPTION: Called feature value on undefined object
> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)

This happens because result (rather than self) is null in both
operations. To initialize it you need to replace

var result : Target!EnumVal;

with

var result : new Target!EnumVal;

(and similarly for the second operation)

>
> The appropriate transformation operation has been invoked
> (transformCodeVal2EnumVal), and self is of the expected type
> (CODEVALType), however it appears to suggest that the receiver (self) is
> undefined when I try to access one of the attributes.
>
> Using the following 'generic' transformation runs without throwing an
> error (although it doesn't provide me with the flexibility of specifying
> when to return an EnumVal object and when to return a SwitchVal object):
>
> rule CodeVal2EnumVal
> transform cv1 : Source!CODEVALType
> to ev2 : Target!EnumVal {
> ev2.value := cv1.value;
> ev2.meaning := cv1.meaning;
> }
>
> So I guess I have two questions:
> 1. Why does self.eClass().name return the expected type (CODEVALType),
> and yet on the very next line when I try to access self.value does self
> appear to be undefined?
> 2. Is there an easier way to achieve the explicit invocation of one rule
> from another?

The .equivalent() operation explicitly calls all the rules applicable to
the source. Would you like to be able to invoke only a specific named
rule instead?

>
> Best Wishes
> Chris

Cheers,
Dimitris

--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
Re: Explicit invocation of ETL rule [message #490386 is a reply to message #490371] Thu, 08 October 2009 13:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: c.k.holmes.lboro.ac.uk

Hi Dimitris,
Thanks for identifying my error - I'm somewhat embarrassed that I didn't
spot it myself :(

It would be useful to be able to invoke a rule by name, in this instance
at least, rather than relying on the equivalent() operation to do the
type match.

Thanks once again.

Best Wishes
Chris

Dimitris Kolovos wrote:
> Hi Chris,
>
> Please see comments below:
>
> Chris Holmes wrote:
>> Dear All,
>> I have two transformation rules of the form:
>>
>> rule LogAttributesType2LogAttributesSwitchType
>> transform logAtts1 : Source!LOGATTRIBUTESType
>> to switchType : Target!LogAttributesSwitchType {
>> guard : logAtts1.type = Source!LogAttType#CODE and
>> logAtts1.codeType = Source!CodeType#SWITCH
>> 'LogAttributesType2LogAttributesSwitchType'.println();
>> --<blah/>
>> switchType.switchValues := logAtts1.cODEVAL.collect(v |
>> v.transformCodeVal2SwitchVal());
>> }
>>
>> rule LogAttributesType2LogAttributesEnumType
>> transform logAtts1 : Source!LOGATTRIBUTESType
>> to enumType : Target!LogAttributesEnumType {
>> guard : logAtts1.type = Source!LogAttType#CODE and
>> logAtts1.codeType = Source!CodeType#ENUM
>> 'LogAttributesType2LogAttributesEnumType'.println();
>> --<blah/>
>> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
>> v.transformCodeVal2EnumVal());
>> }
>>
>> The 'cODEVAL' attribute on the source class is the same in both cases,
>> however I want to apply different transformation rules to this
>> attribute depending of which transformation is currently being invoked.
>>
>> I have defined the two transformation operations as:
>>
>> operation Source!CODEVALType transformCodeVal2EnumVal() :
>> Target!EnumVal {
>> var result : Target!EnumVal;
>> 'transformCodeVal2EnumVal'.println();
>> (self.eClass().name).println();
>> result.value := self.value;
>> result.meaning := self.meaning;
>> return result;
>> }
>>
>> operation Source!CODEVALType transformCodeVal2SwitchVal() :
>> Target!SwitchVal {
>> var result : Target!SwitchVal;
>> 'transformCodeVal2SwitchVal'.println();
>> (self.eClass().name).println();
>> result.value := self.value;
>> result.meaning := self.meaning;
>> return result;
>> }
>>
>> The execution trace shows the following error message:
>> transformCodeType2LogAttCodeType
>> transformCodeVal2EnumVal
>> CODEVALType
>> EXCEPTION: Called feature value on undefined object
>> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)
>
> This happens because result (rather than self) is null in both
> operations. To initialize it you need to replace
>
> var result : Target!EnumVal;
>
> with
>
> var result : new Target!EnumVal;
>
> (and similarly for the second operation)
>
>>
>> The appropriate transformation operation has been invoked
>> (transformCodeVal2EnumVal), and self is of the expected type
>> (CODEVALType), however it appears to suggest that the receiver (self)
>> is undefined when I try to access one of the attributes.
>>
>> Using the following 'generic' transformation runs without throwing an
>> error (although it doesn't provide me with the flexibility of
>> specifying when to return an EnumVal object and when to return a
>> SwitchVal object):
>>
>> rule CodeVal2EnumVal
>> transform cv1 : Source!CODEVALType
>> to ev2 : Target!EnumVal {
>> ev2.value := cv1.value;
>> ev2.meaning := cv1.meaning;
>> }
>>
>> So I guess I have two questions:
>> 1. Why does self.eClass().name return the expected type (CODEVALType),
>> and yet on the very next line when I try to access self.value does
>> self appear to be undefined?
>> 2. Is there an easier way to achieve the explicit invocation of one
>> rule from another?
>
> The .equivalent() operation explicitly calls all the rules applicable to
> the source. Would you like to be able to invoke only a specific named
> rule instead?
>
>>
>> Best Wishes
>> Chris
>
> Cheers,
> Dimitris
>
Re: Explicit invocation of ETL rule [message #490387 is a reply to message #490386] Thu, 08 October 2009 14:01 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Chris,

Chris Holmes wrote:
> Hi Dimitris,
> Thanks for identifying my error - I'm somewhat embarrassed that I didn't
> spot it myself :(

No worries. It took me a while to figure this out too - mainly because I
was looking at the wrong place...

>
> It would be useful to be able to invoke a rule by name, in this instance
> at least, rather than relying on the equivalent() operation to do the
> type match.

Could you please file an enhancement request in the bugzilla?

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GMT& component=Epsilon

>
> Thanks once again.

You're welcome!

>
> Best Wishes
> Chris
>
Cheers,
Dimitris

> Dimitris Kolovos wrote:
>> Hi Chris,
>>
>> Please see comments below:
>>
>> Chris Holmes wrote:
>>> Dear All,
>>> I have two transformation rules of the form:
>>>
>>> rule LogAttributesType2LogAttributesSwitchType
>>> transform logAtts1 : Source!LOGATTRIBUTESType
>>> to switchType : Target!LogAttributesSwitchType {
>>> guard : logAtts1.type = Source!LogAttType#CODE and
>>> logAtts1.codeType = Source!CodeType#SWITCH
>>> 'LogAttributesType2LogAttributesSwitchType'.println();
>>> --<blah/>
>>> switchType.switchValues := logAtts1.cODEVAL.collect(v |
>>> v.transformCodeVal2SwitchVal());
>>> }
>>>
>>> rule LogAttributesType2LogAttributesEnumType
>>> transform logAtts1 : Source!LOGATTRIBUTESType
>>> to enumType : Target!LogAttributesEnumType {
>>> guard : logAtts1.type = Source!LogAttType#CODE and
>>> logAtts1.codeType = Source!CodeType#ENUM
>>> 'LogAttributesType2LogAttributesEnumType'.println();
>>> --<blah/>
>>> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
>>> v.transformCodeVal2EnumVal());
>>> }
>>>
>>> The 'cODEVAL' attribute on the source class is the same in both
>>> cases, however I want to apply different transformation rules to this
>>> attribute depending of which transformation is currently being invoked.
>>>
>>> I have defined the two transformation operations as:
>>>
>>> operation Source!CODEVALType transformCodeVal2EnumVal() :
>>> Target!EnumVal {
>>> var result : Target!EnumVal;
>>> 'transformCodeVal2EnumVal'.println();
>>> (self.eClass().name).println();
>>> result.value := self.value;
>>> result.meaning := self.meaning;
>>> return result;
>>> }
>>>
>>> operation Source!CODEVALType transformCodeVal2SwitchVal() :
>>> Target!SwitchVal {
>>> var result : Target!SwitchVal;
>>> 'transformCodeVal2SwitchVal'.println();
>>> (self.eClass().name).println();
>>> result.value := self.value;
>>> result.meaning := self.meaning;
>>> return result;
>>> }
>>>
>>> The execution trace shows the following error message:
>>> transformCodeType2LogAttCodeType
>>> transformCodeVal2EnumVal
>>> CODEVALType
>>> EXCEPTION: Called feature value on undefined object
>>> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)
>>
>> This happens because result (rather than self) is null in both
>> operations. To initialize it you need to replace
>>
>> var result : Target!EnumVal;
>>
>> with
>>
>> var result : new Target!EnumVal;
>>
>> (and similarly for the second operation)
>>
>>>
>>> The appropriate transformation operation has been invoked
>>> (transformCodeVal2EnumVal), and self is of the expected type
>>> (CODEVALType), however it appears to suggest that the receiver (self)
>>> is undefined when I try to access one of the attributes.
>>>
>>> Using the following 'generic' transformation runs without throwing an
>>> error (although it doesn't provide me with the flexibility of
>>> specifying when to return an EnumVal object and when to return a
>>> SwitchVal object):
>>>
>>> rule CodeVal2EnumVal
>>> transform cv1 : Source!CODEVALType
>>> to ev2 : Target!EnumVal {
>>> ev2.value := cv1.value;
>>> ev2.meaning := cv1.meaning;
>>> }
>>>
>>> So I guess I have two questions:
>>> 1. Why does self.eClass().name return the expected type
>>> (CODEVALType), and yet on the very next line when I try to access
>>> self.value does self appear to be undefined?
>>> 2. Is there an easier way to achieve the explicit invocation of one
>>> rule from another?
>>
>> The .equivalent() operation explicitly calls all the rules applicable
>> to the source. Would you like to be able to invoke only a specific
>> named rule instead?
>>
>>>
>>> Best Wishes
>>> Chris
>>
>> Cheers,
>> Dimitris
>>


--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
Re: Explicit invocation of ETL rule [message #581684 is a reply to message #490312] Thu, 08 October 2009 13:26 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Chris,

Please see comments below:

Chris Holmes wrote:
> Dear All,
> I have two transformation rules of the form:
>
> rule LogAttributesType2LogAttributesSwitchType
> transform logAtts1 : Source!LOGATTRIBUTESType
> to switchType : Target!LogAttributesSwitchType {
> guard : logAtts1.type = Source!LogAttType#CODE and
> logAtts1.codeType = Source!CodeType#SWITCH
> 'LogAttributesType2LogAttributesSwitchType'.println();
> --<blah/>
> switchType.switchValues := logAtts1.cODEVAL.collect(v |
> v.transformCodeVal2SwitchVal());
> }
>
> rule LogAttributesType2LogAttributesEnumType
> transform logAtts1 : Source!LOGATTRIBUTESType
> to enumType : Target!LogAttributesEnumType {
> guard : logAtts1.type = Source!LogAttType#CODE and
> logAtts1.codeType = Source!CodeType#ENUM
> 'LogAttributesType2LogAttributesEnumType'.println();
> --<blah/>
> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
> v.transformCodeVal2EnumVal());
> }
>
> The 'cODEVAL' attribute on the source class is the same in both cases,
> however I want to apply different transformation rules to this attribute
> depending of which transformation is currently being invoked.
>
> I have defined the two transformation operations as:
>
> operation Source!CODEVALType transformCodeVal2EnumVal() : Target!EnumVal {
> var result : Target!EnumVal;
> 'transformCodeVal2EnumVal'.println();
> (self.eClass().name).println();
> result.value := self.value;
> result.meaning := self.meaning;
> return result;
> }
>
> operation Source!CODEVALType transformCodeVal2SwitchVal() :
> Target!SwitchVal {
> var result : Target!SwitchVal;
> 'transformCodeVal2SwitchVal'.println();
> (self.eClass().name).println();
> result.value := self.value;
> result.meaning := self.meaning;
> return result;
> }
>
> The execution trace shows the following error message:
> transformCodeType2LogAttCodeType
> transformCodeVal2EnumVal
> CODEVALType
> EXCEPTION: Called feature value on undefined object
> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)

This happens because result (rather than self) is null in both
operations. To initialize it you need to replace

var result : Target!EnumVal;

with

var result : new Target!EnumVal;

(and similarly for the second operation)

>
> The appropriate transformation operation has been invoked
> (transformCodeVal2EnumVal), and self is of the expected type
> (CODEVALType), however it appears to suggest that the receiver (self) is
> undefined when I try to access one of the attributes.
>
> Using the following 'generic' transformation runs without throwing an
> error (although it doesn't provide me with the flexibility of specifying
> when to return an EnumVal object and when to return a SwitchVal object):
>
> rule CodeVal2EnumVal
> transform cv1 : Source!CODEVALType
> to ev2 : Target!EnumVal {
> ev2.value := cv1.value;
> ev2.meaning := cv1.meaning;
> }
>
> So I guess I have two questions:
> 1. Why does self.eClass().name return the expected type (CODEVALType),
> and yet on the very next line when I try to access self.value does self
> appear to be undefined?
> 2. Is there an easier way to achieve the explicit invocation of one rule
> from another?

The .equivalent() operation explicitly calls all the rules applicable to
the source. Would you like to be able to invoke only a specific named
rule instead?

>
> Best Wishes
> Chris

Cheers,
Dimitris

--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
Re: Explicit invocation of ETL rule [message #581710 is a reply to message #490371] Thu, 08 October 2009 13:58 Go to previous message
Eclipse UserFriend
Originally posted by: c.k.holmes.lboro.ac.uk

Hi Dimitris,
Thanks for identifying my error - I'm somewhat embarrassed that I didn't
spot it myself :(

It would be useful to be able to invoke a rule by name, in this instance
at least, rather than relying on the equivalent() operation to do the
type match.

Thanks once again.

Best Wishes
Chris

Dimitris Kolovos wrote:
> Hi Chris,
>
> Please see comments below:
>
> Chris Holmes wrote:
>> Dear All,
>> I have two transformation rules of the form:
>>
>> rule LogAttributesType2LogAttributesSwitchType
>> transform logAtts1 : Source!LOGATTRIBUTESType
>> to switchType : Target!LogAttributesSwitchType {
>> guard : logAtts1.type = Source!LogAttType#CODE and
>> logAtts1.codeType = Source!CodeType#SWITCH
>> 'LogAttributesType2LogAttributesSwitchType'.println();
>> --<blah/>
>> switchType.switchValues := logAtts1.cODEVAL.collect(v |
>> v.transformCodeVal2SwitchVal());
>> }
>>
>> rule LogAttributesType2LogAttributesEnumType
>> transform logAtts1 : Source!LOGATTRIBUTESType
>> to enumType : Target!LogAttributesEnumType {
>> guard : logAtts1.type = Source!LogAttType#CODE and
>> logAtts1.codeType = Source!CodeType#ENUM
>> 'LogAttributesType2LogAttributesEnumType'.println();
>> --<blah/>
>> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
>> v.transformCodeVal2EnumVal());
>> }
>>
>> The 'cODEVAL' attribute on the source class is the same in both cases,
>> however I want to apply different transformation rules to this
>> attribute depending of which transformation is currently being invoked.
>>
>> I have defined the two transformation operations as:
>>
>> operation Source!CODEVALType transformCodeVal2EnumVal() :
>> Target!EnumVal {
>> var result : Target!EnumVal;
>> 'transformCodeVal2EnumVal'.println();
>> (self.eClass().name).println();
>> result.value := self.value;
>> result.meaning := self.meaning;
>> return result;
>> }
>>
>> operation Source!CODEVALType transformCodeVal2SwitchVal() :
>> Target!SwitchVal {
>> var result : Target!SwitchVal;
>> 'transformCodeVal2SwitchVal'.println();
>> (self.eClass().name).println();
>> result.value := self.value;
>> result.meaning := self.meaning;
>> return result;
>> }
>>
>> The execution trace shows the following error message:
>> transformCodeType2LogAttCodeType
>> transformCodeVal2EnumVal
>> CODEVALType
>> EXCEPTION: Called feature value on undefined object
>> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)
>
> This happens because result (rather than self) is null in both
> operations. To initialize it you need to replace
>
> var result : Target!EnumVal;
>
> with
>
> var result : new Target!EnumVal;
>
> (and similarly for the second operation)
>
>>
>> The appropriate transformation operation has been invoked
>> (transformCodeVal2EnumVal), and self is of the expected type
>> (CODEVALType), however it appears to suggest that the receiver (self)
>> is undefined when I try to access one of the attributes.
>>
>> Using the following 'generic' transformation runs without throwing an
>> error (although it doesn't provide me with the flexibility of
>> specifying when to return an EnumVal object and when to return a
>> SwitchVal object):
>>
>> rule CodeVal2EnumVal
>> transform cv1 : Source!CODEVALType
>> to ev2 : Target!EnumVal {
>> ev2.value := cv1.value;
>> ev2.meaning := cv1.meaning;
>> }
>>
>> So I guess I have two questions:
>> 1. Why does self.eClass().name return the expected type (CODEVALType),
>> and yet on the very next line when I try to access self.value does
>> self appear to be undefined?
>> 2. Is there an easier way to achieve the explicit invocation of one
>> rule from another?
>
> The .equivalent() operation explicitly calls all the rules applicable to
> the source. Would you like to be able to invoke only a specific named
> rule instead?
>
>>
>> Best Wishes
>> Chris
>
> Cheers,
> Dimitris
>
Re: Explicit invocation of ETL rule [message #581727 is a reply to message #490386] Thu, 08 October 2009 14:01 Go to previous message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Chris,

Chris Holmes wrote:
> Hi Dimitris,
> Thanks for identifying my error - I'm somewhat embarrassed that I didn't
> spot it myself :(

No worries. It took me a while to figure this out too - mainly because I
was looking at the wrong place...

>
> It would be useful to be able to invoke a rule by name, in this instance
> at least, rather than relying on the equivalent() operation to do the
> type match.

Could you please file an enhancement request in the bugzilla?

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GMT& component=Epsilon

>
> Thanks once again.

You're welcome!

>
> Best Wishes
> Chris
>
Cheers,
Dimitris

> Dimitris Kolovos wrote:
>> Hi Chris,
>>
>> Please see comments below:
>>
>> Chris Holmes wrote:
>>> Dear All,
>>> I have two transformation rules of the form:
>>>
>>> rule LogAttributesType2LogAttributesSwitchType
>>> transform logAtts1 : Source!LOGATTRIBUTESType
>>> to switchType : Target!LogAttributesSwitchType {
>>> guard : logAtts1.type = Source!LogAttType#CODE and
>>> logAtts1.codeType = Source!CodeType#SWITCH
>>> 'LogAttributesType2LogAttributesSwitchType'.println();
>>> --<blah/>
>>> switchType.switchValues := logAtts1.cODEVAL.collect(v |
>>> v.transformCodeVal2SwitchVal());
>>> }
>>>
>>> rule LogAttributesType2LogAttributesEnumType
>>> transform logAtts1 : Source!LOGATTRIBUTESType
>>> to enumType : Target!LogAttributesEnumType {
>>> guard : logAtts1.type = Source!LogAttType#CODE and
>>> logAtts1.codeType = Source!CodeType#ENUM
>>> 'LogAttributesType2LogAttributesEnumType'.println();
>>> --<blah/>
>>> enumType.enumeratedValues := logAtts1.cODEVAL.collect(v |
>>> v.transformCodeVal2EnumVal());
>>> }
>>>
>>> The 'cODEVAL' attribute on the source class is the same in both
>>> cases, however I want to apply different transformation rules to this
>>> attribute depending of which transformation is currently being invoked.
>>>
>>> I have defined the two transformation operations as:
>>>
>>> operation Source!CODEVALType transformCodeVal2EnumVal() :
>>> Target!EnumVal {
>>> var result : Target!EnumVal;
>>> 'transformCodeVal2EnumVal'.println();
>>> (self.eClass().name).println();
>>> result.value := self.value;
>>> result.meaning := self.meaning;
>>> return result;
>>> }
>>>
>>> operation Source!CODEVALType transformCodeVal2SwitchVal() :
>>> Target!SwitchVal {
>>> var result : Target!SwitchVal;
>>> 'transformCodeVal2SwitchVal'.println();
>>> (self.eClass().name).println();
>>> result.value := self.value;
>>> result.meaning := self.meaning;
>>> return result;
>>> }
>>>
>>> The execution trace shows the following error message:
>>> transformCodeType2LogAttCodeType
>>> transformCodeVal2EnumVal
>>> CODEVALType
>>> EXCEPTION: Called feature value on undefined object
>>> (C:\EclipseWorkspaces\Blah\MyTransformation.etl@lineNo)
>>
>> This happens because result (rather than self) is null in both
>> operations. To initialize it you need to replace
>>
>> var result : Target!EnumVal;
>>
>> with
>>
>> var result : new Target!EnumVal;
>>
>> (and similarly for the second operation)
>>
>>>
>>> The appropriate transformation operation has been invoked
>>> (transformCodeVal2EnumVal), and self is of the expected type
>>> (CODEVALType), however it appears to suggest that the receiver (self)
>>> is undefined when I try to access one of the attributes.
>>>
>>> Using the following 'generic' transformation runs without throwing an
>>> error (although it doesn't provide me with the flexibility of
>>> specifying when to return an EnumVal object and when to return a
>>> SwitchVal object):
>>>
>>> rule CodeVal2EnumVal
>>> transform cv1 : Source!CODEVALType
>>> to ev2 : Target!EnumVal {
>>> ev2.value := cv1.value;
>>> ev2.meaning := cv1.meaning;
>>> }
>>>
>>> So I guess I have two questions:
>>> 1. Why does self.eClass().name return the expected type
>>> (CODEVALType), and yet on the very next line when I try to access
>>> self.value does self appear to be undefined?
>>> 2. Is there an easier way to achieve the explicit invocation of one
>>> rule from another?
>>
>> The .equivalent() operation explicitly calls all the rules applicable
>> to the source. Would you like to be able to invoke only a specific
>> named rule instead?
>>
>>>
>>> Best Wishes
>>> Chris
>>
>> Cheers,
>> Dimitris
>>


--
Spread the word: http://www.eclipse.org/gmt/epsilon/spreadtheword
Follow Epsilon on Twitter: http://twitter.com/epsilonews
Previous Topic:Null Pointer Exception when invoking .asOrderedSet in EOL query
Next Topic:Null Pointer Exception when invoking .asOrderedSet in EOL query
Goto Forum:
  


Current Time: Wed Nov 26 05:55:41 GMT 2014

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

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