[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] Re: References in ATL output

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@xxxxxxxxxxxxxx
http://www.sciences.univ-nantes.fr/lina/atl/
--------------------------------------------------------