Bug 389117 - [quick fix] Add "create final field 'xxx' in type 'YYY'" to list of quick-fix options, if the statement is in the constructor
Summary: [quick fix] Add "create final field 'xxx' in type 'YYY'" to list of quick-fix...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-09 04:57 EDT by Lukas Eder CLA
Modified: 2024-04-12 09:22 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Eder CLA 2012-09-09 04:57:11 EDT
If the quick fix context is within a constructor, it would be nice to provide an option to make the generated field a final field. This is best explained with an example:

----------------------------------------------------
public class Test {
    public Test() {
        this.couldBeFinal = 3;
        // Quick-fixing this only offers generating a non-final field
        // Some users may prefer a final field here
    }
    
    public void notConstructor() {
        this.cannotBeFinal = 4;
        // In this case, of course, final fields are not possible
    }
}
----------------------------------------------------

Note, that I have found a related issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=176877

When a new field is assigned to the constructor argument value, then, only final fields can be generated. For instance:

----------------------------------------------------
public class Test {
    public Test(int willBeFinal) {
        // Quick-fixing "willBeFinal" will generate a final field and
        // a corresponding assignment
    }
}
----------------------------------------------------
Comment 1 Eclipse Genie CLA 2020-04-30 12:51:27 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Lukas Eder CLA 2020-05-01 04:11:39 EDT
I would definitely still love this. In most of my classes, my fields are final, and it will be a long time until I can use records.
Comment 3 Eclipse Genie CLA 2022-04-22 14:41:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Eclipse Genie CLA 2024-04-12 09:22:23 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.