Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Eclipse auto-generate an interface of a 3rd party library class?

I'm working with Apache's FTPClient class in the Apache commons net library. Sadly it doesn't implement an interface for most of the functionality which makes testing classes which use it tricky. So, I thought I'd create my own class which wrappers this one and implements an interface. Anyway that's the background. My question is, is it possible in Eclipse to generate an Interface (similiar to Refactor->Extract Interface) but for 3rd party code sitting in a jar file?

Just to clarify, I'm not looking for FTPClient to now implement the new interface, but to create an interface which mimics the same public API as FTPClient. I can then create my own class which implements this interface and wrappers the FTPClient.

like image 990
Chris Knight Avatar asked Jun 15 '11 12:06

Chris Knight


1 Answers

Hm. Why not start with an empty class, like

class MyWrapper {

    private Referent client;
}

Then, I'd do "Source -> Generate Delegate Methods", populating the empty class with delegating calls to the underlying original object as I need them. From that class, you can now "Refactor -> Extract interface"... As you need the wrapper for production anyway, this will solve both problems (wrapper generation + interface generation) at once.

like image 64
Dirk Avatar answered Nov 19 '22 03:11

Dirk