Bug 185338 - [refactoring] [dcr] Extract Class
Summary: [refactoring] [dcr] Extract Class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Karsten Becker CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-05-03 09:49 EDT by Benno Baumgartner CLA
Modified: 2007-08-09 09:40 EDT (History)
2 users (show)

See Also:


Attachments
Initial Release (138.51 KB, patch)
2007-07-20 10:01 EDT, Karsten Becker CLA
no flags Details | Diff
Close to final (202.44 KB, patch)
2007-07-25 05:00 EDT, Karsten Becker CLA
no flags Details | Diff
Updated Patch (70.57 KB, patch)
2007-07-25 10:30 EDT, Karsten Becker CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2007-05-03 09:49:48 EDT
I20070502-0010

Given:
package test;
public class UFO {
	private int x;
	private int y;
	private int z;
	
	private String homePlanet;
	
	public UFO(int x, int y, int z, 
			String homePlanet) {
		this.x= x;
		this.y= y;
		this.z= z;
		this.homePlanet= homePlanet;
	}
        
	public String toString() {
		return "An UFO from " + homePlanet +
			"is at position " +
			"[" + x + ", " + y + ", " + z + "]";
	}
}
It is possible to introduce a parameter object 'Position' for the constructor 'UFO', but this is not possible for the fields. The refactoring invoked on class 'UFO' and generating a field encapsulation object called 'Position' for fields x/y/z should produce a result like:

package test;
public class UFO {	
	private static class Position {
		private int x;
		private int y;
		private int z;
	}
	
	private Position position;	
	private String homePlanet;
	
	public UFO(int x, int y, int z, 
			String homePlanet) {
		
		position= new Position();
		position.x= x;
		position.y= y;
		position.z= z;
		
		this.homePlanet= homePlanet;
	}
	
	public String toString() {
		return "An UFO from " + homePlanet +
			"is at position " +
			"[" + position.x + ", " + position.y + 
			", " + position.z + "]";
	}
}

Of course with options to generate getters/setters and all the like.
Even more interesting in combination with introduce parameter object.
Comment 1 Martin Aeschlimann CLA 2007-05-04 05:52:43 EDT
see http://www.refactoring.com/catalog/extractClass.html
Comment 2 Karsten Becker CLA 2007-07-20 10:01:32 EDT
Created attachment 74258 [details]
Initial Release

First proposal for this refactoring. The javadoc is not quite ready, and the ui is more a stub. But one might test the results.
Comment 3 Karsten Becker CLA 2007-07-23 09:30:10 EDT
Personally I am not so happy about 'Extract Class' as name for this refactoring. Before releasing anything to CVS I would like to have the final name for it. My suggestion would be 'Introduce Field Object'. This shows the similarity to 'Introduce Parameter Object' and is not so close to the other Extract Interface, Extract Super Class and the like.
The Extract* refactorings are mostly side-effect free, but Extract Class can not be completely without side-effects. 
Comment 4 Martin Aeschlimann CLA 2007-07-23 10:12:32 EDT
We should use the name that is used in the refactoring references as in Fowlers book.
The refactoring is called 'Extract class' everywhere. 'Introduce Field Object' is not in use.
'Extract class from fields' and 'Extract class from parameters' would be a possibility.
Comment 5 Karsten Becker CLA 2007-07-25 05:00:54 EDT
Created attachment 74534 [details]
Close to final

Descriptor javadoc is still incomplete
Menuitem at wrong position, missing in context menu
Comment 6 Martin Aeschlimann CLA 2007-07-25 09:59:26 EDT
patch released > 20070725

Can you have a look at the following issues:
- Javadoc in descriptor
- using progress monitor in ExtractClassRefactoring
- make sure all tests pass
Comment 7 Karsten Becker CLA 2007-07-25 10:30:35 EDT
Created attachment 74567 [details]
Updated Patch

Fixed the tests that were broken by the patch tool
Finalised doc in ExtractClassDescriptor
Moved getAssignedValue() to GetterSetterUtil
Comment 8 Martin Aeschlimann CLA 2007-07-25 13:04:19 EDT
patch released > 20070725
Comment 9 Benno Baumgartner CLA 2007-08-08 12:21:16 EDT
This refactoring will be available in 3.3M1+
Comment 10 Markus Keller CLA 2007-08-09 09:40:23 EDT
Verified in I20070809-0010.