Bug 318553 - [quick fix] Add quick fix for 'The parameter x should not be assigned'
Summary: [quick fix] Add quick fix for 'The parameter x should not be assigned'
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-01 04:01 EDT by Lars Svensson CLA
Modified: 2012-05-29 05:02 EDT (History)
2 users (show)

See Also:


Attachments
Example code (5.12 KB, image/x-citrix-gif)
2010-07-01 04:05 EDT, Lars Svensson CLA
no flags Details
We get errors if compilition is set to errors on assinging values to parameters (7.37 KB, image/x-citrix-gif)
2010-07-01 04:06 EDT, Lars Svensson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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 ;-)