简体   繁体   中英

Refactor my Java code to replace attribute access to getters and setters

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

If you are using IntelliJ as your IDE, you can do this:

right click the public attribute -> refactor -> encapsulate fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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