Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [henshin-dev] Problem with "destructive operations" on rule-nodes

Hi Jens,

you are right about the changes to transformation rules. If you need several variations of the same rule, what you can do is to make copies of the rule using

Rule copy = (Rule) EcoreUtil.copy(rule);

Now you can safely modify the copy without affecting the original rule. This works because rules are self-contained model elements (unlike general units). 

Say, you have a set of types and a rule and you want to instantiate the type of a node in the rule with these different types. You could create a map that maps the types to rules like this:

Rule rule = ...
List<EClass> types = ...

Map<EClass,Rule> typedRules = new HashMap<EClass,Rule>();
for (EClass type : types) {
   Rule copy = (Rule) EcoreUtil.copy(rule);
   copy.getLhs().getNode("x").setType(type);
   typedRules.put(type, copy);
}

where "x" is the name of the node which should have the given type(s). If you want to use the rules, you can quickly find the rule for a given type by:

Rule r = typedRules.get(type);
...

Hope this helps.

Cheers,
Christian

On 12/21/2012 05:32 PM, Jens Bürger wrote:
Hello all,

I have a problem whilst doing matches with Henshin API.

As Christian suggested some time ago, I set the types of nodes in rules via

getType() and setType() methods.

This happens via some instances of the class "ClicheInstance" which owns the method getAllMatches (see attached source).
Now I found out that the modifications I apply to the transformation model seem to be applied down to the resource, so that I get funny effects when using different modifications to rules and transformations on one transformation model at a time.

I had a look at the Henshin sources and got the following question:

Am I right that if I want do to several type modifications at a time, my only chance is to create seperate HenshinResourceSets for each of the ClicheInstance-instances?

Jens


_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/henshin-dev


Back to the top