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

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

问题描述

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



这是重构遗留代码时经常遇到的重复任务。无论如何,我目前正在使用Eclipse 3.0.2,但是如果可以在更新版本的eclipse中使用Eclipse,那么仍然会对这个答案感兴趣。谢谢!

解决方案

我不认为这种重构存在。



Bug 225716 有(2008年初以来)。

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


创建一个新课程,并将相关领域和方法从旧类移动到新类中。


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


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.

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.

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."

I mention a workaround in this SO answer.

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

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