Skip to content

Commit

Permalink
[enhancement](community): enhance java style (#9693)
Browse files Browse the repository at this point in the history
Enhance java style.

Now: checkstyle about code order is in this page--Class and Interface Declarations

This pr can make idea auto rearrange code
  • Loading branch information
jackwener authored May 20, 2022
1 parent 61a60d1 commit 0c4b477
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 7 deletions.
228 changes: 226 additions & 2 deletions build-support/IntelliJ-code-format.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ under the License.
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
</value>
</option>
<option name="ALIGN_MULTILINE_RECORDS" value="false" />
Expand Down Expand Up @@ -90,6 +88,232 @@ under the License.
<order>KEEP</order>
</group>
</groups>
<rules>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PUBLIC>true</PUBLIC>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PUBLIC>true</PUBLIC>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PROTECTED>true</PROTECTED>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PROTECTED>true</PROTECTED>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PRIVATE>true</PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PRIVATE>true</PRIVATE>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PUBLIC>true</PUBLIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PUBLIC>true</PUBLIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PROTECTED>true</PROTECTED>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PROTECTED>true</PROTECTED>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PACKAGE_PRIVATE>true</PACKAGE_PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<FINAL>true</FINAL>
<PRIVATE>true</PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<FIELD>true</FIELD>
<PRIVATE>true</PRIVATE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<FIELD>true</FIELD>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<INITIALIZER_BLOCK>true</INITIALIZER_BLOCK>
</match>
</rule>
</section>
<section>
<rule>
<match>
<CONSTRUCTOR>true</CONSTRUCTOR>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<METHOD>true</METHOD>
<STATIC>true</STATIC>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<METHOD>true</METHOD>
</match>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions docs/en/developer-guide/java-format-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,37 @@ standard java package
* Do not use `import *`
* Do not use `import static`

## Checkstyle
## Checkstyle Plugin

Now we have `formatter-check` in `CI` to check the code format.

### IDEA

If you use `IDEA` to develop Java code, please install `Checkstyle-IDEA` plugin.

Setting the `checkstyle.xml` file in `Tools->Checkstyle`.

Click the plus sign under Configuration File, select `Use a local Checkstyle file`, and select the `fe/check/checkstyle/checkstyle.xml` file.

### VS Code

If you use VS Code to develop Java code, please install `Checkstyle for Java` plugin, and config according to the [document](https://code.visualstudio.com/docs/java/java-linting) and the picture

## IDEA

### Auto format code

The automatic formatting function of `IDEA` is also recommended.

Go to `Preferences->Editor->Code Style->Java` click the config sign and select `Import Scheme`,select `IntelliJ IDEA code style XML`,and select the `build-support/IntelliJ-code-format.xml` file.

If you use VS Code to develop Java code, please install `Checkstyle for Java` plugin, and config according to the [document](https://code.visualstudio.com/docs/java/java-linting) and the picture.
### Auto rearrange code

Checkstyle will check declarations order according to [Class and Interface Declarations](https://www.oracle.com/java/technologies/javase/codeconventions-fileorganization.html#1852) .

After add the `build-support/IntelliJ-code-format.xml` file. Click `Code/Rearrange Code` to auto rearrange code.

![](/images/idea-rearrange-code.png)



22 changes: 19 additions & 3 deletions docs/zh-CN/developer-guide/java-format-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,33 @@ standard java package
* 禁止使用 `import *`
* 禁止使用 `import static`

## Checkstyle
## Checkstyle 插件

现在的 `CI` 之中会有 `formatter-check` 进行代码格式化检测。

### IDEA

如果使用 `IDEA` 进行 Java 开发,请在设置中安装 `Checkstyle-IDEA` 插件。

`Tools->Checkstyle``Configuration File` 里点击 `Use a local Checkstyle file`,选择项目的 `fe/check/checkstyle/checkstyle.xml` 文件。

同时推荐使用 `IDEA` 的自动格式化功能。
### VS Code

如果使用 VS Code 进行 Java 开发,请安装 `Checkstyle for Java` 插件,按照[文档](https://code.visualstudio.com/docs/java/java-linting)里的说明和动图进行配置。

## IDEA

### 自动格式化

推荐使用 `IDEA` 的自动格式化功能。

`Preferences->Editor->Code Style->Java` 的配置标识点击 `Import Scheme`,点击 `IntelliJ IDEA code style XML`,选择项目的 `build-support/IntelliJ-code-format.xml` 文件。

如果使用 VS Code 进行 Java 开发,请安装 `Checkstyle for Java` 插件,按照[文档](https://code.visualstudio.com/docs/java/java-linting)里的说明和动图进行配置。
### Rearrange Code

Checkstyle 会按照 [Class and Interface Declarations](https://www.oracle.com/java/technologies/javase/codeconventions-fileorganization.html#1852) 检测代码的 declarations 顺序。

在导入上面的 `build-support/IntelliJ-code-format.xml` 文件后,使用 `Code/Rearrange Code` 自动完成排序

![](/images/idea-rearrange-code.png)

0 comments on commit 0c4b477

Please sign in to comment.