Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTO] One more question...
[QVTO] One more question... [message #76890] Tue, 18 March 2008 08:36 Go to next message
Juan Cadavid is currently offline Juan CadavidFriend
Messages: 59
Registered: July 2009
Location: Paris, France
Member

Hey guys, I have one more question. Is it possible to declare variables in
a transformation file to be referenced across all the rules? For example,
the result of an expensive query that yields the same thing during all the
transformation. Thanks a lot!

-Juan
Re: [QVTO] One more question... [message #76922 is a reply to message #76890] Tue, 18 March 2008 10:49 Go to previous messageGo to next message
Sergey Boyko is currently offline Sergey BoykoFriend
Messages: 171
Registered: July 2009
Senior Member
Hi Juan,

In current implementation transformation-scope variables are declared
using "property" keyword.

For example:

modeltype ecore uses ecore('http://www.eclipse.org/emf/2002/Ecore');
transformation sample(inout model : ecore);

property counter: Integer = 1;
property tempClass : EClass = object EClass{};

main() {
model.rootObjects()->select(oclIsKindOf(EClass))
->collect(c|c.oclAsType(EClass).map toEClass());
}

mapping EClass::toEClass() : EClass {
init { this.counter = this.counter + 1; }
name := self.name + this.counter.toString() + tempClass.name;
}


Regards,
Sergey.

Juan Jose Cadavid G wrote:
> Hey guys, I have one more question. Is it possible to declare variables
> in a transformation file to be referenced across all the rules? For
> example, the result of an expensive query that yields the same thing
> during all the transformation. Thanks a lot!
>
> -Juan
>
Re: [QVTO] One more question... [message #76939 is a reply to message #76922] Tue, 18 March 2008 15:21 Go to previous messageGo to next message
Juan Cadavid is currently offline Juan CadavidFriend
Messages: 59
Registered: July 2009
Location: Paris, France
Member

Thanks a lot. I would also like to know how the local variables inside
queries work. I've noticed there's a 'var' keyword, but haven't been able
to guess its syntax. I keep getting "is not compatible with actual type
'oclstdlib::Boolean' ".

Thank you!

-Juan
Re: [QVTO] One more question... [message #76953 is a reply to message #76939] Tue, 18 March 2008 17:19 Go to previous messageGo to next message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Hi Juan,

The code snippet below shows an example of variable decl syntax:

query testQuery() : Boolean {
var b1 :=3D true; -- type can be omitted, deduced from the value
var b2 : Boolean :=3D false;
=

if(b1) then {
var b3 :=3D true; -- local scope - in if block expression
} endif;
=

return b1 or b2;
}

Could you post your code? I'm not sure what the problem could be in your=
=

case.

/Radek


On Tue, 18 Mar 2008 08:21:24 -0700, Juan Jose Cadavid G =

<juanjosecg@gmail.com> wrote:

> Thanks a lot. I would also like to know how the local variables inside=
=

> queries work. I've noticed there's a 'var' keyword, but haven't been =

> able to guess its syntax. I keep getting "is not compatible with actua=
l =

> type 'oclstdlib::Boolean' ".
>
> Thank you!
>
> -Juan
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [QVTO] One more question... [message #77018 is a reply to message #76953] Wed, 19 March 2008 01:36 Go to previous messageGo to next message
Juan Cadavid is currently offline Juan CadavidFriend
Messages: 59
Registered: July 2009
Location: Paris, France
Member

Thanks a lot! I wasn't clever enough to figure the := operator... or the
content assist already available :P

However, I hope I don't abuse your help but I got one more question, about
transformation-scope variables with 'property'. I have declared the
following property:

property providers: OrderedSet(Component) = OrderedSet{};

and then, later in a query, I try to add an element to this collection,
like this:

query myQuery() : Boolean{
var comp : Component := Object Component{};
providers->append(comp);
return true;
}

but after running some tests, I realize it doesn't work as expected; the
collection remains empty. I tried redefining the providers collection
inside the query, but '=' is a boolean operator and ':=' isn't allowed.
Can you give me some ideas please?

Also, I wanted to ask you for some debugging tips, besides looking at at
qvtotrace file, since this displays results only on the mappings but not
the query results and the such. Is there a way to do a .println() or
something during queries? Thanks a lot.
Re: [QVTO] One more question... [message #77102 is a reply to message #77018] Wed, 19 March 2008 04:56 Go to previous messageGo to next message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Hi Juan,

Some comments in-lined bellow.

Regards,
/Radek

> Thanks a lot! I wasn't clever enough to figure the :=3D operator... or=
the =

> content assist already available :P
>
> However, I hope I don't abuse your help but I got one more question,

Do not hesitate to ask, that's what we are here for ;-)
Also, the following link might be useful: =

http://www.omg.org/cgi-bin/doc?ptc/2007-07-07

> about transformation-scope variables with 'property'. I have declared =
=

> the following property:
>
> property providers: OrderedSet(Component) =3D OrderedSet{};
>
> and then, later in a query, I try to add an element to this collection=
, =

> like this:
>
> query myQuery() : Boolean{
> var comp : Component :=3D Object Component{};
> providers->append(comp);
> return true;
> }

The problem is the in append() operation. You actually call =

OrderedSet::append() from
the OCL standard library, and OCL is side effect-free language.
IOW, it does not modify a collection here, but creates a new one with th=
e
element appended already. Therefore the original collection is not =

modified.
You can use the code bellow instead:

providers +=3D comp; -- additive assignment semantics

>
> but after running some tests, I realize it doesn't work as expected; t=
he =

> collection remains empty. I tried redefining the providers collection =
=

> inside the query, but '=3D' is a boolean operator and ':=3D' isn't all=
owed. =

> Can you give me some ideas please?
>
> Also, I wanted to ask you for some debugging tips, besides looking at =
at =

> qvtotrace file, since this displays results only on the mappings but n=
ot =

> the query results and the such. Is there a way to do a .println() or =

> something during queries? Thanks a lot.

The traces are created only for mapping operation calls, as defined by t=
he =

spec.
You can use log expression like this:
log('your message', obj);

See LogExp in the spec link I have posted above.

-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [QVTO] About [message #77122 is a reply to message #77102] Wed, 19 March 2008 06:11 Go to previous messageGo to next message
Juan Cadavid is currently offline Juan CadavidFriend
Messages: 59
Registered: July 2009
Location: Paris, France
Member

Hi Radek,

I just tried the additive assignment inside the query and it triggers an
error in the editor that says "'providers' cannot be resolved", and when
trying to execute it, yields a parsing error. It's weird, because when I
invoke operations on this collection (for example, as I was trying to do
in 'providers->append()') I don't get this error in the editor.

I just made a test having 'providers' as a local variable inside the query:

var providers: OrderedSet(Component) := OrderedSet{};

instead of a transformation-scope property:

property providers: OrderedSet(Component) = OrderedSet{};

And the error isn't there. Maybe this isn't allowed for properties? Is
there anything I could do in that case?

BTW, I'm using build I200803070100.

Thanks a lot guys!

-Juan

Radek Dvorak wrote:

> Hi Juan,

> Some comments in-lined bellow.

> Regards,
> /Radek

>> Thanks a lot! I wasn't clever enough to figure the := operator... or the
>> content assist already available :P
>>
>> However, I hope I don't abuse your help but I got one more question,

> Do not hesitate to ask, that's what we are here for ;-)
> Also, the following link might be useful:
> http://www.omg.org/cgi-bin/doc?ptc/2007-07-07

>> about transformation-scope variables with 'property'. I have declared
>> the following property:
>>
>> property providers: OrderedSet(Component) = OrderedSet{};
>>
>> and then, later in a query, I try to add an element to this collection,
>> like this:
>>
>> query myQuery() : Boolean{
>> var comp : Component := Object Component{};
>> providers->append(comp);
>> return true;
>> }

> The problem is the in append() operation. You actually call
> OrderedSet::append() from
> the OCL standard library, and OCL is side effect-free language.
> IOW, it does not modify a collection here, but creates a new one with the
> element appended already. Therefore the original collection is not
> modified.
> You can use the code bellow instead:

> providers += comp; -- additive assignment semantics

>>
>> but after running some tests, I realize it doesn't work as expected; the
>> collection remains empty. I tried redefining the providers collection
>> inside the query, but '=' is a boolean operator and ':=' isn't allowed.
>> Can you give me some ideas please?
>>
>> Also, I wanted to ask you for some debugging tips, besides looking at at
>> qvtotrace file, since this displays results only on the mappings but not
>> the query results and the such. Is there a way to do a .println() or
>> something during queries? Thanks a lot.

> The traces are created only for mapping operation calls, as defined by the
> spec.
> You can use log expression like this:
> log('your message', obj);

> See LogExp in the spec link I have posted above.
Re: [QVTO] About [message #77135 is a reply to message #77122] Wed, 19 March 2008 06:54 Go to previous messageGo to next message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Hi Juan,

Your propblem should be solved by using 'this' variable to access the =

transformation property.
Looks like you hit a bug as 'this' should be automatically resolved as t=
he =

implicit source
of calls to transformation properties an operations, which works but fai=
ls =

just for the write access.

So rewrite it as follows:
this.providers +=3D comp; -- this - predefined variable, refers to the =
=

transformation instance

/Radek

On Tue, 18 Mar 2008 23:11:27 -0700, Juan Jose Cadavid G =

<juanjosecg@gmail.com> wrote:

> Hi Radek,
>
> I just tried the additive assignment inside the query and it triggers =
an =

> error in the editor that says "'providers' cannot be resolved", and wh=
en =

> trying to execute it, yields a parsing error. It's weird, because when=
I =

> invoke operations on this collection (for example, as I was trying to =
do =

> in 'providers->append()') I don't get this error in the editor.
>
> I just made a test having 'providers' as a local variable inside the =

> query:
>
> var providers: OrderedSet(Component) :=3D OrderedSet{};
>
> instead of a transformation-scope property: property providers: =

> OrderedSet(Component) =3D OrderedSet{};
>
> And the error isn't there. Maybe this isn't allowed for properties? Is=
=

> there anything I could do in that case?
>
> BTW, I'm using build I200803070100.
>
> Thanks a lot guys!
>
> -Juan
>
> Radek Dvorak wrote:
>
>> Hi Juan,
>
>> Some comments in-lined bellow.
>
>> Regards,
>> /Radek
>
>>> Thanks a lot! I wasn't clever enough to figure the :=3D operator... =
or =

>>> the content assist already available :P
>>>
>>> However, I hope I don't abuse your help but I got one more question,=

>
>> Do not hesitate to ask, that's what we are here for ;-)
>> Also, the following link might be useful: =

>> http://www.omg.org/cgi-bin/doc?ptc/2007-07-07
>
>>> about transformation-scope variables with 'property'. I have declare=
d =

>>> the following property:
>>>
>>> property providers: OrderedSet(Component) =3D OrderedSet{};
>>>
>>> and then, later in a query, I try to add an element to this =

>>> collection, like this:
>>>
>>> query myQuery() : Boolean{
>>> var comp : Component :=3D Object Component{};
>>> providers->append(comp);
>>> return true;
>>> }
>
>> The problem is the in append() operation. You actually call =

>> OrderedSet::append() from
>> the OCL standard library, and OCL is side effect-free language.
>> IOW, it does not modify a collection here, but creates a new one with=
=

>> the
>> element appended already. Therefore the original collection is not =

>> modified.
>> You can use the code bellow instead:
>
>> providers +=3D comp; -- additive assignment semantics
>
>>>
>>> but after running some tests, I realize it doesn't work as expected;=
=

>>> the collection remains empty. I tried redefining the providers =

>>> collection inside the query, but '=3D' is a boolean operator and ':=
=3D' =

>>> isn't allowed. Can you give me some ideas please?
>>>
>>> Also, I wanted to ask you for some debugging tips, besides looking a=
t =

>>> at qvtotrace file, since this displays results only on the mappings=
=

>>> but not the query results and the such. Is there a way to do a =

>>> .println() or something during queries? Thanks a lot.
>
>> The traces are created only for mapping operation calls, as defined b=
y =

>> the spec.
>> You can use log expression like this:
>> log('your message', obj);
>
>> See LogExp in the spec link I have posted above.
>
>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Re: [QVTO] About [message #77151 is a reply to message #77135] Wed, 19 March 2008 07:11 Go to previous messageGo to next message
Juan Cadavid is currently offline Juan CadavidFriend
Messages: 59
Registered: July 2009
Location: Paris, France
Member

Wow, thanks a lot! My transformation is working alright now :)

You guys rock... hope I can contribute to the project somehow soon.

-Juan
Re: [QVTO] About [message #77212 is a reply to message #77151] Wed, 19 March 2008 15:35 Go to previous message
Radomil Dvorak is currently offline Radomil DvorakFriend
Messages: 249
Registered: July 2009
Senior Member
Great to hear that!
We look forward to get other people involved in QVTO. ;-)

Thanks,
/Radek

On Wed, 19 Mar 2008 00:11:43 -0700, Juan Jose Cadavid G
<juanjosecg@gmail.com> wrote:

> Wow, thanks a lot! My transformation is working alright now :) You guys
> rock... hope I can contribute to the project somehow soon.
>
> -Juan
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Previous Topic:[ATL] Where are other posts ?!
Next Topic:[atl] thisModule.resolveTemp() for a called rule
Goto Forum:
  


Current Time: Sun Aug 18 23:42:39 GMT 2019

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

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

Back to the top