Java Intellij (Android studio) 成员变量前缀
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22732722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Intellij (Android studio) member variable prefix
提问by Sergo Pasoevi
How do I configure Android Studio (or Intellij generally) to correctly generate getters and setters for member variables with prefixes?
如何配置 Android Studio(或通常的 Intellij)以正确生成带有前缀的成员变量的 getter 和 setter?
If I have a class
如果我有一堂课
public class Foo{
int mBar;
}
I want it to create getBar()
instead of getMBar
when I do Refactor->Encapsulate
or Generate
我希望它创建getBar()
而不是getMBar
当我做Refactor->Encapsulate
或Generate
EDIT
编辑
I found the way to do it per-project basis: You just go File->Settings->Project Settings->Code Style
我找到了按项目执行的方法:你去吧 File->Settings->Project Settings->Code Style
But it created a settings file somewhere in my project directory.
但它在我的项目目录中的某处创建了一个设置文件。
I want a solution which allows me to do it once for all projects, present and future.
我想要一个解决方案,让我可以为所有项目,现在和未来做一次。
采纳答案by Emil Re?a Enriquez
In Mac OS
在 Mac 操作系统中
- Android Studio -> Preferences -> Code Style -> Java
- on the right panel, click on the right arrow until you see
code generation tab
- Click ok
- Android Studio -> 首选项 -> 代码风格 -> Java
- 在右侧面板上,单击向右箭头,直到您看到
code generation tab
- 单击确定
回答by Davis
Try going to File-->Other Settings-->Default Settings. Your should be able to make prefixes for every other project that you do if you change prefix settings with the scheme set to default instead of Project. The prefix change would be in Java and Code Generation. That will fix setters and getters.
尝试转到文件--> 其他设置--> 默认设置。如果您更改前缀设置并将方案设置为默认而不是 Project,您应该能够为您所做的每个其他项目制作前缀。前缀更改将在 Java 和代码生成中进行。这将修复 setter 和 getter。
回答by Graeme
回答by Robert Odoch
- Open Android Studio's preferences (from the Android Studio menu on Mac and from File-> Settingson Windows and Linux).
- Expand Editorand then expand Code Style.
- Select Java, then choose the Code Generationtab.
- In the Namingtable, select the Fieldrow and add
m
as the name prefix forfields
. Then adds
as the name prefix forstatic
fields.
- 打开 Android Studio 的首选项(从 Mac 上的 Android Studio 菜单和Windows 和 Linux 上的文件->设置)。
- 展开编辑器,然后展开代码样式。
- 选择Java,然后选择代码生成选项卡。
- 在命名表中,选择字段行并添加
m
为 的名称前缀fields
。然后添加s
作为static
字段的名称前缀。
- Click Ok
- 单击确定