且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Intellij IDEA和eclipse代码格式一致的商业解决方案

更新时间:2022-08-14 16:28:54

Intellij IDEA使用教程相关系列 目录

目录


Intellij IDEA使用教程相关系列 目录


1、安装


2、配置


基础配置


import顺序配置


保存自动格式化


1、安装

点击File->Setting ->Plugins->Install plugin from disk...,选中解压好的/EclipseFormat/EclipseFormatter.zip安装包安装,重启后生效。


注:EclipseFormatter有针对不同idea版本,如果上述压缩文件不支持,请下载对应的版本


下载地址:https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter/versions

Intellij IDEA和eclipse代码格式一致的商业解决方案2、配置

基础配置

选择File->Setting ->Eclipse Code Formatter,勾选Use the Eclipse-code-formatter,在Supported file types:勾选Enable Java和Enable JavaScript。


并在Eclipse Java Formatter config file选择Eclipse用的formatter-profile-java.xml文件,这个选项会决定格式化Java代码的方式。


配置Import order,这个选项会决定组织import区域的方式。输入


java;javax;net;org;com;

配置Eclipse JavaScript Formatter config file的From File也为Eclipse用的formatter-profile-js.xml文件,这个选项会决定格式化Javascript代码方式。如下图:


Intellij IDEA和eclipse代码格式一致的商业解决方案注:上面的文件:formatter-profile-java.xml、formatter-profile-js.xml可在eclipse导出


助力通道:eclipse 代码模板导出配置


import顺序配置

File->Setting ->Editor


设置Class count to use import with '*': 99


Names count to use static import with '*' : 99Intellij IDEA和eclipse代码格式一致的商业解决方案Intellij IDEA和eclipse代码格式一致的商业解决方案使用Intellij的格式化快捷键"Ctrl+ALT+L"即可进行格式化。如果出错会输出提示到Event Log里,如果看到'xxx formatted sucessfully by Eclipse code formatter'则表示格式化成功。


使用Intellij的格式化快捷键"Ctrl+ALT+O"即可进行import包顺序格式化。


大招:保存自动格式化

1、打开setting,找到Plugins选项(安装Save Action 插件(如果有就跳过这一步))


搜索:Save Action  

Intellij IDEA和eclipse代码格式一致的商业解决方案Intellij IDEA和eclipse代码格式一致的商业解决方案2、重启之后,打开setting,找到我们的save actions(直接搜索)


第一个√标识保存代码时执行动作;(只有用ctrl+s才有效,idea自动保存不会触发)


第二个√格式化导包;(相当于触发了"Ctrl+ALT+O")


第三个√格式化代码;(相当于触发了"Ctrl+ALT+L")

Intellij IDEA和eclipse代码格式一致的商业解决方案