diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java b/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java index c9d4713a1b7..237100e281a 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java @@ -46,7 +46,7 @@ private ModuleReflectionUtil() { } /** - * Gets checkstyle's modules (directly, not recursively) in the given packages. + * Gets checkstyle's modules classes (directly, not recursively) in the given packages. * * @param packages the collection of package names to use * @param loader the class loader used to load Checkstyle package names @@ -65,32 +65,14 @@ public static Set> getCheckstyleModules( } /** - * Checks whether a class may be considered as a checkstyle module. Checkstyle's modules are - * non-abstract classes, which are either checkstyle's checks, file sets, filters, file filters, - * {@code TreeWalker} filters, audit listener, or root module. - * - * @param clazz class to check. - * @return true if the class may be considered as the checkstyle module. - */ - public static boolean isCheckstyleModule(Class clazz) { - return isValidCheckstyleClass(clazz) - && (isCheckstyleTreeWalkerCheck(clazz) - || isFileSetModule(clazz) - || isFilterModule(clazz) - || isFileFilterModule(clazz) - || isTreeWalkerFilterModule(clazz) - || isAuditListener(clazz) - || isRootModule(clazz)); - } - - /** - * Checks whether a class extends 'AutomaticBean', is non-abstract, and has a default - * constructor. + * Checks whether a class may be considered as a checkstyle module. + * Checkstyle's modules are classes which extend 'AutomaticBean', is + * non-abstract, and has a default constructor. * * @param clazz class to check. * @return true if a class may be considered a valid production class. */ - public static boolean isValidCheckstyleClass(Class clazz) { + public static boolean isCheckstyleModule(Class clazz) { return AutomaticBean.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers()) && hasDefaultConstructor(clazz) diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java index 8bfe18c23e5..41636ec4b17 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java @@ -441,7 +441,7 @@ public void testGetShortFromFullModuleNamesThirdParty() { * to initialize private field {@code PackageObjectFactory.thirdPartyNameToFullModuleNames}. * Since the method and the field both are private, the {@link TestUtil} is required to ensure * that the field is changed. Also, the expected exception should be thrown from the static - * method {@link ModuleReflectionUtil#getCheckstyleModules}, so {@link Mockito#mockStatic} + * method {@link ModuleReflectionUtil#isCheckstyleModule}, so {@link Mockito#mockStatic} * is required to mock this exception. * * @throws Exception when the code tested throws an exception diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/ArchUnitSuperClassTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/ArchUnitSuperClassTest.java index d82494140a9..d3682089ec0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/ArchUnitSuperClassTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/ArchUnitSuperClassTest.java @@ -100,7 +100,7 @@ public void testChecksShouldHaveAllowedAbstractClassAsSuperclass() { @Override public boolean test(JavaClass input) { final Class clazz = input.reflect(); - return ModuleReflectionUtil.isValidCheckstyleClass(clazz) + return ModuleReflectionUtil.isCheckstyleModule(clazz) && (ModuleReflectionUtil.isCheckstyleTreeWalkerCheck(clazz) || ModuleReflectionUtil.isFileSetModule(clazz)); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java index ffc09f01a94..498c8cc9dbc 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/internal/ImmutabilityTest.java @@ -197,7 +197,7 @@ public class ImmutabilityTest { @Override public boolean test(JavaClass input) { final Class clazz = input.reflect(); - return ModuleReflectionUtil.isValidCheckstyleClass(clazz) + return ModuleReflectionUtil.isCheckstyleModule(clazz) && (ModuleReflectionUtil.isCheckstyleTreeWalkerCheck(clazz) || ModuleReflectionUtil.isFileSetModule(clazz)); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java index 38c4640e6d0..3ae86f06bf7 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtilTest.java @@ -78,22 +78,22 @@ public void testIsCheckstyleModule() { @Test public void testIsValidCheckstyleClass() { assertWithMessage("Should return true when valid checkstyle class is passed") - .that(ModuleReflectionUtil.isValidCheckstyleClass(ValidCheckstyleClass.class)) + .that(ModuleReflectionUtil.isCheckstyleModule(ValidCheckstyleClass.class)) .isTrue(); assertWithMessage("Should return false when invalid class is passed") .that( - ModuleReflectionUtil.isValidCheckstyleClass(InvalidNonAutomaticBeanClass.class)) + ModuleReflectionUtil.isCheckstyleModule(InvalidNonAutomaticBeanClass.class)) .isFalse(); assertWithMessage("Should return false when invalid class is passed") - .that(ModuleReflectionUtil.isValidCheckstyleClass(AbstractInvalidClass.class)) + .that(ModuleReflectionUtil.isCheckstyleModule(AbstractInvalidClass.class)) .isFalse(); assertWithMessage("Should return false when invalid class is passed") .that(ModuleReflectionUtil - .isValidCheckstyleClass(InvalidNonDefaultConstructorClass.class)) + .isCheckstyleModule(InvalidNonDefaultConstructorClass.class)) .isFalse(); assertWithMessage("Should return false when forced invalid class is passed") .that( - ModuleReflectionUtil.isValidCheckstyleClass(XpathFileGeneratorAstFilter.class)) + ModuleReflectionUtil.isCheckstyleModule(XpathFileGeneratorAstFilter.class)) .isFalse(); }