Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3.4.1] Call a query on a String element from another project doesn't work at execution
[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 Go to next message
Mad Vin is currently offline Mad VinFriend
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 :
aString.isEmpty()
instead of
isEmpty(aString)
, 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 #1783250 is a reply to message #1783248] Fri, 09 March 2018 15:58 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6114
Registered: July 2009
Senior Member
Hi

Sorry, I suspect that you are stuck with the limitation, which the following might explain....

Acceleo complies with the principle that templates/queries are never re-executed for the same arguments, rather the previous results are re-used; very helpful but sometimes surprising. Acceleo traces query/template execution and probably uses the trace as part of the re-use detection. Ensuring that simple operations such as 2+2 re-use rather than recompute involves a massive overhead on a trivial operation so it can be convenient to ignore the must re-use for non-EObjects. This pragmatism can accidentally spread to prohibit tracing of non-EObject queries even though this is a slightly different issue. So I suspect that what you describe is a bug. At least the foregoing corresponds to what I have been observing for QVTr where I have realized that the re-use/recompute decision seems to be a designer's heuristic.

(You could create a Java library of non-EObject methods that you make available by and include file of invoke's)

Regards

Ed Willink

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 Go to previous message
Mad Vin is currently offline Mad VinFriend
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

Previous Topic:[Acceleo]
Next Topic:Acceleo Tool
Goto Forum:
  


Current Time: Tue Nov 20 13:20:30 GMT 2018

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

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

Back to the top