Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 349749

Summary: Inconsistent query evaluation
Product: [Modeling] Acceleo Reporter: Ed Willink <ed>
Component: CoreAssignee: Project Inbox <acceleo-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: laurent.goubet, stephane.begaudeau
Version: 3.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Ed Willink CLA 2011-06-18 06:42:22 EDT
The following partial template works fine

[template public generateJava(result : String, ast : CollectionLiteralExp)]
[let listVarName : String = 'list_'+getSymbolName(ast)]
[let resultVarName : String = 'result_'+getSymbolName(ast)]
Value result_[getSymbolName(ast)/]; 
try {
	List<Value> [listVarName/] = new ArrayList<Value>(); 
[for (part : CollectionLiteralPart | ast.part)]
	[generateJava(listVarName, part)/]
[/for]

invoking

[query public getSymbolName(elem : Element) : String = 
invoke('org.eclipse.ocl.examples.build.acceleo.NameQueries', 'getSymbolName(java.lang.Object)', Sequence{elem}) /]

successfully. But if changed to

[let listVarName : String = 'list_'+getSymbolName(ast)]
[let resultVarName : String = 'result_'+getSymbolName(ast)]
Value result_[getSymbolName(ast)/]; 
try {
	List<Value> [listVarName/] = new ArrayList<Value>(); 
[for (part : CollectionLiteralPart | ast.part)]
	[generateJava('list_'+getSymbolName(ast), part)/]
[/for]
 
the getSymbolName in 'list_'+getSymbolName(ast) evaluates to the mumbo-jumbo for invalid.
Comment 1 Laurent Goubet CLA 2011-06-20 03:36:32 EDT
Ed,

I must admit that I have no idea as to why we wouldn't be able to find the proper operation call in the second case except ... what would be the priority of both operations?

i.e, does it evaluate correctly with this :

[generateJava(('list_'+getSymbolName(ast)), part)/]

I think that the parser does not manage to understand the type of its parameter when a "+" operator is embedded in there (having the "+" between Strings is one of the many things we've had to 'hack' OCL for since it takes precedence over us for this operation).
Comment 2 Ed Willink CLA 2011-06-20 04:34:22 EDT
(In reply to comment #1)
> one of the many things we've had to 'hack' OCL

Very plausible explanation; I am consistently amazed at how accurate Acceleo is despite inaccuracy in OCL underneath.

+ is one of many things that are fixed by the pivot binding; + is just a modeled operator, so the library model specifies what it does.
Comment 3 Stephane Begaudeau CLA 2011-08-09 06:15:31 EDT
>>> 'list_'+getSymbolName(ast) evaluates to the mumbo-jumbo
>>> for invalid.

If an ocl operation uses the result of another operation as an argument and if this other operation is an Acceleo operation (aka template or query call) then the operation call is changed to a template or query operation call. This "hack" was not performed if the operation was a *non standard* operation like "+". A fix has been contributed along with a unit test for "+". The unit tests will need to be expand to test all the operation in the Acceleo non standard library. The fix will be available in Acceleo 3.1.1
Comment 4 Laurent Goubet CLA 2016-04-01 11:11:00 EDT
This has been fixed since then.