Bug 318553

Summary: [quick fix] Add quick fix for 'The parameter x should not be assigned'
Product: [Eclipse Project] JDT Reporter: Lars Svensson <oxvalley>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, ruediger.herrmann
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Example code
none
We get errors if compilition is set to errors on assinging values to parameters none

Description Lars Svensson CLA 2010-07-01 04:01:53 EDT
Build Identifier: 

When using Refactoring-> Extract Method, a parameter sometimes get assigned a new value, which is not completely allowed.

Reproducible: Always

Steps to Reproduce:
1.Write:
int i=0;

i=5;

System.out.println(i);


2.Mark line 2 "i=5;" and use Refactoring->Extract Method. Call the method anything you want 


3.The method will look like this:
public int foo(int i){
i=5;
return i;
}

Now we are assigning a value to a parameter which is bad. Even if we change compiling to "Assigning a value to a parameter" is set to 'Error'. We will then get a compiler error here.
Comment 1 Lars Svensson CLA 2010-07-01 04:05:34 EDT
Created attachment 173171 [details]
Example code
Comment 2 Lars Svensson CLA 2010-07-01 04:06:25 EDT
Created attachment 173172 [details]
We get errors if compilition is set to errors on assinging values to parameters
Comment 3 Lars Svensson CLA 2010-07-01 04:18:11 EDT
Tested in Ganymede, Galilleo and Helios
Comment 4 Dani Megert CLA 2010-07-28 11:30:25 EDT
Lars your example is wrong, you need to have "i=+5" to get a method with a parameter. Having said that, we don't want to change the generated code since it's better if it's as close to the extracted one as possible. What we could do is a adding a quick fix to get rid of the problem.
Comment 5 Lars Svensson CLA 2010-07-28 17:36:05 EDT
(In reply to comment #4)
> Lars your example is wrong, you need to have "i=+5" to get a method with a
> parameter. 


Not sure what you are meaning here... I double-checked this example and it gives me the same error... What am I explaining badly in my example??
Comment 6 Lars Svensson CLA 2010-07-28 17:37:48 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > Lars your example is wrong, you need to have "i=+5" to get a method with a
> > parameter. 
> Not sure what you are meaning here... I double-checked this example and it
> gives me the same error... What am I explaining badly in my example??

OK.. :-) Now I see my misstake.. bad explaining in text but my two attachments in comment 1 and 2 show the real reason for this error report...
Comment 7 Dani Megert CLA 2010-07-29 01:51:41 EDT
>OK.. :-) Now I see my misstake.. bad explaining in text but my two attachments
>in comment 1 and 2 show the real reason for this error report...
Exactly ;-)