HexLiteralCase

Since Checkstyle 12.1.0

Description

Checks that hexadecimal literals are defined using uppercase letters (A-F) rather than lowercase (a-f). This convention follows the OpenJDK Style Guide.

Examples

To configure the check:


<module name="Checker">
  <module name="TreeWalker">
    <module name="HexLiteralCase"/>
  </module>
</module>

Example:


class Example1 {
  byte b1  = 0x1b;          // violation  'Should use uppercase hexadecimal letters.'
  byte b2  = 0x1B;

  short s1 = 0xF5f;         // violation  'Should use uppercase hexadecimal letters.'
  short s2 = 0xF5F;

  int i1 = 0x11 + 0xabc;    // violation  'Should use uppercase hexadecimal letters.'
  int i2 = 0x11 + 0xABC;
  int i3 = 0X123 + 0Xabc;   // violation  'Should use uppercase hexadecimal letters.'
  int i4 = 0X123 + 0XABC;
  int i5 = 0xdeadbeef;      // violation  'Should use uppercase hexadecimal letters.'
  int i6 = 0xDEADBEEF;

  long l1 = 0x7fff_ffff_ffff_ffffL;
  // violation above 'Should use uppercase hexadecimal letters.'
  long l2 = 0x7FFF_FFFF_FFFF_FFFFL;

  long l3 = 0x7FFF_AAA_bBB_DDDL;
  // violation above 'Should use uppercase hexadecimal letters.'
  long l4 = 0x7FFF_AAA_BBB_DDDL;

  float c = 0x1ap1f; // violation  'Should use uppercase hexadecimal letters.'
  float c2 = 0x1Ap1f;
  double e = 0x1AbC.p1d; // violation  'Should use uppercase hexadecimal letters.'
  double e2 = 0x1ABC.p1d;
  double f = 0x1AbC.P1D; // violation  'Should use uppercase hexadecimal letters.'
  double f2 = 0x1ABC.P1D;
  float g = 0x1b.p1f; // violation  'Should use uppercase hexadecimal letters.'
  float g2 = 0x1B.p1f;
  float h = 0x1b.P1F; // violation  'Should use uppercase hexadecimal letters.'
  float h2 = 0x1B.P1F;
  float i = 0x1B.p1f;
  double j = 0x1B.p1d;
  float p = 0x7f_ff_ff_ff; // violation  'Should use uppercase hexadecimal letters.'
  float p2 = 0x7F_FF_FF_FF;
  float q = 0x1.ffcp15f; // violation  'Should use uppercase hexadecimal letters.'
  float q2 = 0x1.FFCP15f;
  float r = -0x1.ffcP+15f; // violation  'Should use uppercase hexadecimal letters.'
  float r2 = -0x1.FFCP+15f;

}

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