Search code examples
eclipsejava-8keyboard-shortcutssts-springsourcetoolsuite

Method reference shortcut transformation in Eclipse Luna


In Spring Tool Suite

(Version: 3.7.0.RELEASE
Build Id: 201506290649
Platform: Eclipse Luna SR2 (4.4.2))

Is there a shortcut to go from something like:

Function<String, Integer> func = str -> Integer.valueOf(str);

to something like this:

Function<String, Integer> func =  Integer::valueOf;

(and backwards) via a keyboard shortcut?

I am aware of Ctrl+1 key combo, but it doesn't seem to offer the method reference conversion, hence this inquiry:

enter image description here


Solution

  • First, you need Eclipse 4.5 or greater, because that's when this particular assist was first published.

    Next you should avoid the "unused" warning on the variable, because otherwise content assist will jump to the nearest warning / error rather than proposing a change unrelated to any problem in the current code (this is not strictly necessary, but makes the next step easier).

    Finally, you need to position the cursor on the ->, because that's the only piece of syntax definitely identifying the lambda.

    convert to method reference assist

    See also the first item in the 4.5 "New-&-Noteworthy", Section on JDT.