Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to autogenerate wrappers in Eclipse?

Tags:

I have to create several proxies, to add, for example, logging. Something like that:

interface IMath {     public int add(a, b); }  class Math implements IMath {     public int add(a, b) { return a + b; } }  class MathWithLogs implements IMath {     private IMath realMath;     public int add(a, b) {         Log.d("tag", "valueable info");         return realMath.add(a, b);     } } 

Everything is fine as long as these interfaces aren't 20 methods and I have to add something to just one.

My question is, is there a way to autogenerate wrapper classes with some plugin for eclipse?

Or maybe there is a way to do something with annotations to invoke methods from realMath unless stated otherwise (like @Override)?

like image 662
Yuriy Kulikov Avatar asked Aug 17 '12 10:08

Yuriy Kulikov


People also ask

What are Eclipse stubs?

but for Eclipse instead of Visual Studio. Both NetBeans and Eclipse have a function that, if you declare a Java class to implement an interface but omit one or more methods, will automatically generate a stub method for you. The difference is that the Eclipse version will do nothing, and return zero or null, e.g.


1 Answers

Right click in any source file (.java) and navigate to source -> Override/Implement Methods/Generate Delegate Methods.

The first will paste the body of all methods of your immediate interface. the second will do the same for all the hierarchy up to Object(I guess, not sure). Hope this helps.

like image 58
Ved Avatar answered Sep 30 '22 06:09

Ved