Eclipse可以自动生成第三方库类的接口吗? [英] Can Eclipse auto-generate an interface of a 3rd party library class?

查看:159
本文介绍了Eclipse可以自动生成第三方库类的接口吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Apache Apache Commons网络库的FTPClient类中工作。遗憾的是,它并没有为大多数功能实现接口,这使得使用它的测试类变得棘手。所以,我以为我会创建我自己的类包装这个并实现一个接口。无论如何,这是背景。我的问题是,是否可能在Eclipse中生成一个接口(类似于Refactor-> Extract Interface),但是位于jar文件中的第三方代码?



澄清,我不是在寻找FTPClient来实现新的接口,而是创建一个模仿与FTPClient相同的公共API的接口。然后我可以创建自己的类来实现这个接口并包装FTPClient。

解决方案

为什么不从空类开始,如

  class MyWrapper {

private指示客户端;
}

然后,我会做Source - > Generate Delegate Methods,填充空的类,根据需要,委托调用底层的原始对象。从该类开始,您现在可以使用Refactor - > Extract接口...随着您需要生产的包装器,这将一次解决这两个问题(包装生成+接口生成)。


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.

解决方案

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.

这篇关于Eclipse可以自动生成第三方库类的接口吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆