Bug 461417

Summary: [quick fix] Generate constructor if no constructor exists and if there are final members
Product: [Eclipse Project] JDT Reporter: Lukas Eder <lukas.eder>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: noopur_gupta
Version: 4.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Lukas Eder CLA 2015-03-04 11:35:56 EST
I have this class

public class X {
    final int i;
    final int j;
    ...
}

This class doesn't compile. I have to tediously write the constructor and repeat all field types and names and then assignments. Scala has case classes, which work the same way, but don't have the boilerplate.

It would be great if I could just auto-generate the constructor using Eclipse:

public class X {
    final int i;
    final int j;
    ...

    public X(int i, int j, ...) {
        this.i = i;
        this.j = j;
        ...
    }
}
Comment 1 Lukas Eder CLA 2015-03-04 11:38:19 EST
I realise that these are similar issues:

- https://bugs.eclipse.org/bugs/show_bug.cgi?id=80197
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=77147

But I don't think they're the same...
Comment 2 Lukas Eder CLA 2015-03-04 12:39:49 EST
In fact, I just realised that this feature already exists, but not as a quick-fix option. "Create constructor from fields...". Would be great to offer that feature as a quick-fix option!
Comment 3 Noopur Gupta CLA 2015-04-01 08:10:48 EDT

*** This bug has been marked as a duplicate of bug 345896 ***