可以eclipse转换/重构一个方法到类吗? [英] Can eclipse convert/refactor a method to a class?

查看:323
本文介绍了可以eclipse转换/重构一个方法到类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎应该是相当直接,但我看不到任何明显。我基本上想做到指向一个方法和refactor-> extract类。这将把有问题的方法带到一个新类,该方法作为顶级公共API。重构也会将任何所需的方法和变量拖放到新类中,如果旧类中没有其他方法使用它,则从旧类中删除它们。

This seems like it should be fairly straight-forward, but I can't see anything obvious. What I basically want to do it to point at a method and refactor->extract class. This would take the method in question to a new class with that method as top level public API. The refactoring would also drag any required methods and variables along with it to the new class, deleting them from the old class if nothing else in the old class is using it.

这是我在重构旧代码时经常遇到的重复性任务。无论如何,我目前使用Eclipse 3.0.2,但仍然有兴趣的答案,如果它可用在更新的eclipse版本。谢谢!

This is a repetitive task I often encounter when refactoring legacy code. Anyway, I'm currently using Eclipse 3.0.2, but would still be interested in the answer if its available in a more recent version of eclipse. Thanks!

推荐答案

我不认为这种重构存在。

I don't think this kind of refactoring exists yet.

错误225716 有已经记录了这种特性(自2008年年初)。

Bug 312347 也是这样重构的一个很好的实现。

Bug 225716 has been log for that kind of feature (since early 2008).
Bug 312347 would also be a good implementation of such a refactoring.


一个新类,并将相关字段和方法从旧类转移到新类中。

"Create a new class and move the relevant fields and methods from the old class into the new class."

我提到了此 SO答案中的解决方法

这篇关于可以eclipse转换/重构一个方法到类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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