Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Evaluating "If" condition in Acceleo/Sirius
Evaluating "If" condition in Acceleo/Sirius [message #1776412] Thu, 16 November 2017 09:49 Go to next message
Yash Khatri is currently offline Yash KhatriFriend
Messages: 31
Registered: October 2017
Member
I am facing problem on evaluation of this if condition:

[if (loadedVocabularies->size()=0) then '' else (loadedVocabularies->select(v : Vocabulary | v.terms->select(t : Term | t.oclIsTypeOf(Class))->notEmpty() ))  endif/]


loadedVocabularies is a eList that contains eList of Vocabulary and Vocabulary contains eList of Terms .

I do not want to evaluate this statement if the loadedVocabularies does not contain any thing.

If the loadedVocabularies is empty I am getting this compilation error on console:

!ENTRY org.eclipse.acceleo.parser 4 0 2017-11-16 10:34:40.567
!MESSAGE Compilation error for expression [if (loadedVocabularies->size()=0) then '' else (loadedVocabularies->select(v : Vocabulary | v.terms->select(t : Term | t.oclIsTypeOf(Class))->notEmpty() )) endif/] : Unknown type (Vocabulary)


However it works well if loadedVocabularies in not empty. I am expecting the else condition should not be evaluated when if condition is true.

What am I missing here?

Any pointers?
Re: Evaluating "If" condition in Acceleo/Sirius [message #1776422 is a reply to message #1776412] Thu, 16 November 2017 10:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6621
Registered: July 2009
Senior Member
Hi

Your (runtime) expectation is correct.

What you are observing is a compile time problem. Perhaps Vocabulary is in a not-imported model, perhaps it needs disambiguation. IIRC Acceleo can get confused by complex expressions. Perhaps the origin of loadedVocabularies, that you do not show, is too complex and a let variable might help. In your particular example the Vocabulary in "v : Vocabulary | v.terms..." should be redundant so you could try "v | v.terms..." or even "terms..." both of which avoid an opportunity for the compiler to think that your Vocabulary is different to its own.

Regards

Ed Willink
Re: Evaluating "If" condition in Acceleo/Sirius [message #1776452 is a reply to message #1776422] Thu, 16 November 2017 14:32 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 470
Registered: May 2011
Senior Member
Hello,

In your VSM, on the parent representation description, containing your expression, have you set the metamodel (in the metamodel tab)? Is it possible that you have another metamodel with a class also named Vocabulary? In your expression, you can prefix the class name with the metamodel name in this pattern "metamodelName::className" so if your metamodel (or the package containing the Vocabulary eclass) is called "dictionnary" then you should have: ...select(v: dictionnary::Vocabulary...
Also, note that you do not need the parenthesis in the if block and that size()=0 can be replace by isEmpty like this: [if loadedVocabularies->isEmpty() then ...

Regards,
Steve


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Evaluating "If" condition in Acceleo/Sirius [message #1776819 is a reply to message #1776452] Tue, 21 November 2017 23:01 Go to previous message
Jad El-khoury is currently offline Jad El-khouryFriend
Messages: 41
Registered: August 2015
Member
It is odd that the operation works as expected if loadedVocabularies is not empty, so it cannot be that Vocabulary is not imported.
Worth noting also that loadedVocabularies is a result of a java service call that is to return a list of Vocabulary eClass instances.
Could it be that when the returned list is empty, the compiler does not recognise that the (empty) list is expected to be of type Vocabulary, hence it complains "Unknown type (Vocabulary)"?

In the end, what worked is the following:

[loadedVocabularies->select(v | v.oclAsType(vocabulary::Vocabulary).terms->select(t | t.oclIsTypeOf(vocabulary::Class))->notEmpty() ) /]


1. As suggested above, we replaced "v : Vocabulary" with simply 'v', to avoid the compilation error.
2. But then we need to replace "v.terms" with " v.oclAsType(vocabulary::Vocabulary).terms", since the compiler complained that it did not recognise 'terms', unless we tell it what the type of 'v' is first.

This change works for both empty, and non-empty loadedVocabularies.

But it is still not 100% clear why the compiler fails.
Previous Topic:Diagram extension question
Next Topic:The trigger when the node is moved
Goto Forum:
  


Current Time: Sun Apr 05 23:12:47 GMT 2020

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

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

Back to the top