前言

一个好的format配置,可以让代码更整洁易读,而且可以 组合操作,减少开发的工作量,提升工作效率。

本文主要讲一讲关于eclipse中format的配置。

协议说明

Google Java Style文档详细的定义了谷歌在Java开发中的详细代码风格,当然其中也不乏有争议的地方,你也可以根据自己的需求做相应的细节调整,如果你不想做任何调整,可以直接下载Eclipse Java Google Style,然后通过Window -> Preferences -> Java -> Code Style -> Formatter > Import ,导入该xml完成GoogleStyle配置。

因为我接触Java较早,写了一些自己用的代码库,由于自己电脑的渣分辨率,在使用GoogleStyle的时候,感觉不太好,所以就在这个协议的基础上,做了一些细节上的修改。

Codelogger Formatter

Codelogger Code Formatter里面包含了Codelogger所有的可导出的代码风格配置文件,不能导出的,将在下文进行配置说明。

导入方式, 以Codelogger-Java-Code-Formatter.xml为例,步骤:Window > Preferences > Java > Code Style > Formatter > Import, 选取Codelogger-Java-Code-Formatter.xml导入,点击Apply然后OK就可以了。

下面将进行Eclipse不能导出的相关配置,进行详细说明,所有配置都在Window > Preferences里进行。

General > Editors > Text Editors

*Window > Preferences > General > Editors > Text Editors

XML > XML Files > Editor

*Window > Preferences > XML > XML Files > Editor

Web > Html Files > Editor

*Window > Preferences > Web > Html Files > Editor

Java > Editor > Save Actions

*Window > Preferences > Java > Editor > Save Actions

你在Save Actions中添加的所有actions,都会在你进行保存操作的时候触发,然后完成保存,所以这样可以强制进行代码格式化等操作,当然这也是一把双刃剑,请自己根据情况配置。

Java > Editor > Content Assist > Favorites

*Window > Preferences > Java > Editor > Content Assist > Favorites

You can define a list of static members and types containing static
members on this page. Content assist will propose those members even
if the import is missing.

Action Description
New Type Add a new type to the list. All static members declared by the added type will be proposed by content assist.
New Member Add a static member to the list. The member will be proposed by content assist.

简单来说,Type具体到类,Member具体到方法,内容提示助手在你在没有本类引入访包或方法的情况下,也给予提示。

后记

根据上面配置的Code Style,能够确保代码风格统一,在做git的merge的时候,尽量减少因为代码风格不统一而造成冲突。

拥有个人喜欢的favorites,根据save而触发的actions都能更进一步的提高代码编写速度。

希望本文对你有所帮助。




如果您觉得这篇文章对您有所帮助, 点我, 可以请我喝杯咖啡。
< 支付宝 | 微信 >
Published with Hexo and Theme by Kael
Flag Counter
X