Bug 51540 - "Encapuslate field" can fail when two variables in one variable declaration. [refactoring]
Summary: "Encapuslate field" can fail when two variables in one variable declaration. ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P4 normal (vote)
Target Milestone: 3.0 M8   Edit
Assignee: Dirk Baeumer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-10 16:01 EST by Michael Scharf CLA
Modified: 2004-03-22 09:59 EST (History)
1 user (show)

See Also:


Attachments
Patch fixing the problem (6.37 KB, patch)
2004-02-24 19:12 EST, Dmitry Stalnov CLA
no flags Details | Diff
The updated patch can be applied to latest HEAD (2.64 KB, patch)
2004-03-16 16:04 EST, Dmitry Stalnov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Scharf CLA 2004-02-10 16:01:21 EST
Start with:
  public class Test {
	int fFoo, fBar;
  }

"Encapsulate field..." fFoo. This yields in:

  public class Test {
	private int fFoo, fBar;
	void setFoo(int foo) {
		fFoo = foo;
	}
	int getFoo() {
		return fFoo;
	}
 }

However, if some classes in the package refer to fBar, the code becomes 
uncompilable, because fBar is now private too....
Comment 1 Olivier Thomann CLA 2004-02-10 16:25:50 EST
Move to JDT/UI.
Comment 2 Dirk Baeumer CLA 2004-02-12 09:28:18 EST
Depends on overall 3.0 planning. 
Comment 3 Dmitry Stalnov CLA 2004-02-24 19:12:54 EST
Created attachment 8144 [details]
Patch fixing the problem

The patch creates new private variable declaration if original declaration
contains more than one fragment.

Also it fixes a problem when encapsulated field is declared inside anonymous
class. Previous implementation added getter and setter to the outer class.

Dirk, I didn't find any unit tests for encapsulate field refactoring. If you
tell me where they are then I will add new test case verifying this fix.
Comment 4 Dirk Baeumer CLA 2004-03-12 07:28:14 EST
The test cases are named SefTests and the resources folder is named 
SefWorkSpace.
Comment 5 Dmitry Stalnov CLA 2004-03-16 16:04:20 EST
Created attachment 8612 [details]
The updated patch can be applied to latest HEAD
Comment 6 Dirk Baeumer CLA 2004-03-22 09:59:15 EST
Patch verified and released for M8. For the record (I change 
ASTNode.getBodyDeclarations() to reflect current changes of the AST).