Since Checkstyle 5.0
name | description | type | default value | since |
---|---|---|---|---|
format | Sets the pattern to match valid identifiers. | Pattern | "^[A-Z]$" |
5.0 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="ClassTypeParameterName"/> </module> </module>
Example:
class Example1 { class MyClass1<T> {} class MyClass2<t> {} // violation class MyClass3<abc> {} // violation class MyClass4<LISTENER> {} // violation class MyClass5<RequestT> {} // violation }
To configure the check for names that are uppercase word:
<module name="Checker"> <module name="TreeWalker"> <module name="ClassTypeParameterName"> <property name="format" value="^[A-Z]{2,}$"/> </module> </module> </module>
Example:
class Example2 { class MyClass1<T> {} // violation class MyClass2<t> {} // violation class MyClass3<abc> {} // violation class MyClass4<LISTENER> {} class MyClass5<RequestT> {} // violation }
To configure the check for names that are camel case word with T as suffix (Google Style):
<module name="Checker"> <module name="TreeWalker"> <module name="ClassTypeParameterName"> <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/> </module> </module> </module>
Example:
class Example3 { class MyClass1<T> {} class MyClass2<t> {} // violation class MyClass3<abc> {} // violation class MyClass4<LISTENER> {} // violation class MyClass5<RequestT> {} }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.naming