Kengo's blog

Technical articles about original projects, JVM, Static Analysis and TypeScript.

My ideal Java coding rule checker

 I think coding rule and code analysis is helpful solution for Java. They develop advantage of Java, solidness, and help to change your project easy to read. We can use checkstyle, PMD, findbugs and another solution.
 コーディングルールやコード解析はJavaを使う上でとても役立つ技術だと思います。Javaの長所である堅牢性を伸ばしつつコードを読みやすくしてくれます。checkstyleやPMD、findbugsなどが実用的でしょう。

 But I think that they aren't major technology in Java community yet. FOSS project which has checkstyle.xml or pom.xml contains plugins for these tools are minor.
 でもこれらの技術はJavaコミュニティでもまだメジャーではない気がします。というのも、オープンソースプロジェクトでこれらを採用しているものって少ないと思うんですよね。checkstyle.xmlとかこれらのプラグインを含むpom.xmlとかあまり見たことがありません。

 I guess its reason is interface. These tools isn't easy to use and its configuration file is little hard to read.
 たぶんこの原因はツールのインタフェースなんじゃないでしょうか。ツール自体が使いにくい上に設定ファイルが読みにくいことが多いです。

 Why these configuration file should be easy to read? Because all coder for project should understand coding rule. If configuration file isn't easy to read, you have to tell rules to your team member. It's very boring and makes your code review worthless.
 設定ファイルの読みやすさはこうしたツールにとって重要だと思います。プロジェクトに関わるすべての開発者がルールを理解する必要があるからです。もし理解していない開発者がいると、いちいち口頭で教えなければならないしコードレビューも希薄なものになるでしょう。

 The ideal tool must have readable DSL to write rules. I guess Markdown is the best format because we can convert rules to PDF, HTML and wiki formats etc.
 私の理想はやはり人間に読みやすいDSLを使ってルールが書ける人間に読みやすいことです。Markdownでルール書けたら最高じゃないでしょうか?MarkdownならばPDFやHTML、wikiフォーマットへの変換も容易です。

definitions
-----------
 - DTO is class in jp.skypencil.project.dto
 - SERVICE is class which extends jp.skypencil.project.service.AbstractService

rules
-----
 - Inner classes should be static
 - Fields must be private

 - DTO must have default constructor
 - DTO must implement java.io.Serializable
 - DTO must be public
 - DTO must have #equals and #hashCode

 - Method which returns value should be annotated with javax.annotation.Nonnull or javax.annotation.Nullable

 Implementing it look easy if we can make it as a thin wrapper for existing tool. Does ANTLR3 match to implement? Or using another language is better?
 既存ツールのラッパーに徹すれば実装は難しくない気がしますが、どうなんでしょう。ANTLR3とか使えばJavaでも実装しやすいかな。別の言語でも構わないけど。