如何使用Eclipse在Java类中排序方法/成员? [英] How to sort methods/members of a Java Class by their usage in Eclipse?

查看:471
本文介绍了如何使用Eclipse在Java类中排序方法/成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

书籍CleanCode根据他们的呼叫顺序重新排序功能:

The book CleanCode recomments to sort functions by their call order:


如果一个函数调用另一个函数,它们应该垂直关闭,
和呼叫者应该在被叫方之上,如果可能的话。这给程序一个自然的
流程。

If one function calls another, they should be vertically close, and the caller should be above the callee, if at all possible. This gives the program a natural flow.

我想在我的清理程序中包含这个顺序。以下示例

I would like to include that order in my cleanup routine. The following example

public void content(){
   primary();
   secondary();
}   

private void secondary(){

}

private void primary(){

};

应自动重新排序到

public void content(){
   primary();
   secondary();
}

private void primary(){

};

private void secondary(){

}

(这不是字母顺序,而primary()和secondary()具有相同的修饰符。)

(This is not the alphabetical order and primary() and secondary() have the same modifiers.)

但是,我找不到Eclipse功能。 Eclipse似乎能够按照类型对成员进行排序,而不是按照它们的用法进行排序。

However, I could not find an Eclipse feature doing so. Eclipse just seems to be able to sort members by their type and not by their usage.

是否有我想要的默认功能或可以安装的其他Eclipse插件?

Is there a default feature that I missed or an additional Eclipse plugin that I could install?

(I我没有看到或提供这个命令的大纲视图,我想改变代码中的实际顺序。这个问题不是关于以这种方式改变代码的利弊。)

(I am not looking or an outline view that provides that order. I would like to change the actual order in the code. This question is not about the pros and cons of changing the code this way.)

相关文章:

如何在Eclipse中格式化时指定类成员的顺序

推荐答案

感谢ProgrammersBlock的评论,我发现这个插件处于测试状态:

Thanks to the comment of ProgrammersBlock I found this plugin in Beta status:

http://wiki.eclipse.org/Recommenders/CleanCodeMethodSorter

这篇关于如何使用Eclipse在Java类中排序方法/成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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