Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » acceleo - cast of variables(using a query to associate different types of elements)
acceleo - cast of variables [message #658045] Sat, 05 March 2011 09:33 Go to next message
Dulz is currently offline Dulz
Messages: 5
Registered: November 2010
Junior Member
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
Re: acceleo - cast of variables [message #658159 is a reply to message #658045] Mon, 07 March 2011 03:31 Go to previous messageGo to next message
Philippe Palau is currently offline Philippe Palau
Messages: 13
Registered: February 2011
Junior Member
Hi,

I' think you can cast using oclAsType

oclAsType ( typespec : Classifier ) : T

Returns self statically typed as typespec if it is an instance of this type. Note that this does not alter the runtime value of self, it only enables access to subtype operations. This operation allows users to cast self to another type.

examples:
Expression Result
aPerson.oclAsType(Employee) an object of Employee type


http:// help.eclipse.org/helios/index.jsp?topic=/org.eclipse.acceleo .doc/doc/html/acceleo_operation_reference.html


in your query:

[query public
...
->select(oclIsTypeOf(SLVSubjAdjPComplt)or oclIsTypeOf(SVDOObjEdParticipleComplt)or
oclIsTypeOf(SVDO)).siblings(SimpleSentence)->select(oclIsKindOf(UseCaseModelElement))
)).oclAsType(UseCaseModelElement) ->asSet()
/]

Best regards

Re: acceleo - cast of variables [message #658171 is a reply to message #658045] Mon, 07 March 2011 04:28 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
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--
Re: acceleo - cast of variables [message #658185 is a reply to message #658171] Mon, 07 March 2011 05:10 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi Laurent

On 07/03/2011 09:28, Laurent Goubet wrote:
> or ".oclAsType(UseCaseModelElement)" (casts each element individually).
Unfortunately OCL does just that.

oclAsType(Collection(UseCaseModelElement))

is not in OCL 2.2. It is specified by the resolution of Issue 14585 for
OCL 2.3. It is in the Eclipse OCL 3.1 Examples.

For now in OCL you have to use a select iteration to allow each element
to be cast individually. So use Acceleo's filter.

Regards

Ed Willink
Previous Topic:workflow runner going out of space
Next Topic:Best practice to test M2T transformation
Goto Forum:
  


Current Time: Fri Jul 25 19:09:32 EDT 2014

Powered by FUDForum. Page generated in 0.03834 seconds