Learning Resources for Software Engineering Students »
Author: Xiao Pu
CheckStyle is a static analyser for Java. It can be used to assist developers in static analysis process.
CheckStyle will examine code based on different rules(or checks).
According to the checks list provided by CheckStyle, the checks(rules) can be divided into 14 sections.
- Block Checks
- Class Design
- Javadoc Comments
- Naming Conventions
- Size Violations
As described here, there are several limitations in CheckStyle.
- The code must be written in ASCII characters only.
- The examined code has to be compilable. The reason is described in How does it work section.
- Files will be examined one by one, which means you cannot check multiple files at the same time.
- For example, you cannot determine the full inheritance hierarchy of a class as you need to examine the parent class while checking the child class.
How to use it
CheckStyle uses a configuration file to know all the rules that it is supposed to check.
CheckStyle supports suppressing warnings in four ways:
There are several ways to run CheckStyle.
Build Automation Tools:
There are two widely used configurations: Sun Code Conversions and Google Java Style. Some common rules are already included in these configurations.
How does it work
CheckStyle will use ANTLR to parse your code into a AST(Abstract Syntax Tree) and visit it in a DFS(Depth First Search) pattern to check violations. Thus, it is necessary to make the code compilable in order for the ANTLR to work. You can view the syntax tree using CheckStyle Grammar Tree Viewer
- CheckStyle: CheckStyle official website. You can download the latest version, view online documentation there.
- CheckStyle Github: CheckStyle GitHub page. You can contribute to the project or report bugs there.
- StackOverflow CheckStyle: Question/Answer forum in StackOverflow for CheckStyle. You can ask question related to the using of CheckStyle.