diff --git a/.ci/pitest-suppressions/pitest-utils-suppressions.xml b/.ci/pitest-suppressions/pitest-utils-suppressions.xml index e36e6c35d87..3063ed3f770 100644 --- a/.ci/pitest-suppressions/pitest-utils-suppressions.xml +++ b/.ci/pitest-suppressions/pitest-utils-suppressions.xml @@ -636,7 +636,7 @@ getCheckstyleModules org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator replaced call to java/util/stream/Stream::filter with receiver - .filter(ModuleReflectionUtil::isCheckstyleModule) + .filter(ModuleReflectionUtil::isValidCheckstyleClass) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java b/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java index bec9669bf3f..5da711a217b 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/PackageObjectFactory.java @@ -303,7 +303,7 @@ Definitions.CHECKSTYLE_BUNDLE, getClass(), private Map> generateThirdPartyNameToFullModuleName(ClassLoader loader) { Map> returnValue; try { - returnValue = ModuleReflectionUtil.getCheckstyleModules(packages, loader).stream() + returnValue = ModuleReflectionUtil.getValidCheckstyleClasses(packages, loader).stream() .collect(Collectors.groupingBy(Class::getSimpleName, Collectors.mapping(Class::getCanonicalName, Collectors.toSet()))); } 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..882ee49589d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/utils/ModuleReflectionUtil.java @@ -46,21 +46,21 @@ private ModuleReflectionUtil() { } /** - * Gets checkstyle's modules (directly, not recursively) in the given packages. + * Gets valid checkstyle's 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 - * @return the set of checkstyle's module classes + * @return the set of checkstyle's classes * @throws IOException if the attempt to read class path resources failed * @see #isCheckstyleModule(Class) */ - public static Set> getCheckstyleModules( + public static Set> getValidCheckstyleClasses( Collection packages, ClassLoader loader) throws IOException { final ClassPath classPath = ClassPath.from(loader); return packages.stream() .flatMap(pkg -> classPath.getTopLevelClasses(pkg).stream()) .map(ClassPath.ClassInfo::load) - .filter(ModuleReflectionUtil::isCheckstyleModule) + .filter(ModuleReflectionUtil::isValidCheckstyleClass) .collect(Collectors.toSet()); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/PackageObjectFactoryTest.java index 8bfe18c23e5..da8024206e0 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#getValidCheckstyleClasses}, so {@link Mockito#mockStatic} * is required to mock this exception. * * @throws Exception when the code tested throws an exception @@ -457,8 +457,9 @@ public void testGenerateThirdPartyNameToFullModuleNameWithException() throws Exc try (MockedStatic utilities = mockStatic(ModuleReflectionUtil.class)) { - utilities.when(() -> ModuleReflectionUtil.getCheckstyleModules(packages, classLoader)) - .thenThrow(new IOException("mock exception")); + utilities.when(() -> { + ModuleReflectionUtil.getValidCheckstyleClasses(packages, classLoader); + }).thenThrow(new IOException("mock exception")); final String internalFieldName = "thirdPartyNameToFullModuleNames"; final Map nullMap = TestUtil.getInternalState(objectFactory,