Bug 82005 - "Encapsulate Field" changes the data type of member variable [refactoring] [sef]
Summary: "Encapsulate Field" changes the data type of member variable [refactoring] [sef]
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Dirk Baeumer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 82584 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-29 16:54 EST by conrad.roche CLA
Modified: 2005-02-11 05:01 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description conrad.roche CLA 2004-12-29 16:54:30 EST
Eclipse Version: Version: 3.1.0
Build id: 200412162000

Create this simple class in eclipse -
public class TestEncapsulate {

	String a, b;
}

1) Select the Field a
2) Right-click and select Refactor -> Encapsulate Field.
3) Click Ok.
4) The following code is generated -

public class TestEncapsulate {

	String b;
	private int a;

	/**
	 * @param a The a to set.
	 */
	void setA(String a) {
		this.a = a;
	}

	/**
	 * @return Returns the a.
	 */
	String getA() {
		return a;
	}
}

Problems
a) The field was changed to a private field even though it was package-private
earlier.
b) The data type was changed from String to int!!! 

The encapsulate field works fine when there is only one field delared in one
line (String a;)
It breaks in the above code for both fields 'a' & 'b'.
Comment 1 conrad.roche CLA 2004-12-30 09:11:07 EST
This happens when the member variables are package-private, protected or public. 
This does not happen when the variables are private.
Comment 2 Dirk Baeumer CLA 2005-01-14 05:29:57 EST
*** Bug 82584 has been marked as a duplicate of this bug. ***
Comment 3 Dirk Baeumer CLA 2005-02-11 05:01:44 EST
Fixed for M5.