英文:
How to rename a field managed by Lombok
问题
我经常在代码中使用Lombok的@Data注解。但有时候我需要重命名一个字段。我的集成开发环境(Eclipse)允许我重命名字段,但是所有引用并没有自动更新,这导致了许多错误,还需要大量手动工作来将引用更改为新的字段名。
有没有办法可以重命名一个字段并自动更新相应的引用呢?
谢谢提供任何提示!
Thorsten
英文:
I use Lombok quite a lot with @Data annotation. But sometimes I need to rename a field. My IDE (Eclipse) let me rename the field, but all references are not updated which results in a lot of errors and also lots of manual work to change the refernces to the new field name.
Is there any way to rename a field that automatically renames the references as well ?
thanks for any hints!
Thorsten
答案1
得分: 4
Renaming在lombok的后续版本中应该可以工作,最近出现了一些问题1。
在要重命名的字段上按Alt+Shift+R
(或者在项目资源管理器中找到字段然后选择重命名)。
确保选择您要执行的所有选项,例如在JavaDoc中更新引用或重命名getter和setter方法。
点击确定或预览!
--
1 https://github.com/rzwitserloot/lombok/issues/1758
英文:
Renaming should work in later versions of lombok, there has been some issues lately 1.
On the field you want to rename press Alt+Shift+R
(alternatively find a field in Project explorer a select rename)
and make sure you select all options you want to be performed e.g. updating references in JavaDoc or renaming getters and setters.
Hit the OK or Preview!
--
答案2
得分: 1
使用AccessLevel.NONE
@Getter(lombok.AccessLevel.NONE)
Long accountForFees;
public Long getAccountForFees() {
return accountForFees;
}
现在您可以使用IDE来重命名方法。
英文:
Use AccessLevel.NONE
@Getter(lombok.AccessLevel.NONE)
Long accountForFees;
public Long getAccountForFees() {
return accountForFees;
}
Now you can use IDE to rename method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论