简体   繁体   English

为什么在Eclipse中禁用“Generate Getters and Setters ...”快捷方式?

[英]Why would “Generate Getters and Setters…” shortcut be disabled in Eclipse?

I am using Eclipse 4.9.0. 我正在使用Eclipse 4.9.0。

I have a whole bunch of fields for which I want to generate getters and setters in a certain file. 我有一大堆字段,我想在某个文件中生成getter和setter。 However, the option does not appear in the context menu (alt+shift+S), and if I go to menu bar Source > Generate Getters and Setters... , it is grayed out (disabled). 但是,该选项不会出现在上下文菜单中(alt + shift + S),如果我转到菜单栏Source> Generate Getters and Setters ...,它将显示为灰色(禁用)。

In another file in the same project the option is available, so it is not a problem with my IDE. 在同一项目中的另一个文件中,该选项可用,因此我的IDE不存在问题。

To make things stranger, when I hover over the variables and the suggestions to address that these variables are not used come up, one of them is the option to create getters and setters, and selecting that does bring up the dialogue, but only for one field at a time. 为了让事情变得陌生,当我将鼠标悬停在变量和建议上以解决这些变量未被使用时,其中一个是创建getter和setter的选项,并且选择确实会引发对话,但仅限于一个一次一个字段。 It does successfully create getters and setters that way. 它确实成功地创建了getter和setter。

Sample code: 示例代码:

@Entity
public class sampleClass extends anotherClass {

  @Id
  private String sampleVar1;
  private String sampleVar2;
  private Date sampleVar3;
  private int sampleVar4;

What would cause the getter/setter generation to be disabled? 什么会导致getter / setter生成被禁用?

I think the problem is your cursor placement. 我认为问题是你的光标位置。 I guess you are not placing your mouse pointer in the right place. 我想你不是把你的鼠标指针放在正确的位置。 If you place your cursor anywhere outside the class parenthesis then you may not be able to generate it. 如果将光标放在类括号外的任何位置,则可能无法生成它。 Make sure your mouse pointer is next to your variable assignment. 确保鼠标指针位于变量赋值旁边。 Let me know if this helps. 如果这有帮助,请告诉我。

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

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