简体   繁体   English

Eclipse重构-用直接字段访问替换Java getter和setter

[英]Eclipse Refactoring - Replace Java getters & setters with direct field access

For our pure data classes, we don't use getters or setters. 对于纯数据类,我们不使用getter或setter。 When refactoring old code, I would like to be able to quickly replace (typically Eclipse-generated) calls to getters & setters with direct field access. 重构旧代码时,我希望能够使用直接字段访问快速替换(通常是Eclipse生成的)对getter和setter的调用。

Is there a plugin that does that? 有没有这样做的插件?

Note : I'm not interested in the pros & cons of encapsulation or not, that has already been discussed too many times . 注意我对封装的优缺点不感兴趣,已经讨论了太多次了

So, I would like to replace: 因此,我想替换为:

myData.setValue(17);
int value = myData.getValue();

with: 与:

myData.value = 17;
int value = myData.value;

You can use the existing inline method refactoring. 您可以使用现有的内联方法重构。 Just make the field in question public and then execute that refactoring. 只需公开相关字段,然后执行该重构即可。 If your code base is too large to do this by hand, you might have a look at How to execute inline refactoring programmatically using JDT/LTK? 如果您的代码库太大而无法手动执行此操作,则可以看看如何使用JDT / LTK以编程方式执行内联重构?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM