[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, ...

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!