Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367231 - [generate delegate][refactoring] Generate Decorator Class
Summary: [generate delegate][refactoring] Generate Decorator Class
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-20 13:03 EST by Nathan Reynolds CLA
Modified: 2012-02-01 04:08 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 Nathan Reynolds CLA 2011-12-20 13:03:26 EST
Build Identifier: 20110916-0149

I would like to be able to click on the Source menu and have a menu item say
"Generate Decorator Class".  This will popup a dialog box in which I enter
the name of my new class and the source class name.  The dialog box will have
other controls similar to that of creating a new class dialog box (where
applicable).  

When the user clicks okay in the dialog box it will create the new class.  
The new class will implement all of the same interfaces and methods as the
source class.  The new class constructor will accept a reference to the
source class.  All of the methods in the new class will simply forward the
call to the source class.

This functionality makes it easy to use the Decorator Pattern.  See http://en.wikipedia.org/wiki/Decorator_pattern for more information.

Reproducible: Always
Comment 1 Deepak Azad CLA 2012-02-01 04:08:16 EST
You can do most of the heavy lifting already.

- Start with 
------------------------------------------------
interface MyInterface {
	void foo();
	void bar();
}
class Decorator {
	private MyInterface obj;
}
------------------------------------------------
- Select 'obj'
- Source > Generate delegate methods
- Select 'obj' again
- Source > Generate Constructor using fields

- Final result is 
------------------------------------------------
interface MyInterface {
	void foo();
	void bar();
}
class Decorator {
	private MyInterface obj;

	public Decorator(MyInterface obj) {
		super();
		this.obj = obj;
	}

	public void foo() {
		obj.foo();
	}

	public void bar() {
		obj.bar();
	}
}
------------------------------------------------

Closing as WONTFIX.