|
Re: Generation of elements and refereces between them [message #1690190 is a reply to message #1690093] |
Wed, 25 March 2015 15:29 |
|
The preferred (simple) solution is to use normal, matched rules to generate your setters. If you want to only generate setters based on a certain condition, use rule inheritance.
If you still must use lazy rules, consider using unique lazy rules. Unique lazy rules will always return the same output for a given input (i.e. output elements are created only once for a unique input). Make sure you don't call the lazy rule for the opposite setter from within the lazy rule, because the unique trace will not be available until the rule returns, and you will end up with an infinite loop! So no recursion.
Cheers,
Dennis
|
|
|
Re: Generation of elements and refereces between them [message #1690197 is a reply to message #1690190] |
Wed, 25 March 2015 16:05 |
Alexander R Messages: 211 Registered: July 2013 |
Senior Member |
|
|
Hi,
many thanks! I never thougth about:
Quote:... generate setters based on a certain condition, use rule inheritance
This is what I was looking for. Instead I crippled my code with lazy rules....triggered by if-clauses...D'OH!
One last question to rule inheritance. Is it a good Idea to model rule-inheritances like this:
abstract rule SuperProp2Field {
from
prop : IN!Prop
to
field : OUT!Field (
)
}
--will create fields, even if setter already in class
rule RuleOnlyForGuardAndForFieldCreation extends SuperProp2Field {
from
prop : IN!Prop (prop.upper > 0)
to
}
--will create setter, but the fields will be created in RuleOnlyForGaurd
rule Prop2SpecialSetterForUpperBigger1 extends RuleOnlyForGaurd {
from
prop : IN!Prop (prop.getOwnerClass.allOperations->select(op| op.name = 'getter' + prop.name)->isEmpty())
to
target : OUT!Method (
name<-'getter' + prop.name
)
}
The idea behind this is: I want to create field, even if setter-methods are already in the class. So fields will be generated irrespective of the setters.
~Alex
[Updated on: Wed, 25 March 2015 16:48] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03624 seconds