Home » Archived » M2M (model-to-model transformation) » [ATL] How to obtain all the subclasses of a class?
() 1 Vote
| | | |
Re: [ATL] How to obtain all the subclasses of a class? [message #541308 is a reply to message #541306] |
Sat, 19 June 2010 19:21 |
wafaa Messages: 163 Registered: January 2010 Location: Egypt |
Senior Member |
|
|
hi Bler
let me explain something
when transforming the parent , transform only its name and the attributes you want
you do not need to delet actually operations will be created if you transformed them too.
like this
rule parentClass {
from uc : UML!Class ( uc.hasChild())
to c : UML!Class (
name <- uc.name,
ownedAttribute <- uc.ownedAttribute )
}
and when transforming children create operation for each like this
rule child{
from uc : UML!CLass
( not uc.hasChild() )
to c: UML!Class (
name <- uc.name ,
ownedAttribute <- uc.ownedAttribute,
ownedOperation <- uc.ownedOperation ,
ownedOperation <- uc.superClass.ownedOperation
}
and let hasChild
helper context UML!Class def: hasChild () : Boolean =
if thisModule.getAllSupers ->exists(self)
then
true
else
false;
helper def : getAllSupers () : Sequence(UML!Class) =
UML!CLass.allInstances() ->select(p | p.superClass) ->asSet();
[Updated on: Sat, 19 June 2010 19:28] Report message to a moderator
|
|
| |
Re: [ATL] How to obtain all the subclasses of a class? [message #541374 is a reply to message #541310] |
Sun, 20 June 2010 14:55 |
Bler Messages: 26 Registered: June 2010 |
Junior Member |
|
|
Hi wafaa,
I had an error with the helper
helper def : getAllSupers() : Sequence(UML!Class) =
UML!Class.allInstances() ->select(p | p.superClass) ->asSet();
Error looks like this : "Operation not found: Sequence {}.not()"
I could not correct it, so I modified the helper "hasChild()" as below, since I have:
- a super-class "A" with 2 properties (pro1 and pro2) and 3 operations (oper1,oper2 and oper3), and
- 3 sub-classes "B" "C" and "D"
The code is :
helper context UML!Class def: hasChild () : Boolean =
if self.name = 'A' then
true
else
false
endif;
rule parentClass {
from uc : UML!Class ( uc.hasChild())
to c : UML!Class (
name <- uc.name,
ownedAttribute <- uc.ownedAttribute
)
}
rule child {
from uc : UML!Class( not uc.hasChild() )
to c: UML!Class (
name <- uc.name,
ownedAttribute <- uc.ownedAttribute,
ownedOperation <- uc.ownedOperation,
ownedOperation <- uc.superClass.first().ownedOperation.at(2)
)
}
I would like to move « oper2 » form A to B, C, and « D », after the transformations I have:
- the super class "A", with 2 properties (pro1 and pro2) and 2 operations (oper1, oper3),it's good, but
- the "oper2" appears only in the sub-class "D"
Could you tell me way please?
Regards,
|
|
| |
Re: [ATL] How to obtain all the subclasses of a class? [message #541605 is a reply to message #541524] |
Mon, 21 June 2010 18:21 |
Bler Messages: 26 Registered: June 2010 |
Junior Member |
|
|
Hi wafaa,
Thank you so much for your help,
Yes I used only the operation 2 to be inherited, I just started to learn ATL..., I suppose that the operations 1 and 3 were transformed because only the operation 2 has been inherited. Like a kind of swap...I'm not sure, if I use only one sub-class it is ok, but for more than one class, the operation 2 is created only on the last one, so maybe I have to duplicated it (clone or something like that...), for the moment I added a third rule to add the operation for the sub-classes without it... I debug it, it same to be good, anyway I have to check, read/learn...
Thanks again ,
Regards
|
|
|
Goto Forum:
Current Time: Wed Nov 06 09:44:26 GMT 2024
Powered by FUDForum. Page generated in 0.05860 seconds
|