[Acceleo 3.4.1] Call a query on a String element from another project doesn't work at execution [message #1783248] |
Fri, 09 March 2018 15:35 |
Mad Vin Messages: 40 Registered: September 2013 |
Member |
|
|
Hi,
I've discovered another annoying thing... :/
If you have an Acceleo project in which you define a query on a String element, for example :
[query public isEmpty (aString : String) : Boolean = aString = ''/]
You can call this query from this project : the code compilation and the code execution are both OK.
But if you call this query from another Acceleo project in which you have added the dependency to the project defining this query, the compilation works, but the execution is KO with the following error :
java.lang.UnsupportedOperationException: Operation isEmpty() is undefined on type java.lang.String.
at org.eclipse.acceleo.engine.internal.environment.AcceleoLibraryOperationVisitor.getExceptionOperationCallFailed(AcceleoLibraryOperationVisitor.java:1056)
at org.eclipse.acceleo.engine.internal.environment.AcceleoLibraryOperationVisitor.callStandardOperation(AcceleoLibraryOperationVisitor.java:267)
at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitOperationCallExp(AcceleoEvaluationVisitor.java:1209)
at org.eclipse.ocl.ecore.impl.OperationCallExpImpl.accept(OperationCallExpImpl.java:390)
...
Very annoying isn't it ?
I suppose the same problem happens with all the standard types like Integer or Real ? Because it works well for queries on OclAny or metamodels types.
Is there a solution to use this query like this or it is mandatory to define the query like below : ?
[query public isEmpty (contextElement : OclAny, aString : String) : Boolean = aString = ''/]
I know it is highly recommended to always create queries and templates on a metamodel element, but for such simple queries, i would prefer to be able to use the format : instead of , especially when it works well in the project in which the query is defined.
FYI : I use the Java runner.
Best regards.
[Updated on: Fri, 09 March 2018 15:36] Report message to a moderator
|
|
|
|
Re: [Acceleo 3.4.1] Call a query on a String element from another project doesn't work at execution [message #1783372 is a reply to message #1783250] |
Mon, 12 March 2018 13:02 |
Mad Vin Messages: 40 Registered: September 2013 |
Member |
|
|
Hi !
There is no cache for the templates. The templates are always executed even with the same arguments. I'm sure of this because I use this principle to update the values of some static attributes (like counters for example) in Java classes, which can't work with the queries because of the cache.
The problem I described happens also with the templates. And the use of an invoke in my code each time I want to use this method is very ugly and impractical.
However, I've made a bad diagnosis about the cause of the problem : the problem is not that the query/template is defined in another project or applied on a standard type, it is I call it in a sub-expression returning the value of an argument. I haven't noticed it :/. Ex :
[template myTemplate(aPackage : Package]
[let aString : String = getAStringValue()]
[anotherTemplate('a string', 'another string', if aString.isEmpty() then '' else '# ' + aString endif)/]
[/let]
[/template]
If I add a let block storing the value returned by "if aString.isEmpty() then '' else '# ' + aString endif", it works well.
I've noticed such a similar problem previously : https://www.eclipse.org/forums/index.php/t/1087401/ and the bug 519518 has fixed this old problem. Maybe my current problem is the same, and so has been fixed too at the same time. Laurent could confirm if it is a different problem or not... Otherwise, I think it could be fixed like the bug 519518 because it looks like a similar cause.
Best regards.
[Updated on: Mon, 12 March 2018 13:05] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03776 seconds