Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to use generic types with for sequence?
How to use generic types with for sequence? [message #986838] Wed, 21 November 2012 21:40 Go to next message
TASSIN Florian is currently offline TASSIN FlorianFriend
Messages: 2
Registered: November 2012
Junior Member
Hello,

For my studies I develop an HTML code generator with Acceleo v3.3.1.

To do this I have to run through different classes that didn't get the same ancestors (probably a mistake in my ecore model but it is to late to change it), how can I do to loop over all the classes? I tried to cast them with OclAny and T but the twice give me the following error:

Module generateHtml for block for (aContenu.oclAsType(site::Rubrique).eContents()). site.impl.TexteImpl was not an instanceof T.

Here is the code where the error is thrown:

[for (aDiv : T | aContenu.oclAsType(Rubrique).eContents())]
[if aDiv.oclIsTypeOf(Texte) ]
<p class="texte">[aDiv.oclAsType(Texte).texte /]</p>
[/if]
[if aDiv.oclIsTypeOf(Lien) ]
<a href="aDiv.oclAsType(Lien).adresse">[aDiv.oclAsType(Lien).libelle/]</a>
[/if]
[/for]

Thanks for your help, and sorry for my english (I'm french)..
Re: How to use generic types with for sequence? [message #986870 is a reply to message #986838] Thu, 22 November 2012 08:01 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

Having a common superclass would be the easiest way, but you can also do through ifs :

[for (aDiv: EObject | aContenu.eContents())]
  [if (aDiv.oclIsKindOf(Rubrique) or aDiv.oclIsKindOf(AnotherType) or ...]
    generate this
  [/if]
[/for]


Laurent Goubet
Obeo
Re: How to use generic types with for sequence? [message #986940 is a reply to message #986870] Thu, 22 November 2012 12:52 Go to previous messageGo to next message
TASSIN Florian is currently offline TASSIN FlorianFriend
Messages: 2
Registered: November 2012
Junior Member
Thanks for your reply.

I tried with EObject as generic type but it says me "Invalid Type: EObject" and it fails at the compilation.

I also tried with T and OclAny which didn't show any advertissement but which also fails at the compilation time with the following message:

org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type for iteration at line 24 in Module generateHtml for block for (aContenu.eContents()). site.impl.TexteImpl was not an instanceof T.
Re: How to use generic types with for sequence? [message #986988 is a reply to message #986940] Thu, 22 November 2012 17:24 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

OCL has yet to be fully aligned with UML 2.x and so there is no support
for generic types; consequently there is no support for generic types in
Acceleo.

In the Ecore-based version of Eclipse OCL, "T" and "T1" are magic
non-types used for declaration purposes of e.g. Set(T) which looks like
but is not a UML templated type. Their specified semantics is unclear.
Don't expect them to do anything useful for you.

The new Pivot-based version of Eclipse OCL prototypes a variety of UML
alignment resolutions including support for generic types. "T" and "T1"
are no longer magic, they are just the names of declared template
parameters.

Regards

Ed Willink


On 22/11/2012 12:52, TASSIN Florian wrote:
> Thanks for your reply.
>
> I tried with EObject as generic type but it says me "Invalid Type:
> EObject" and it fails at the compilation.
>
> I also tried with T and OclAny which didn't show any advertissement
> but which also fails at the compilation time with the following message:
> org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid type
> for iteration at line 24 in Module generateHtml for block for
> (aContenu.eContents()). site.impl.TexteImpl was not an instanceof T.
Re: How to use generic types with for sequence? [message #987047 is a reply to message #986988] Fri, 23 November 2012 07:57 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Florian,

T is a non-existing type and should not be used, Ed explained that better than I could.

You have to use an existing type for the loop variable, and the best choice when you have no common-supertypes is EObject. If it is not recognized as-is by OCL, use its qualified name :

[for (aDiv: ecore::EObject | aContenu.eContents())]
  [if (aDiv.oclIsKindOf(Rubrique) or aDiv.oclIsKindOf(AnotherType) or ...]
    generate this
  [/if]
[/for]


Laurent Goubet
Obeo
Previous Topic:[Acceleo] EMTL files not contained in build
Next Topic:EMFT JET Transformation Project Error: Could not load JET template loader
Goto Forum:
  


Current Time: Sat Apr 20 16:03:44 GMT 2024

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

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

Back to the top