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

Bug 390744

Summary: [Xcore] Lambda Expressions difficult to use in op
Product: [Modeling] EMF Reporter: Michael Vorburger <mike>
Component: XcoreAssignee: Ed Merks <Ed.Merks>
Status: CLOSED FIXED QA Contact: Ed Merks <Ed.Merks>
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on:    
Bug Blocks: 397324    

Description Michael Vorburger CLA 2012-09-28 22:13:52 EDT
This doesn't currently work in Xcore:

op MdfProperty getProperty(String propertyName) {
    properties.findFirst( property | property.name == propertyName )
}

The Xcore Editor shows no error, but the .java complains because propertyName is not final.

The workaround is to use

op MdfProperty getProperty(String propertyName) {
    val finalPropertyName = propertyName
    properties.findFirst( property | property.name == finalPropertyName )
}

which is not so nice.
Comment 1 Michael Vorburger CLA 2012-10-01 10:08:51 EDT
I just noticed that on http://wiki.eclipse.org/Xcore#Specifying_an_Operation there is a very similar example.. once this is addressed, it may be useful to others to change that to something like:

op Book getBook(String title) {
   books.findFirst( book | book.title == title )
}

May be as an alternative to the "classic" Java for (Book book : books) ...

Just a thought.
Comment 2 Ed Merks CLA 2012-10-03 02:00:09 EDT
Sven,

Should/does Xbase check that the referenced identifier is final?
Comment 3 Sebastian Zarnekow CLA 2012-10-03 03:28:28 EDT
Yes, we check that. JvmFormalParameters are always assumed to be final. Unfortunately there is no way to query parameters for their actual final state in the java.lang.reflect API so we had to make some assumptions.
Comment 4 Ed Merks CLA 2012-10-03 04:00:46 EDT
I see!

If I try to assign a parameter a new value in the XBlockExpression, it makes that same assumption and says I can't do the assignment. That implies I really should generate these parameters as final, at least for the case where I know there is a body generated based on Xbase-specified behavior...
Comment 5 Ed Merks CLA 2012-10-08 01:41:46 EDT
Changes to ensure that class methods corresponding to things with bodies specified in the model are generated as final are committed to master.

http://git.eclipse.org/c/emf/org.eclipse.emf.git/commit/?id=c890894964aed60c99e76223ac85f14dc1f315af
Comment 6 Ed Merks CLA 2013-07-10 11:26:24 EDT
The changes are available in Kepler.