简体   繁体   English

有什么方法可以自动将“此”关键字添加到Intellij Idea中的类字段吗?

[英]Is there any way to add “this” key word automatically to class fields in Intellij Idea?

For example, instead of this: 例如,代替此:

public String getName(){
    return name;
}

I want to get this: 我想得到这个:

public String getName(){
    return this.name;
}

It appears I used such setting in Eclipse, but I can't find it for Idea... 看来我在Eclipse中使用了这样的设置,但是我在Idea中找不到它。

Yes, you can use an inspection for that. 是的,您可以为此进行检查。

  • search inspections for "this" 搜索检查“此”
  • enable "Instance field access not qualified with 'this'" in "Code style issues" (see capture below) 在“代码样式问题”中启用“实例字段访问不符合'this'资格”(请参见下面的捕获)

启用“实例字段访问不符合'this'的条件”

Now IntelliJ Idea will highlight not qualified access and you can refactor ( ALT - ENTER under linux) to fix the issue (see capture below) 现在,IntelliJ Idea将突出显示不合格的访问权限,您可以重构(在Linux下为ALT - ENTER )来解决此问题(请参见下面的捕获)

解决问题

(screenshots from IntelliJ Idea 12 under linux) (来自Linux下的IntelliJ Idea 12的屏幕截图)

暂无
暂无

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

相关问题 是否有任何键盘快捷键可在IntelliJ Idea的课堂上添加@SuppressWarnings? - Is there any keyboard shortcut to add @SuppressWarnings on class in IntelliJ Idea? IntelliJ Idea高级搜索包含特定单词的类中的关键字 - IntelliJ Idea advanced search for key word in the classes containing a certain word 有没有办法在 Intellij Idea 中用另一个类替换类? - Is there a way to replace class by another one in Intellij Idea? 是否有任何选项可以自动修复 Intellij IDEA 中的数据类型? - Is there any option to automatically fix the data types in Intellij IDEA? Intellij Idea - 自动将 final 关键字添加到生成的变量中 - Intellij Idea - automatically add final keyword to the generated variables Intellij Idea现场团队介绍,可按班级字段创建设置器 - Intellij Idea live teamplate for create setters by class fields 任何方式(或快捷方式)自动导入 IntelliJ IDEA 中的类,如 Eclipse? - Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse? IntelliJ IDEA:有没有办法列出一个类及其父类实现的所有接口? - IntelliJ IDEA: Is there a way to list all interfaces implemented by a class and its parents? 将外部 jars (lib/*.jar) 添加到 IntelliJ IDEA 项目的正确方法 - Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project Intellij IDEA:如何将单个类文件添加到项目 - Intellij IDEA: How to add single class file to project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM