Since Checkstyle 5.3
Foo
must be in a file named
Foo.java
.
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="OuterTypeFilename"/> </module> </module>
Example file content with name of file Example1.java
public class Example1 {}
Example file content with name of file Example2.java
// violation below 'The name of the outer type and the file do not match.' class Example2ButNotSameName {}
Example file content with name of file Example3.java
// violation below 'The name of the outer type and the file do not match.' interface Example3ButNotSameName {}
Example file content with name of file Example4.java
// violation below 'The name of the outer type and the file do not match.' enum Example4ButNotSameName {}
Example file content with name of file Example5.java
// violation below 'The name of the outer type and the file do not match.' class Example5ButNotSameName {}
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks