Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.1.0Release
-
Fix Version/s: 2.6.0.Release
-
Component/s: Refactoring
-
Labels:None
-
Number of attachments :
Description
Given the following example:
class Simple {
def test() {
def map = [one:"two"]
def foo = {
println map.one
}
}
}
If you run extract variable on map.one you get:
class Simple {
def test() {
def map = [one:"two"]
def mapOne = map.one
def foo = {
println mapOne
}
}
}
Which is incorrect. The variable should be within the scope of the closure above the println statement
This one is a little tricky because the refactoring engine assumes that the extracted local should be as close as possible to the declaration. But you are saying that it should be close to its first use.
There are semantic differences between these two options, but different situations may call for different uses.
I did try a similar scenario in Java and the result is putting the local variable inside the closure. We should probably be using the same behavior as JDT, so I'll keep this issue open.