ClassTypeParameterName

Since Checkstyle 5.0

Description

Checks that class type parameter names conform to a specified pattern.

Properties

name description type default value since
format Sets the pattern to match valid identifiers. Pattern "^[A-Z]$" 5.0

Examples

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

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.naming

Parent Module

TreeWalker