From 6398e0aa244cf1c0feda9c166e096a108e20e0a9 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:10:19 +0100 Subject: [PATCH] Add Checkstyle rule to enforce use of class literals for primitives & void This commit introduces Checkstyle rules for `main` and `test` which enforce the use of class literals for primitive types and void by forbidding the use of the TYPE constants in Boolean, Character, Byte, Short, Integer, Long, Float, Double, and Void. For example, if MyClass uses one of the TYPE constants, the build will now fail with a message similar to the following. [ERROR] <...>/MyClass.java:39: Please use class literals for primitives and void -- for example, int.class instead of Integer.TYPE. --- gradle/config/checkstyle/checkstyleMain.xml | 7 +++++++ gradle/config/checkstyle/checkstyleTest.xml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/gradle/config/checkstyle/checkstyleMain.xml b/gradle/config/checkstyle/checkstyleMain.xml index 447d02df9c62..27ff53749020 100644 --- a/gradle/config/checkstyle/checkstyleMain.xml +++ b/gradle/config/checkstyle/checkstyleMain.xml @@ -20,6 +20,13 @@ + + + + + + + diff --git a/gradle/config/checkstyle/checkstyleTest.xml b/gradle/config/checkstyle/checkstyleTest.xml index 6ac9b5d89eb5..b795207938ad 100644 --- a/gradle/config/checkstyle/checkstyleTest.xml +++ b/gradle/config/checkstyle/checkstyleTest.xml @@ -12,6 +12,13 @@ + + + + + + +