Save Actions 配置与选项详解

Save Actions 是idea一款格式自动化的插件,非常好用。

我的设置
在这里插入图片描述
在这里插入图片描述
以下设置详解引用自链接:Save Actions 配置与选项详解,看完再也不迷惑了

设置详解

General 基本设置

Activate save actions on save(before saving each file,performs the configured actions below)
保存时自动格式化

Activate save actions on shortcut
使用快捷键保存时自动格式化
使用场景:收到一份格式很乱的文件,可以使用这个快捷键自动格式化

Activate save actions on batch(Code>Save Actions>Execute on multiple files)
保存时批量格式化
这个没用过,因为有的时候你的格式化设置和同事的不一样,一起格式化了会导致合并时候有冲突

Formatting Actions 格式化触发设置
Optimize imports
优化导入(没有用到的类自动删去import,这个一般要勾选)

Reformat file
重新格式化文件(只要保存文件就会自动格式化)

Reformat only change code
仅仅当代码变化时重新格式化
以上两个设置是互斥的,意思是,要么代码变化时候触发,要么文件变化时触发
我一般勾选上面那个,觉得好用一点

Rerrange fields and methods(configured in “File>Setting>Editor>Code Style>(…)>Arragement”)
重新调整字段和方法的范围
不知道什么意思,没用过

Build Actions build设置
是在build项目时候用到的设置,这里就不讨论了

Java Inspection and Quick Fix 具体格式化设置
Add final modifier to field
给字段添加final修饰符
没用过不知道啥意思

Add final modifier to local variable or parameter
向局部变量或参数添加final修饰符
使用效果如下,所有的局部参数都添加了final修饰符

public void printStr(final String str1, final String str2, final String str3) {
        System.out.println(str1 + str2 + str3);
    }

这个选项我不会勾选,因为有的时候形参会发生变化

Add final modifier to local variable or parameter except if it is implicit
向非隐式的局部变量或参数添加final修饰符
不太理解这个非隐式是什么意思

Add static modifier to methods
给方法添加static修饰符
效果如下,不要勾选

public static void testStatic(String str) {
    System.out.println(str);
}

Add this to field access
字段的使用加上“this”指针
可勾可不勾,看个人的使用习惯。

Add this to method access
方法使用加上this
跟上面那个选项意思差不多,可勾可不勾,看代码习惯

Add class qualifier to static member access
静态成员访问添加类限定符
就是说静态方法访问了静态变量的话,会自动加上类.变量名,可以点

Add class qualifier to static member access outside declaring class
声明类外的静态成员访问添加类限定符
不太懂这个声明之外的类是什么意思,反正跟上面那个是互斥的

Add missing @Override annotions
添加漏写的@Override注解
可以勾

Add blocks to if/while/for statements
给if/while/for语句添加大括号

public String judgeIt(int a) throws Exception {
    if (a == 3) {
        return "yes";
    }
    throw new Exception();
}

Remove blocks from if/while/for statements
给if/while/for语句移除大括号

public String judgeIt(int a) throws Exception {
    if (a == 3) return "yes";
    throw new Exception();
}

Remove unnessary this to field and method
给字段或者方法去掉不必要的“this”
看个人习惯,我不怎么喜欢用this,所以会勾选这个

-Remove final from private method
私有方法去掉final关键字

private final String getStr(final String str) {// 设置后final关键字保存时会被去掉
    return str;
}

Remove explicit generic type for diamond
删除显式泛型类型的尖括号
这个我不懂什么意思,就没有勾

Remove unused suppress warning annotation
移除没用的Suppress警告

Remove unnecessary semicolon
删除不必要的分号

Change visibility of field or method to lower access
更改字段或方法的可见性以降低访问权限

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿界新星蔡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值