Bug 527104 - [1.8] Add Java 8 code templates (ex.: lambdas)
Summary: [1.8] Add Java 8 code templates (ex.: lambdas)
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.7.1a   Edit
Hardware: PC Windows NT
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-10 05:15 EST by Mauro Molinari CLA
Modified: 2017-11-10 06:30 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mauro Molinari CLA 2017-11-10 05:15:40 EST
I would find extremely useful if JDT provided some code templates for some Java 8 features. Above all, a lambda code template, that allows you to type zero or more parameters (having it be context sensitive would be great!) and automatically adds the necessary structure, i.e.: () -> { }.

Here are some examples (which however seem not to be context sensitive): https://github.com/Tasktop/eclipse-templates

As an example, let Validator be javax.faces.validator.Validator, with its functional method be javax.faces.validator.Validator.validate(FacesContext, UIComponent, Object):

public class MyClass {

  private Validator myValidator = lamb| <= invoke code assist here

}

let "lambda" be the code template name, the completion could be:

public class MyClass {

  private Validator myValidator = (context, component, value) -> {
    | <= cursor here
  }
}
Comment 1 Dani Megert CLA 2017-11-10 06:02:48 EST
See also bug 513688.
Comment 2 Mauro Molinari CLA 2017-11-10 06:22:07 EST
Thank you! (In reply to Dani Megert from comment #1)
> See also bug 513688.

Thank you! I don't understand why I could not find it, I made multiple attempts to find one...

Any way, this might be useful to track also other Java 8 templates (like ones for Optional creation/consumption, for instance...).
Comment 3 Noopur Gupta CLA 2017-11-10 06:30:00 EST
(In reply to Mauro Molinari from comment #2)
> Any way, this might be useful to track also other Java 8 templates (like
> ones for Optional creation/consumption, for instance...).

Would you like to suggest and/or contribute such templates to JDT?