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 of class Test in a file named Test.java

public class Test { // OK

}
        

Example of class Foo in a file named Test.java

class Foo { // violation

}
        

Example of interface Foo in a file named Test.java

interface Foo { // violation

}
        

Example of enum Foo in a file named Test.java

enum Foo { // violation

}
        

Example of record Foo in a file named Test.java

record Foo { // violation

}
        

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