Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [henshin-dev] ConditionalUnit example

Hi Sebastien,

the semantics of the rules and unit types is documented here: https://wiki.eclipse.org/Henshin_Transformation_Meta-Model

--> ConditionalUnits have either two or three sub-units: ifthen, (and else). If a match for the if unit can be found, the then unit is executed. Otherwise, if present, the else unit is executed. Note that any changes specified in the if unit are ignored; it is used for matching only.

In your case, I think the engine should be smart enough to convert a string into an enum. Then you would just use one rule. The rule needs to have a parameter called, say, "w" that is used to store the word size. In your Platform node, create an attribute 
 
   wordSize = w 

This will store the value of the wordSize attribute in the w-parameter. In the MyNewPlatform node, you also add the wordSize attribute. If this node is created by the rule, set the attribute to 

  wordSize = "_" + w

If the MyNewPlatform node is not created by the rule (it is matched) then you need to set the attribute to

  wordSize = ? -> "_" + w

This means that the wordSize attribute is not matched by the LHS, but it is modified in the RHS of the rule.

The engine should automatically convert the string "_" + w into the corresponding enum literal.

Cheers,
Christian

2015-01-22 15:37 GMT+01:00 Sébastien Pasero <sebastien.pasero@xxxxxx>:
Hi,

I would like to have some examples using a ConditionalUnit during a Henshin transformation.
I don't understand how the "if" condition works :
 - Shall the rule return a boolean parameter ? How ?
 - Shall the rule return a parameter, and if it's null or empty, the condition is false ?
 - Anything else ?

Here is what I'm doing :
My source ecore model contains a class "Platform", with an attribute named "wordSize", which can have following values : 16 or 32.
I would like to transform this to :
 - a class "MyNewPlatform" with its attribute "wordSize" set to _16 (it's an enumeration value) if Platform.wordSize = 16
 - a class "MyNewPlatform" with its attribute "wordSize" set to _32 (it's an enumeration value) if Platform.wordSize = 32

Could you help me with this ?

Regards,
Sebastien
_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/henshin-dev


Back to the top