automated way to create a wrapper?


Is there a quick way to create wrapping classes?


i.e.

From:
-



public interface Foo
{
int method1 ();
int method2 ();
int method3 ();
}



To :
-



public class FooXXL implements Foo
{
private Foo __rawFoo;
public FooXXL (Foo i_rawFoo) {
__rawFoo = i_rawFoo;
}

public int method1 () { return __rawFoo.method1 (); }
public int method2 () { return __rawFoo.method2 (); }
public int method3 () { return __rawFoo.method3 (); }

}



Alain

0
Avatar
Permanently deleted user

More or less:

Implement methods in FooXXL
Replace inheritance with delegation


0
Avatar
Permanently deleted user

Alt-ins to implement Foo, add _rawFoo as a field in the implementation class (by hand! the horrors!), alt-Ins to create the constructor, alt-Ins to delegate all the methods.

Of course, depending on your design you may be better off using dynamic proxies and having the JVM do all of this work for you. Depends what you need the wrapper for.

--Dave Griffith

0
Avatar
Permanently deleted user


>.. (by hand! the horrors!), ..
>

>

posted:
"new refactoring: create a wrapper"
http://www.jetbrains.net/jira/browse/IDEA-1921

0
Avatar
Permanently deleted user

As always, and I mean this as the highest compliment, your commitment to developer laziness surpasses even mine.

--Dave Griffith

0
Avatar
Permanently deleted user

Dave

>As always, and I mean this as the highest compliment, your commitment to developer laziness surpasses even mine.
>

>

Thank you.

Alain

0

Sure, but a little code to start with is needed:

Then "Code -> Delegate Methods", select __rawFoo as target, select all methods of Foo.

0
Avatar
Permanently deleted user

Stephen

Thanks.

>Then "Code -> Delegate Methods", select __rawFoo as target, select all methods of Foo.

>

I was looking in the "delegate" direction, but all I could remember/find
was
"Replace Inheritance with Delegation"
Tunnel vision...


>Sure, but a little code to start with is needed..
>

All the mechanics to remove that step is already there, so
"new refactoring: create a wrapper"
http://www.jetbrains.net/jira/browse/IDEA-1921

should be really easy to implement.



Alain

0

请先登录再写评论。