I was wondering if there was some functionality for generating the skeletons of a decorator from an interface similar to Generate Setters and Getters
. I would like to create a class from an interface that took an instance of that interface and implemented every method as calling that same method with those same parameters on the instance. I have an ugly class from a library that I would like to decorate but it has ~50 methods and I only want to change the functionality of one of them and would like to save some typing. Is there anything like this?
Example, given the interface:
interface FooBar{ void foo( Object o ); Object bar(); }
produce something like the class:
class FooBarDecorator implements FooBar{ private final FooBar fubee; FooBarDecorator( final FooBar fb ){ this.fubee = fb; } public void foo( Object o ){ this.fubee.foo( o ); } public Object bar(){ return this.fubee.bar(); } }
Search – Eclipse Shortcuts CTRL SHIFT G – Search for current cursor positioned word reference in workspace. CTRL H – Java search in workspace.
If you press CTRL + I it will just format tabs/whitespaces in code and pressing CTRL + SHIFT + F format all code that is format tabs/whitespaces and also divide code lines in a way that it is visible without horizontal scroll.
Use the menu Search->File and in the "Containing Text" field type in "System. out. println*", in the "File name patterns" field type in "*.
Yes!! Right click on your fubee
member, select Source
-> Generate Delegate Methods
-> done! Although, I think that for this to work, you will have to write
class FooBarDecorator implements FooBar { // [...]
Letting the decorator implement the interface
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With