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

Bug 361539

Summary: [Xtend] use extension (i.e. setter) methods for assignments
Product: [Modeling] TMF Reporter: Sven Efftinge <sven.efftinge>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: knut.wannheden, sebastian.zarnekow
Version: 2.1.0Flags: sven.efftinge: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sven Efftinge CLA 2011-10-20 09:23:29 EDT
given the following extension function:

def void setFoo(MyObj it, String prefix) {
   ...
}

I'd like to call it using assignment syntax:

val MyObj x = ...

x.foo = "Hello World"
Comment 1 Knut Wannheden CLA 2011-10-20 10:25:55 EDT
Would it make sense to also allow:

val MyObj x = ...
x.foos += "Hello World"

for something like:

def List<String> getFoos(MyObj it) {
   ...
}

or the JavaBeans addFoo() style?
Comment 2 Sven Efftinge CLA 2011-10-20 10:28:29 EDT
Yes, but that should work already.
Comment 3 Sebastian Zarnekow CLA 2011-10-22 10:29:09 EDT
(In reply to comment #1)
> or the JavaBeans addFoo() style?

JavaBeans only use #add and #remove prefixes for listener registration. That's why we don't have any plans to support the #add prefix for sugared method invocation.
Comment 4 Sebastian Zarnekow CLA 2011-10-22 13:44:50 EDT
(In reply to comment #1)
> val MyObj x = ...
> x.foos += "Hello World"
> 
> for something like:
> 
> def List<String> getFoos(MyObj it) {
>    ...
> }


I added a test case for that example and for the variant that uses even more implicit variables:

..
val MyObj it = ..
foos += "Hello World"
..

def List<String> getFoos(MyObj something) {
..
}
Comment 5 Sebastian Zarnekow CLA 2011-10-24 04:28:56 EDT
Pushed to master.
Comment 6 Karsten Thoms CLA 2017-09-19 17:58:16 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 18:09:02 EDT
Closing all bugs that were set to RESOLVED before Neon.0