|
|
Re: acceleo - cast of variables [message #658171 is a reply to message #658045] |
Mon, 07 March 2011 09:28 |
|
This is a multi-part message in MIME format.
--------------070507030503050604030908
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
How can you even read this?
I know OCL isn't the best language for readability purposes ... but you
have to try and make your generation modules easy to read : think
maintenance :).
You don't have any superclass of the many subtypes you're tring to get here?
-----
oclIsTypeOf(SysSubjVActorDOObjPPComplt) or oclIsTypeOf(SV) or
oclIsTypeOf(SysSubjLVSubjAdjPComplt) or oclIsTypeOf(SysSubjVDO) or
oclIsTypeOf(SysSubjVDOObjIngParticipleComplt) or oclIsTypeOf(SysSubjV)
-----
strike me as something that should be changed to something like
-----
oclIsKindOf(MySuperType)
-----
if your metamodel allows for it. If it does not, at least extract this
into a subquery. Other than that, try and use meaningful variable names
(single-letter names are hard to decode). Something like this should be
equivalent to your long example :
-----
[query public doublefunc(useCase : UseCase) : Set(UseCaseModelElement) =
let allPatterns : Sequence(UseCaseModelElement) =
useCase.specification.eContents(BasicFlow).eContents(SimpleS entence).pattern
in
allPatterns->select(isRelevantSysPattern()).siblings(Predicate)- >
union(
allPatterns-> select(isRelevantActorPattern()).siblings(Predicate).eConten ts(DirectObject))- >
union(
allPatterns->select(isRelevantPattern()).siblings(SimpleSentence)- >filter(UseCaseModelElement))->asSet()
/]
[query private isRelevantSysPattern(pattern : UseCaseModelElement) :
boolean =
pattern.oclIsTypeOf(SysSubjVActorDOObjPPComplt) or
pattern.oclIsTypeOf(SV) or
pattern.oclIsTypeOf(SysSubjLVSubjAdjPComplt) or
pattern.oclIsTypeOf(SysSubjVDO) or
pattern.oclIsTypeOf(SysSubjVDOObjIngParticipleComplt) or
pattern.oclIsTypeOf(SysSubjV)
/]
[query private isRelevantActorPattern(pattern : UseCaseModelElement) :
boolean =
pattern.oclIsTypeOf(ActorSubjVDO) or
pattern.oclIsTypeOf(ActorSubjVDOObjPPComplt) or
pattern.oclIsTypeOf(SVIODO)
/]
[query private isRelevantPattern(pattern : UseCaseModelElement) : boolean =
pattern.oclIsTypeOf(SLVSubjAdjPComplt) or
pattern.oclIsTypeOf(SVDOObjEdParticipleComplt) or
pattern.oclIsTypeOf(SVDO)
/]
-----
This expects that your "SimpleSentence.pattern" call returns a Sequence
of UseCaseModelElement, that the " siblings(Predicate)" that were lying
here and there are indeed ".siblings..." and that all of these elements
are indeed subtypes of UseCaseModelElement.
When that is done, you can call "doublefunc" to retrieve the set, and
cast its content if needed through either
"->filter(UseCaseModelElement)" (removes from the list everything that
is not an instance of UseCaseModelElement, and casts the result in a
list of the appropriate type) or ".oclAsType(UseCaseModelElement)"
(casts each element individually).
Laurent Goubet
Obeo
On 05/03/2011 15:34, Dulz wrote:
> Hi, i would like to create a query that associates 3 different kind of
> elements into a set. In practice i would like to do a cast of every type
> to transform these in UseCaseModelElement, that is a class (of an ecore
> diagram) common to every type of every ecore i'm working with. Is it
> possible?
> The query is this:
> [query public doublefunc(u:UseCase):Set(UseCaseModelElement)=
> u.specification.eContents(BasicFlow).eContents(SimpleSentenc e).pattern
> ->select(oclIsTypeOf(SysSubjVActorDOObjPPComplt)or oclIsTypeOf(SV)or
> oclIsTypeOf(SysSubjLVSubjAdjPComplt)or
> oclIsTypeOf(SysSubjVDO)or
> oclIsTypeOf(SysSubjVDOObjIngParticipleComplt)or oclIsTypeOf(SysSubjV))
> siblings(Predicate)->union(
> u.specification.eContents(BasicFlow).eContents(SimpleSentenc e).pattern
> ->select(oclIsTypeOf(ActorSubjVDO)or
> oclIsTypeOf(ActorSubjVDOObjPPComplt)or oclIsTypeOf(SVIODO))
> siblings(Predicate).eContents(DirectObject)->union(
> u.specification.eContents(BasicFlow).eContents(SimpleSentenc e).pattern
> ->select(oclIsTypeOf(SLVSubjAdjPComplt)or
> oclIsTypeOf(SVDOObjEdParticipleComplt)or
> oclIsTypeOf(SVDO)).siblings(SimpleSentence)->select(oclIsKindOf(UseCaseModelElement))
>
> ))->asSet()/]
>
> Sorry for my poor english and thank you in advance.
> Marco
--------------070507030503050604030908
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------070507030503050604030908--
|
|
|
|
Powered by
FUDForum. Page generated in 0.02764 seconds