ClassHeaderWrapOpenjdk
Since Checkstyle 14.4.0
Description
This check only applies when the type declaration header, from the declaration keyword through the end of its extends/implements clauses (or its name/type parameters/record components when neither clause is present), spans more than one line. A header whose content is entirely on one line is not in scope, even if its opening curly brace is pushed onto its own following line; that is a brace placement choice for other checks (such as LeftCurly) to enforce, not a wrapping concern this check is about.
The two rules enforced are:
- Each of the
extendsandimplementsclauses, when present, must stand out on its own new line once the header has started wrapping, or once that clause's own list of supertypes wraps across lines. Wrapping that happens only inside a single supertype's type arguments (the same way method arguments may wrap) does not require the clause keyword itself to move to a new line. - Only checked when rule 1 above found nothing to report: the header should not have been wrapped in the first place if, joined back onto one line, it would still fit within 80 columns.
Examples
To configure the check to follow openjdk guidelines for class header wrapping:
<module name="Checker">
<module name="TreeWalker">
<module name="ClassHeaderWrapOpenjdk"/>
</module>
</module>
Example:
public class Example1 {
abstract static class ValidGenericContainer<T, S>
extends HashMap<T, S>
implements Comparable<T> {
}
abstract static class InvalidGenericContainer<T, S>
extends HashMap<T, S> implements Comparable<T> {
// violation above """The 'implements' clause should be on a new line when
// the class header is wrapped."""
}
static class UnnecessaryWrap
extends Object {
// violation 2 lines above """The class header should not be wrapped as it
// fits within the maximum column limit of 80."""
}
}
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.indentation.ClassHeaderWrapOpenjdkCheck
Use this fully qualified class name in configuration when an exact class reference is required.






