| Summary: | [quick assist] create fields from multiple parameters | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Lars Svensson <oxvalley> | ||||||
| Component: | UI | Assignee: | Noopur Gupta <noopur_gupta> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | enhancement | ||||||||
| Priority: | P3 | CC: | channingwalton, daniel_megert, f.neblung, Lars.Vogel, markus.kell.r, noopur_gupta, psuzzi, sandra.lions-piron, stephan.herrmann, stepper | ||||||
| Version: | 3.7 | Flags: | noopur_gupta:
review-
|
||||||
| Target Milestone: | 4.6 M7 | ||||||||
| Hardware: | All | ||||||||
| OS: | All | ||||||||
| See Also: |
https://git.eclipse.org/r/69497 https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=efe3e2778fd024ed9b8e81ac10ed369eabda4fb3 |
||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
We already have a quick assist "Assign parameter to new field" for single parameters (put caret into parameter name and press Ctrl+1). I'll keep this bug to turn this into a multi-fix (such that Ctrl+Enter assigns all parameters to new fields). Excellent this with Ctrl-1. I just never got the idea of looking under "Quick Fix" for such a function. But if Quick fix also had the option "Assign ALL parameters to fields" we would be done her.. *** Bug 123421 has been marked as a duplicate of this bug. *** It would be great to see this feature. In general I want a constructor to just assign the given params to fields. Repeatedly doing the CTRL+1 trick works, but is still cumbersome. You can assign this issue to me. Created attachment 243493 [details] Unit Test + Patch As opposed to the single "Assign parameter to new field" quick fix, I do not add any linked proposals. This contribution complies with http://www.eclipse.org/legal/CoO.php (In reply to sandra lions from comment #6) AssignToVariableAssistProposal#doAddAllFields() should not duplicate so much code. Please share the bulk of the implementation with the old doAddField() and just make the latter a special case that only assigns a single field. For the 'all' quick fix, the linked proposals are also important. To keep the proposals for the different fields apart, you have to use different groupIDs, e.g. KEY_NAME + parameterIndex. We don't use assert statements. The first one in doAddAllFields is already ruled out by the type check before. The loop over methodDecl.parameters() should not use toArray(). It should use List<SingleVariableDeclaration> parameters= methodDecl.parameters(); and then directly loop over the list items with get(int). You may wonder why the assignment compiles without a warning. That's because the "Ignore unavoidable generic type problems due to raw APIs" option is enabled in the project's preferences. Local variables should not be marked final unless necessary. Created attachment 243612 [details] Unit Test + Patch version 2 Take into account Markus Keller comments (comment 7). *** Bug 478011 has been marked as a duplicate of this bug. *** Would this new quick fix work on normal *method* parameters, too? Like the old single parameter quick fix... (In reply to Eike Stepper from comment #10) > Would this new quick fix work on normal *method* parameters, too? Like the > old single parameter quick fix... Yes. Would be nice to have more N&N entries for JDT M3. I set the M3 target for this bug, please adjust if necessary. As stated in Bug 478011, it would be nice to have this additional quickfix. There are some things I don't understand: - version 3.7 , but current org.eclipse.jdt.ui is v.3.12 --> update - status assigned, but no assignee --> assign this or fix status - is the attachment still actual ? --> gerrit push, review, git commit (In reply to Patrik Suzzi from comment #13) > There are some things I don't understand: > - version 3.7 , but current org.eclipse.jdt.ui is v.3.12 --> update This one is simply explained: the bug was raised against 3.7, this just records the history, when this was first detected / requested. Planning happens via the "Target Milestone", currently set to 4.6 M4. More can be seen by clicking "History" in the bug header. (In reply to sandra lions from comment #8) > Created attachment 243612 [details] [diff] > Unit Test + Patch version 2 The patch works but has issues like: - Command not added to plugin.xml - Missing checks in QuickAssistProcessor#getAssignAllParamsToFieldsProposals - Linked mode should end after the last statement generated in the method, not the first - Assigning method to fVariableKind and fNodeToAssign is logically incorrect and needs a rewrite of the approach used in AssignToVariableAssistProposal I will upload a new patch for this. New Gerrit change created: https://git.eclipse.org/r/69497 Gerrit change https://git.eclipse.org/r/69497 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=efe3e2778fd024ed9b8e81ac10ed369eabda4fb3 |
Build Identifier: There is already a function Source->Create constructor using fields. I would like just the opposite. When I program I call constructors that do not exists: MyClass m = new MyClass("first", "second", "third"); I then use the light bulb to create this new constructor. Inside the constructor I change the names of the parameters and begin the hard work I would like some help with: public MyClass(String firstValue, String secondValue, String thirdValue){ // These lines could be generated automatically // Prefix 'i' is already there under "Code Templates" iFirstValue = firstValue; iSecondValue = secondValue; iThirdValue = thirdValue; } // Also, the fields would have to be created: private String iFirstValue; private String iSecondValue; private String iThirdValue; Reproducible: Always