Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 80364

Summary: [Quick Assist] "Assign parameter to field" does not work for existing field
Product: [Eclipse Project] JDT Reporter: Thomas Singer <eclipse>
Component: UIAssignee: Martin Aeschlimann <martinae>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, david, dcorbin, hudsonr, preuss
Version: 3.1   
Target Milestone: 3.1 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Thomas Singer CLA 2004-12-07 08:42:12 EST
In this small example, there does not occur the quick-fix to "Assign parameter
to new field":

public class Foo {

	private final Bar bar;
	
	public Foo(Bar bar) {
	}
}

Even worse: when I remove the final from the variable declaration, invoking the
quick-fix creates a new variable bar2 instead of reusing the existing one.
Comment 1 Dani Megert CLA 2004-12-07 11:43:39 EST
Regarding the last comment: maybe another quick fix "assign to..." would be nice
since the current really says "new" and hence it's not OK the reuse an existing one.
Comment 2 Thomas Singer CLA 2004-12-08 04:51:16 EST
Why not remove the "new" from the quick-fix' name and ask the user in the
situation, when the variable already exists, whether it wan't to reuse it or
assign it a new one? (although adding a new quick-fix "Assign parameter to
existing field" also sounds useful, but might be more difficult, because you
would need to allow selection of existing member variables)
Comment 3 Martin Aeschlimann CLA 2004-12-08 05:59:08 EST
quick fix doesn't show dialogs to ask users. But what we can do is to offer 
more than one proposal. 'Assign to field 'xxx'' if the type matches.
Comment 4 Thomas Singer CLA 2004-12-08 06:05:01 EST
> quick fix doesn't show dialogs to ask users.

OK, although I think, this is a too hard restriction.

> But what we can do is to offer more than one
> proposal. 'Assign to field 'xxx'' if the type matches.

Sounds good-enough for me.

Tom
Comment 5 Martin Aeschlimann CLA 2005-05-19 09:58:24 EDT
fixed > 20050519
Comment 6 Martin Aeschlimann CLA 2005-05-19 10:51:55 EDT
*** Bug 81645 has been marked as a duplicate of this bug. ***
Comment 7 Martin Aeschlimann CLA 2005-05-23 10:22:09 EDT
*** Bug 96142 has been marked as a duplicate of this bug. ***
Comment 8 David Saff CLA 2005-05-27 10:31:29 EDT
Verifying...
Comment 9 David Saff CLA 2005-05-30 09:25:50 EDT
Original bug not fixed in I20050527-1300.  There's still no quick-fix on the
parameter to "Assign parameter to new field".
Comment 10 Martin Aeschlimann CLA 2005-05-30 09:57:31 EDT
in fact you are right. From comment 2 I aassumed that 'assign to existing' was
really wanted here. Thomas please protest if I was wrong.
Comment 11 Thomas Singer CLA 2005-05-30 14:48:37 EDT
I don't know, how exactly you fixed it, but from what I read I think there are
two possible solutions:

1) Rename "Assign parameter to new field" to "Rename parameter to field" and
allow to enter a field name (in a separate dialog, which also allows to mark the
field final when invoked in a constructor), which might be an already existing
one. By default, the suggested name is like the parameter. This is the way IDEA
does; since a couple of EAP builds not only from the constructor, but from every
method.

2) Add another quick-fix "Assign parameter to field 'xyz'".
2a) There is one quick-fix entry for each matching (existing) field
2b) The user can select in a dialog the field to assign to.


I would prefer variant 1) because I already are accustomed to IDEA's behaviour.
Comment 12 Martin Aeschlimann CLA 2005-06-15 06:47:47 EDT
*** Bug 71863 has been marked as a duplicate of this bug. ***
Comment 13 Markus Keller CLA 2005-06-24 08:56:48 EDT
Verified in I20050624-0010 that quick assists "Assign parameter to new field"
and "Assign parameter to field 'bar'" work, unless the field bar is declared final. 

Filed bug 101624 for the remaining problem.