成员变量前缀错误地添加到方法名称中
我正在使用 Eclipse 编写一些 Java 代码,并且我遵循的命名约定使用“m”作为类的任何成员变量的前缀。 一旦我编写了成员变量,我就喜欢转到 Source -> 生成 Getter 和 Setter。 这会生成我需要的方法。 但是,方法和参数名称也都包含此“m”前缀。 我希望 Eclipse 在命名我的方法及其参数时忽略前缀。 我怎样才能实现这个目标?
更新:我已经尝试过下面 Rich 的建议,但没有成功。 目前该选项已设置,并且我已在字段部分中输入“m”。 但Eclipse似乎没有考虑到这一点。 单击同一窗口上的帮助图标会弹出一条通知,说明在使用“代码辅助”和“重构”时将考虑这一点。 “生成 getter/setter”是否受代码协助?
I am using Eclipse to write some Java code and the naming convention that I am following uses an 'm' as a prefix to any member variables for a class. As soon as I write the member variables I like to go to Source -> Generate Getters and Setters. This generates the methods that I require. However, the method and parameter names all include this 'm' prefix too. I would like Eclipse to ignore the prefix when naming my methods and their parameters. How can I achieve this?
UPDATE: I have already tried Rich's suggestion below without any success. Currently the option is set and I have entered 'm' in the fields section. But Eclipse doesn't seem to take this into account. Clicking on the help icon on the same window brings up a notification saying that this will be taken into account when using 'code assist' and 'refactoring'. Does the 'generate getters/setters' come under code assist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您转到 Window->Preferences->Java->Code Style 并选择 Fields,然后 Edit... 并添加 m > 对于前缀列表,您生成的访问器方法将考虑前缀。
If you go to Window->Preferences->Java->Code Style and select Fields, then Edit... and add m to the prefix list, your generated accessor methods will take the prefix into account.