Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Generation of elements and refereces between them(Need to access a currently not created element :))
Generation of elements and refereces between them [message #1690093] Wed, 25 March 2015 08:51 Go to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
Hi,

my problem is quit tricky. Here a little summary what I want to do. I transform my own models to the Java-Modisco-Model. (https://eclipse.org/MoDisco/)
So far so good...
At the same time I want to enrich the generated modisco-models with some additional elements.

Lets say :For every property in a Class I just want to generate getter/setter.
This is achievable (not the best way, but it works) with lazy rules.

But now I would like to use this getter/setter to create bidirectional associations. To achieve this, I have to reference the setter-method of an opposite property.
Here an example from wikipedia http://en.wikipedia.org/wiki/Association_%28object-oriented_programming%29:

http://upload.wikimedia.org/wikipedia/en/f/f5/BidirectionalAssociation.png

And I want to create a model that represents this code (Only Class2):

public class Class1 {

	private Class2 class2;

	public void setClass2(Class2 class2) {
		this.class2 = class2;
		class2.setClass1(this); //<---PROPBLEM
	}
}


No the snake biting its own tail...because:
1. I generate the all setter-operations with lazy-rules
2. When generating setClass2() it is not possible to access the link to setClass1()

Any idea how to solve this problem? Maybe recursion calls of lazy-rules?

Any help is welcome

~Alex
Re: Generation of elements and refereces between them [message #1690190 is a reply to message #1690093] Wed, 25 March 2015 15:29 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

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 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
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

Re: Generation of elements and refereces between them [message #1690223 is a reply to message #1690197] Wed, 25 March 2015 19:52 Go to previous messageGo to next message
Alexander R is currently offline Alexander RFriend
Messages: 211
Registered: July 2013
Senior Member
But I really do not know how i may manage to create the opposite setter (setClass1()), bevore I use it in setClass2(). Because inside one setter,
I have to call the second setter...and this is (I think) not possible...to solve

Do you maybe have ideas?

Thanks a lot,

Alex
Re: Generation of elements and refereces between them [message #1690291 is a reply to message #1690223] Thu, 26 March 2015 11:19 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

thisModule.resolveTemp(prop.opposite, 'target')


where "prop.opposite" refers to the opposite property, and "target" is the name of the rule output element that refers to the setter method of the opposite property.


Cheers,
Dennis
Previous Topic:Bug (?) in Inheritance-hierarchy of matched rules
Next Topic:Inter-model references problem
Goto Forum:
  


Current Time: Tue Apr 23 18:01:38 GMT 2024

Powered by FUDForum. Page generated in 0.04104 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top