英文:
Refactor my Java code to replace attribute access to getters and setters
问题
我刚刚重构了一个旧的Java库,并使用setter和getter替换了所有的公共属性。
现在,有大量的代码在周围直接访问那些旧属性。
有没有人知道是否有一个工具可以遍历所有的数百个类,并重构它们以替换对setter或getter的直接访问?
例如:
old.attr ="Hello!";
String c = old.attr;
到:
old.setAttr("Hello!");
String c = old.getAttr();
有没有类似的工具可以实现这个功能?
提前谢谢,
Juan
英文:
I just refactored an old Java library and replaced all public attributes with setters and getters.
Now, there are tons of code around that is accessing those old attributes directly.
Does anyone know of a tool that can go through all the hundreds of classes and refactor them to replace the direct access to the setter or getter ?
For example:
old.attr = "Hello!";
String c = old.attr;
To:
old.setAttr("Hello!");
String c = old.getAttr();
Is there something around that will do that magic?
Thanks in advance,
Juan
答案1
得分: 1
如果您正在使用IntelliJ作为您的集成开发环境(IDE),您可以执行以下操作:
右键单击公共属性 -> 重构 -> 封装字段
英文:
If you are using IntelliJ as your IDE, you can do this:
>right click the public attribute -> refactor -> encapsulate fields
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论