Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 287374 - [extract method] Allows extracting lhs of full qualified expression
Summary: [extract method] Allows extracting lhs of full qualified expression
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M2   Edit
Assignee: Deepak Azad CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-23 06:57 EDT by Benjamin Muskalla CLA
Modified: 2010-09-01 13:36 EDT (History)
2 users (show)

See Also:


Attachments
fix+test (2.60 KB, patch)
2010-09-01 13:36 EDT, Deepak Azad CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Muskalla CLA 2009-08-23 06:57:12 EDT
The refactoring correctly warns you if you try to extract the lefthandside of an assignment.
In case you only select the SimpleName of a FieldAccess the refactoring works but produces illegal code.

Snippet:

public class A {
	int i;
	
	public void f() {
		this./*[*/i/*]*/ = 4;
	}
}

Extract method on "i" and you end up with


public class A {
	int i;
	
	public void f() {
		this.extracted() = 4;
	}

	private int extracted() {
		return /*[*/i/*]*/;
	}
}

Expected would be an error message as we already do if you select the whole left hand side.
Maybe we can reuse SnippetFinder#isLeftHandSideOfAssignment that will be introduced by bug 264606
Comment 1 Daniele CLA 2009-10-21 05:46:08 EDT
it this bug also for this situation:

this.myField = this.computeSomething();

an extract method on the whole statement should work instead of giving "cannot extract lhs  of assignement"
Comment 2 Deepak Azad CLA 2010-09-01 13:36:29 EDT
Created attachment 177987 [details]
fix+test

Fixed in HEAD.
Comment 3 Deepak Azad CLA 2010-09-01 13:36:58 EDT
.