Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Passing a Type as parameter in acceleo always results in AnyType
Passing a Type as parameter in acceleo always results in AnyType [message #1843459] Fri, 30 July 2021 14:07 Go to next message
Thomas Barth is currently offline Thomas BarthFriend
Messages: 22
Registered: March 2021
Junior Member
I want to pass a Type to a query.

However, whenever I try:
[query public Test(T : OclType) : String = T.toString()/]

I get:
org.eclipse.ocl.ecore.impl.AnyTypeImpl@12dbef96 (name: T) (instanceClassName: null)


.toString() directly at the type gives me the expected result, e.g.:
org.eclipse.emf.ecore.impl.EClassImpl@1f799f4c (name: TechnicalFunction) (instanceClassName: null) (abstract: false, interface: false)


Version:
index.php/fa/40819/0/
  • Attachment: Unbenannt.JPG
    (Size: 25.27KB, Downloaded 209 times)

[Updated on: Fri, 30 July 2021 14:08]

Report message to a moderator

Re: Passing a Type as parameter in acceleo always results in AnyType [message #1843461 is a reply to message #1843459] Fri, 30 July 2021 14:32 Go to previous messageGo to next message
Thomas Barth is currently offline Thomas BarthFriend
Messages: 22
Registered: March 2021
Junior Member
solved: T is a keyword...
Re: Passing a Type as parameter in acceleo always results in AnyType [message #1843463 is a reply to message #1843461] Fri, 30 July 2021 18:28 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Well diagnosed. But not quite right.

"T" is not a reserved or restricted word in OCL 2.4. Rather "T" is some magic that looks remarkably like a template parameter without the inconvenience of following through on alignment with UML and its template capabilities.

Acceleo uses the Classic Eclipse OCL in which "T" and "T1" magic are realized as reserved words.

The newer Pivot-based Eclipse OCL supports UML-like templates and so "T" is only captured within scopes in which"T" has been declared as a template parameter.

Regards

Ed Willink
Re: Passing a Type as parameter in acceleo always results in AnyType [message #1843464 is a reply to message #1843463] Fri, 30 July 2021 20:22 Go to previous messageGo to next message
Thomas Barth is currently offline Thomas BarthFriend
Messages: 22
Registered: March 2021
Junior Member
Hi Ed,

thanks for the insight!

Yeah, I tried to use the passed type as kind of template parameter, e.g.:
[query public Test(any : OclAny, tpe : OclType) : OrderedSet(tpe ) = any.eInverse(tpe )/]

However, it seems like the signature cannot contain "template" parameters (though I could simply use a common base-class) and also OCL is not happy about variable types.
The query I want to write will only use 3 types, I can check for the passed type with if-statements and have static typed queries or is there another way? For now I have 3 times the same query with different types, which is not too elegant I think.

[Updated on: Fri, 30 July 2021 22:42]

Report message to a moderator

Re: Passing a Type as parameter in acceleo always results in AnyType [message #1843466 is a reply to message #1843464] Sat, 31 July 2021 06:16 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Yeah. That's why we need templates.

The OMG specification states that OCL is UML-aligned, giving a very strong indication that OCL should support templates, but there is zero syntactical support for them. It is hardly surprising that Acceleo/MOFM2T and QVTo that extend OCL also lack template support. Eclipse QVTr has a template extension.

You might just get away with redirecting to OCLinEcore where templates are supported. The syntax was challenging; we all expect <> for templates but this conflicts with arithmetic operators and so requires parsing heroics (see my C++ PhD). OCL through Set(MyClass) already has () for templates so I ended up supporting <> for declarations and () for instantiations.

Regards

Ed Willink
Previous Topic:get the instance of the Main AcceleoGenerator class from query invoke
Next Topic:How to access imported packages
Goto Forum:
  


Current Time: Thu Apr 25 23:24:29 GMT 2024

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

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

Back to the top