Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 408937 - [1.8][rename] Unable to rename variables in lambda expression field
Summary: [1.8][rename] Unable to rename variables in lambda expression field
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Martin Mathew CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 408230
Blocks: 405305
  Show dependency tree
 
Reported: 2013-05-24 04:29 EDT by Noopur Gupta CLA
Modified: 2014-04-01 02:32 EDT (History)
3 users (show)

See Also:
manju656: review? (markus.kell.r)


Attachments
Patch with testcases. (20.33 KB, patch)
2013-09-06 08:11 EDT, Martin Mathew CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2013-05-24 04:29:29 EDT
Consider the following example and try to rename the variables mentioned in comments using "Alt+Shift+R":

@FunctionalInterface
interface I {
	int foo (int x);
}

public class C1 {
	I i= (int x) -> { // Unable to Rename "x"
		int p= 10; // Unable to Rename "p"
		I ii= (int a) -> a+100; // Unable to Rename "ii", "a"
		return ii.foo(x) + p;
	};

	void foo() {
		I i= (int x) -> x; // works here
	}	
}

We get the error, "Only local variables declared in methods and initializers can be renamed". 

However, it should be possible to rename variables in any type of lambda expr also.
Comment 1 Martin Mathew CLA 2013-09-06 08:11:19 EDT
Created attachment 235236 [details]
Patch with testcases.

Renaming of variables within lambda is taken care off. Testcases are also included.
Comment 2 Martin Mathew CLA 2013-09-19 02:32:49 EDT
Due to bug 408230 the below case(inferred parameter type) fails during rename operation.
I i1= (x) -> {
		x++; // Select 'x' and invoke rename
		return x;
	     };
Comment 3 Martin Mathew CLA 2014-02-14 01:35:57 EST
Released the fix to BETA_JAVA8 as:
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?h=BETA_JAVA8&id=1fa7558ed5b5098be920ba39ae0d8f2d68e3f004

(In reply to Manju Mathew from comment #2)
> Due to bug 408230 the below case(inferred parameter type) fails during
> rename operation.
> I i1= (x) -> {
> 		x++; // Select 'x' and invoke rename
> 		return x;
> 	     };
Added an additional test for the above case and released to BETA_JAVA8 as: 
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?h=BETA_JAVA8&id=ecba45b579d03f4e3032f64b0dc29bd0b019f356
Comment 4 Martin Mathew CLA 2014-04-01 02:32:51 EDT
Fixed, changes are available in master.