Evaluating "If" condition in Acceleo/Sirius [message #1776412] |
Thu, 16 November 2017 04:49  |
Eclipse User |
|
|
|
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 #1776819 is a reply to message #1776452] |
Tue, 21 November 2017 18:01  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.05263 seconds