Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » References in ATL output
References in ATL output [message #86340] Thu, 10 July 2008 21:48 Go to next message
kaab  is currently offline kaab Friend
Messages: 43
Registered: July 2009
Member
Hi,

We are trying to generate a KDM file with an STM input for the java
language.
The Transformation output looks good but we had problems setting the
references inside of our output.
We use a function to create PrimitiveTypes :

rule CreatePrimitiveTypes()
{
to
B : kdm!BooleanType (
name <- 'boolean'
),
C : kdm!CharType
(
name <- 'char'
),
F : kdm!FloatType
(
name <- 'float'
),
Fd : kdm!FloatType
(
name <- 'double'
),
I : kdm!IntegerType
(
name <- 'int'
),
Il : kdm!IntegerType
(
name <- 'long'
),
v : kdm!VoidType
(
name <- 'void'
),
Vn : kdm!VoidType
(
name <- 'null'
),
kdmLanguageUnit : kdm!LanguageUnit(
name <- 'Primitive Java datatypes',
codeElement <- B,
codeElement <- C,
codeElement <- F,
codeElement <- Fd,
codeElement <- I,
codeElement <- Il,
codeElement <- v,
codeElement <- Vn
)
do
{
kdmLanguageUnit;
}
}


Now we would like to link our generated elements which are Primitve to the
elements created by this rule.

For example :

We have a rule that create Methods parameters :

lazy rule CreateParameters {
from stmConcreteNode : STM!StConcreteNode (
stmConcreteNode.concreteId = 'FieldDeclaration'
)
to
kdmParameter:kdm!ParameterUnit (
name <-
stmConcreteNode.getParameter('./StConcreteNode[2]/StToken[1] /@image')

type <- ???????? (Need to be linked to boolean)

)
}


Right now our output looks like this :

<codeElement xsi:type="code:MethodUnit" name="myMethod1">
<codeElement xsi:type="code:Signature" name="myMethod1">
<parameterUnit name="param"/>
<parameterUnit name="index"/>
<parameterUnit kind="return" type="????"/>
</codeElement>
</codeElement>



And we would like it to look like this :

<codeElement xsi:type="code:MethodUnit" name="myMethod1">
<codeElement xsi:type="code:Signature" name="myMethod1">
<parameterUnit name="param"/>
<parameterUnit name="index"/>
<parameterUnit kind="return"
type="//@model.1/@codeElement.0/@codeElement.3"/>
</codeElement>
</codeElement>


Thanks in advance for your answers,
Re: References in ATL output [message #86364 is a reply to message #86340] Fri, 11 July 2008 08:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Hugo.Bruneliere.univ-nantes.fr

Hi Amid,

Hamid Kaab a écrit :
> Hi,
> We are trying to generate a KDM file with an STM input for the java
> language. The Transformation output looks good but we had problems
> setting the references inside of our output.
> We use a function to create PrimitiveTypes :
>
> rule CreatePrimitiveTypes()
> {
> to
> B : kdm!BooleanType (
> name <- 'boolean'
> ),
> C : kdm!CharType
> (
> name <- 'char'
> ),
> F : kdm!FloatType
> (
> name <- 'float'
> ),
> Fd : kdm!FloatType
> (
> name <- 'double'
> ),
> I : kdm!IntegerType
> (
> name <- 'int'
> ),
> Il : kdm!IntegerType
> (
> name <- 'long'
> ),
> v : kdm!VoidType
> (
> name <- 'void'
> ),
> Vn : kdm!VoidType
> (
> name <- 'null'
> ),
> kdmLanguageUnit : kdm!LanguageUnit(
> name <- 'Primitive Java datatypes',
> codeElement <- B,
> codeElement <- C,
> codeElement <- F,
> codeElement <- Fd,
> codeElement <- I,
> codeElement <- Il,
> codeElement <- v,
> codeElement <- Vn
> )
> do
> {
> kdmLanguageUnit;
> }
> }
>
>
> Now we would like to link our generated elements which are Primitve to
> the elements created by this rule.
>
> For example :
>
> We have a rule that create Methods parameters :
>
> lazy rule CreateParameters {
> from stmConcreteNode : STM!StConcreteNode (
> stmConcreteNode.concreteId = 'FieldDeclaration'
> )
> to
> kdmParameter:kdm!ParameterUnit (
> name <-
> stmConcreteNode.getParameter('./StConcreteNode[2]/StToken[1] /@image')
>
> type <- ???????? (Need to be linked to boolean)
>
> )
> }
>

There are different ways to achieve this.

-------------------------------------
Using a declarative way (preferable):
-------------------------------------

* Don't use a called rule like the "CreatePrimitiveTypes()" one to
initiate the basic types but do it in a normal matched rule concerning
the root element of your input model, something like:

rule createKDMModel {
from
root : stm!???
to
m : kdm!KDMModel (
.....
),
...
B : kdm!BooleanType (
name <- 'boolean'
),
....
}


* Then, you can retrieve from any other matched rule your type by
calling the "resolveTemp" method

type <- thisModule.resolveTemp(rootSTM,'B')

where "rootSTM" is the root element of your STM model

* Note that in order to not make your rules to complicated, you can
create an helper that computes this and then call it each time you need
to get a type

More generally, from a development and maintainability point of view,
it's highly recommended to use as much as possible declarative in your
ATL transformations. By experience, we know that almost all cases have a
declarative solution. Try to limit the use of imperative to very
specific cases where it's really required.

-----------------------------
Using an imperative way:
-----------------------------
* You can create an helper attribute:

helper def: booleanType : kdm!BooleanType =
OclUndefined;

* You can initialize it in the "do" section of your
"CreatePrimitiveTypes()" called rule:

thisModule.booleanType <- B;

* Finally, you can use in your matched rules (only if you're sure
that the "CreatePrimitiveTypes()" has already been called from an
"entrypoint" called rule for instance):

type <- thisModule.booleanType

>
> Right now our output looks like this :
>
> <codeElement xsi:type="code:MethodUnit" name="myMethod1">
> <codeElement xsi:type="code:Signature" name="myMethod1">
> <parameterUnit name="param"/>
> <parameterUnit name="index"/>
> <parameterUnit kind="return" type="????"/>
> </codeElement>
> </codeElement>
>
>
>
> And we would like it to look like this :
>
> <codeElement xsi:type="code:MethodUnit" name="myMethod1">
> <codeElement xsi:type="code:Signature" name="myMethod1">
> <parameterUnit name="param"/>
> <parameterUnit name="index"/>
> <parameterUnit kind="return"
> type="//@model.1/@codeElement.0/@codeElement.3"/>
> </codeElement>
> </codeElement>
>
>
> Thanks in advance for your answers,
>
>
>
>

Best regards,

Hugo

--
--------------------------------------------------------
Hugo Bruneliere - R&D Engineer
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssiniere
44322 Nantes Cedex 3 - France
office +33 2 51 12 58 10 /\ cell.+33 6 07 42 45 30
EMail: Hugo.Bruneliere@univ-nantes.fr
http://www.sciences.univ-nantes.fr/lina/atl/
--------------------------------------------------------
Re: References in ATL output [message #86409 is a reply to message #86364] Fri, 11 July 2008 14:37 Go to previous message
kaab  is currently offline kaab Friend
Messages: 43
Registered: July 2009
Member
Thanks a lot for your answers, that worked for me.
Great ! Thanks again !
Previous Topic:[ATL] Testing transformation rules
Next Topic:[ATL] Iterative expression
Goto Forum:
  


Current Time: Fri Sep 27 00:10:48 GMT 2024

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

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

Back to the top