OuterTypeFilename

Since Checkstyle 5.3

Description

Checks that the outer type name and the file name match. For example, the class Foo must be in a file named Foo.java.

Examples

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 {}
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks

Parent Module

TreeWalker