Files
doris/docs/zh-CN/developer/developer-guide/java-format-code.md
wangyongfeng 2d39cffa5c [doc](website)Add Doris new official website code and documents (#9977)
In order to cooperate with Doris's successful graduation from Apache, the Doris official website also needs a new look
and more powerful feature, so we decided to redesign the Doris official website.
The code and documents of the new official website are included in this PR.

Since the new website is completely rewritten, the content and structure of the project are different from the previous one. 
In particular, the directory structure of documents has changed, and the number of documents is large, so the number of 
files in this PR is very large.

In the old website,all English documents are in the en/ directory, and Chinese documents in the zh-CN/ directory,
but in the new website,the documents are split into multiple directories according to the nav.
The document's directory structure changes as follows:
```
docs (old website)
|   |—— .vuepress (library)
|   |—— en
|   |   |—— admin-manual 
│   │   |—— advanced
|   |   |—— article
|   |   |—— benchmark
|   |   |—— case-user
|   |   |—— community
|   |   |—— data-operate
|   |   |—— data-table
|   |   |—— design
|   |   |—— developer-guide
|   |   |—— downloads
|   |   |—— ecosystem
|   |   |—— faq
|   |   |—— get-starting
|   |   |—— install
|   |   |—— sql-manual
|   |   |—— summary
|   |   |___ README.md
|   |—— zh-CN
...

docs (new website)
|   |—— .vuepress (library)
|   |—— en
|   |   |—— community (unchanged, community nav)
│   │   |—— developer (new directory, developer nav)
│   │   |   |—— design (moved from en/design)
│   │   |   |__ developer-guide (moved from en/developer-guide)
|   |   |—— docs (new directory, all children directories moved from en/, document nav)
│   │   |   |—— admin-manual 
│   │   |   |—— advanced
│   │   |   |—— benchmark
│   │   |   |—— data-operate
│   │   |   |—— data-table
│   │   |   |—— ecosystem
│   │   |   |—— faq
│   │   |   |—— get-starting
│   │   |   |—— install
│   │   |   |—— sql-manual
│   │   |   |—— summary
|   |   |—— downloads (unchanged, downloads nav)
|   |   |—— userCase (moved from en/case-user, user nav)
|   |   |___ README.md
|   |—— zh-CN
...
```
2022-06-08 17:45:12 +08:00

2.6 KiB

title, language
title language
Java 代码格式化 zh-CN

Java 代码格式化

Doris 中 Java 部分代码的格式化工作通常有 IDE 来自动完成。这里仅列举通用格式规则,开发这需要根据格式规则,在不同 IDE 中设置对应的代码风格。

Import Order

org.apache.doris
<blank line>
third party package
<blank line>
standard java package
<blank line>
  • 禁止使用 import *
  • 禁止使用 import static

Checkstyle 插件

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

IDEA

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

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

注意: 保证Checkstyle的版本在9.3及以上(推荐使用最新版本)。

可以使用 Checkstyle-IDEA 插件来对代码进行 Checkstyle 检测

VS Code

如果使用 VS Code 进行 Java 开发,请安装 Checkstyle for Java 插件,按照文档里的说明和动图进行配置。

IDEA

自动格式化

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

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

Rearrange Code

Checkstyle 会按照 Class and Interface Declarations 检测代码的 declarations 顺序。

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