[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.m2m] Re: [ATL] generating ECore!EString or ECore!EInt, ...

Hello,

If your PrimitiveType are in an enumeration you can do:

	type : MM!PrimitiveType    ( type = #String )

if your enum litteral is String. In ATL you access to the enumeration literals by putting '#' before. So for 'Integer' you can do #Integer, etc.

In ATL you can't make a "to" clause empty, because ATL works with matching rule, and if there is no target it can't works.

For the error:

GRAVE: ERROR: could not find operation allInstancesFrom on MOF!EEnum having supertypes: [MOF!EDataType, OclType, OclAny] (including Java operations)
java.lang.RuntimeException: ERROR: could not find operation allInstancesFrom on MOF!EEnum having supertypes: [MOF!EDataType, OclType, OclAny] (including Java operations)


I don't know how you call allInstancesFrom, but normally it must be called like:

in a transformation like:
module myModule;
create out : MM2 from IN : MM1;

--a basic sample helper for allInstancesFrom

helper def: test : Sequence(MM1!Class1) =
	MM1!Class1.allInstancesFrom('IN');

Your error report say there is no operation called allInstancesFrom on your element, or maybe you have forgot a parameter or something like that. The same report is done when you don't spell correctly an operation.

For your helper:

> With a helper:
>
> helper def : getEType(s : MM!PrimitiveType) : ECore!EEnumLiteral =
>     if s.toString() = 'Boolean' then ECore!EBoolean
>         else if s.toString() = 'Integer' then ECore!EInt
>             else if s.toString() = 'Float' then ECore!EFloat
>                 else ECore!EString
>     endif endif endif
>     ;
>
> Don't work with context MM!PrimitiveType instead of (s:
> MM!PrimitiveType) and self instead of s

I don't know the error report for your problem but it must work...
maybe you can try by replacing your :

s.toString() = 'Boolean' by s = #Boolean, and the same for the others...

with the context MM!PrimitiveType and self instead of s it should work, if not I don't know why :(

Hope this helps.

Best regards,

Guillaume


Olivier PATRY a écrit :
Olivier PATRY a écrit :
Guillaume Doux a écrit :
Olivier PATRY a écrit :
Hello,

I'm trying to transform a model conform to a personal metamodel to ECore.

In my metamodel, I had an enumeration PrimitiveType with literals String, Integer, Boolean, Float

I want to transform these personnal types into corresponding ECore types.

I try with
eType <- ECore!EString

wich works well, but I didn't know how to test the "source" type to choose the ECore type (ECore!EString, ECore!EInt, ...)

I try with an helper or lazy rule like

helper context MM!PrimitiveType def : getEType : ECore!???? =
    if String then ECore!EString
    else ...
;

lazy rule getEType
{
    from type :MM!PrimitiveType
    to etype: ECore!????(
    ??? <- EString -- how to choose the right type ?
    )
}

How can I do that, and what is the type of ECore!EString or ECore!EInt ?

Thank you.

(if there is a better way to make the correspondance between ECore primitive types (all) and personnal PrimitiveType, I'm interested ;) )

Bye.


Hello,

Have you try to do it with a guarded matching rule like :

rule primitiveTypeString2EString {
from
type : MM!PrimitiveType ( type.value = 'String' )
-- I put value for the identifier of your primitive type -- because I do not know the corresponding propêrty in -- your metamodel
to
etype: ECore!EString
}


and you can do the same thing for all other primitive type.

I do not know if this is what you expect ?

Hope this helps...

Best regards.


Guillaume Doux
Hi,

yes something like that could help me, but it seems to doesn't work :(

My PrimitiveType is an EEnum, elements in are EEnumLiteral, so I sould have type.value, type.literal and type.name for filtering, it seems to be the right way.

It's possible to make a "to" clause "empty"? (etype:ECore!EString -> nothing after?)

I test some other way like that but nothing was working.

The error I get:

GRAVE: ERROR: could not find operation allInstancesFrom on MOF!EEnum having supertypes: [MOF!EDataType, OclType, OclAny] (including Java operations)
java.lang.RuntimeException: ERROR: could not find operation allInstancesFrom on MOF!EEnum having supertypes: [MOF!EDataType, OclType, OclAny] (including Java operations)


I didn't understand this error...

Thanks,

Olivier Patry
Okay, I finaly get the behavior I wish.

With a helper:

helper def : getEType(s : MM!PrimitiveType) : ECore!EEnumLiteral =
    if s.toString() = 'Boolean' then ECore!EBoolean
        else if s.toString() = 'Integer' then ECore!EInt
            else if s.toString() = 'Float' then ECore!EFloat
                else ECore!EString
    endif endif endif
    ;

Don't work with context MM!PrimitiveType instead of (s: MM!PrimitiveType) and self instead of s

I don't understand why...

I works with this, that's good enough!

Thanks for helping, you put me on the right way!