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

Use Cases

The following use cases use the configuration above.

In UseCase1.java, the interface UseCase1ButNotSameName causes a violation because its name does not match the file name.


// violation below 'The name of the outer type and the file do not match.'
interface UseCase1ButNotSameName {}

In UseCase2.java, the enum UseCase2ButNotSameName causes a violation because its name does not match the file name.


// violation below 'The name of the outer type and the file do not match.'
enum UseCase2ButNotSameName {}

In UseCase3.java, the class UseCase3ButNotSameName causes a violation because its name does not match the file name.


// violation below 'The name of the outer type and the file do not match.'
class UseCase3ButNotSameName {}

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.

Fully Qualified Name

com.puppycrawl.tools.checkstyle.checks.OuterTypeFilenameCheck

Use this fully qualified class name in configuration when an exact class reference is required.

Parent Module

TreeWalker