OuterTypeNumber
Since Checkstyle 5.0
Description
Checks for the number of types declared at the outer (or root) level in a file.
Rationale: It is considered good practice to only define one outer type per file.
Properties
Examples
To configure the check to accept 1 outer type per file:
<module name="Checker">
<module name="TreeWalker">
<module name="OuterTypeNumber"/>
</module>
</module>
Example:
package com.puppycrawl.tools.checkstyle.checks.sizes.outertypenumber;
// violation above 'Outer types defined is 2 (max allowed is 1)'
public class Example1 {
enum outer {
}
}
class ExampleOne {
void exampleMethod() {}
}
To configure the check to accept 2 outer types per file:
<module name="Checker">
<module name="TreeWalker">
<module name="OuterTypeNumber">
<property name="max" value="3"/>
</module>
</module>
</module>
Example:
package com.puppycrawl.tools.checkstyle.checks.sizes.outertypenumber;
public class Example2 {
enum outer {
}
}
class ExampleTwo {
void exampleMethod() {}
}
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.sizes.OuterTypeNumberCheck
Use this fully qualified class name in configuration when an exact class reference is required.






