Skip to main content



      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 10:07 Go to next message
Eclipse UserFriend
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 297 times)

[Updated on: Fri, 30 July 2021 10:08] by 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 10:32 Go to previous messageGo to next message
Eclipse UserFriend
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 14:28 Go to previous messageGo to next message
Eclipse UserFriend
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 16:22 Go to previous messageGo to next message
Eclipse UserFriend
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 18:42] by 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 02:16 Go to previous message
Eclipse UserFriend
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: Tue Jun 24 13:44:48 EDT 2025

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

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

Back to the top