diff --git a/.ci/pitest-suppressions/pitest-utils-suppressions.xml b/.ci/pitest-suppressions/pitest-utils-suppressions.xml index e36e6c35d87..82c6d71ae77 100644 --- a/.ci/pitest-suppressions/pitest-utils-suppressions.xml +++ b/.ci/pitest-suppressions/pitest-utils-suppressions.xml @@ -639,69 +639,6 @@ .filter(ModuleReflectionUtil::isCheckstyleModule) - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - && (isCheckstyleTreeWalkerCheck(clazz) - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - || isAuditListener(clazz) - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - || isFileFilterModule(clazz) - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - || isFileSetModule(clazz) - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - || isFilterModule(clazz) - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF - removed conditional - replaced equality check with true - || isRootModule(clazz)); - - - - ModuleReflectionUtil.java - com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil - isCheckstyleModule - org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_ELSE - removed conditional - replaced equality check with false - || isTreeWalkerFilterModule(clazz) - - ScopeUtil.java com.puppycrawl.tools.checkstyle.utils.ScopeUtil diff --git a/config/archunit-store/slices_should_be_free_of_cycles_suppressions b/config/archunit-store/slices_should_be_free_of_cycles_suppressions index 08e79e572b6..1f8aefd7f2f 100644 --- a/config/archunit-store/slices_should_be_free_of_cycles_suppressions +++ b/config/archunit-store/slices_should_be_free_of_cycles_suppressions @@ -280,13 +280,13 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:57)\ - Static Initializer ()> references class object in (TokenUtil.java:60)\ - Method calls method in (ScopeUtil.java:73)\ + - Method references class object in (ModuleReflectionUtil.java:76)\ - Static Initializer ()> references class object in (JavadocUtil.java:79)\ - Method calls method in (BlockCommentPosition.java:85)\ - Method calls method in (BlockCommentPosition.java:88)\ - Method calls method in (ScopeUtil.java:88)\ - Method calls method in (BlockCommentPosition.java:89)\ - Method calls method in (BlockCommentPosition.java:92)\ - - Method references class object in (ModuleReflectionUtil.java:94)\ - Method calls method in (AnnotationUtil.java:95)\ - Method calls method in (CheckUtil.java:95)\ - Method calls method in (CheckUtil.java:96)\ @@ -300,6 +300,7 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:107)\ - Method calls method in (ScopeUtil.java:107)\ - Method calls method in (CheckUtil.java:108)\ + - Method references class object in (ModuleReflectionUtil.java:108)\ - Method gets field in (ScopeUtil.java:108)\ - Method calls method in (ScopeUtil.java:110)\ - Method gets field in (ScopeUtil.java:111)\ @@ -308,16 +309,17 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:118)\ - Method calls method in (JavadocUtil.java:119)\ - Method calls method in (JavadocUtil.java:119)\ + - Method references class object in (ModuleReflectionUtil.java:119)\ - Method gets field in (ScopeUtil.java:121)\ - Method calls method in (CheckUtil.java:122)\ - Method calls method in (CheckUtil.java:124)\ - - Method references class object in (ModuleReflectionUtil.java:126)\ + - Method references class object in (ModuleReflectionUtil.java:130)\ - Method calls method in (ScopeUtil.java:134)\ - Method calls method in (CheckUtil.java:135)\ - Method calls method in (ScopeUtil.java:136)\ - - Method references class object in (ModuleReflectionUtil.java:137)\ - Method calls method in (ScopeUtil.java:137)\ - Method calls method in (ScopeUtil.java:140)\ + - Method references class object in (ModuleReflectionUtil.java:141)\ - Method calls method in (AnnotationUtil.java:142)\ - Method gets field in (ScopeUtil.java:145)\ - Method calls method in (XpathUtil.java:145)\ @@ -327,13 +329,12 @@ Cycle detected: Slice api -> \ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (CheckUtil.java:148)\ - - Method references class object in (ModuleReflectionUtil.java:148)\ - Method calls method in (AnnotationUtil.java:151)\ + - Method references class object in (ModuleReflectionUtil.java:152)\ - Method calls method in (XpathUtil.java:157)\ - - Method references class object in (ModuleReflectionUtil.java:159)\ + - Method references class object in (ModuleReflectionUtil.java:163)\ - Method calls method in (XpathUtil.java:167)\ - Method calls method in (XpathUtil.java:168)\ - - Method references class object in (ModuleReflectionUtil.java:170)\ - Method calls method in (BlockCommentPosition.java:171)\ - Method calls method in (BlockCommentPosition.java:172)\ - Method calls method in (JavadocUtil.java:173)\ @@ -341,7 +342,6 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:174)\ - Method calls method in (BlockCommentPosition.java:175)\ - Method calls method in (BlockCommentPosition.java:175)\ - - Method references class object in (ModuleReflectionUtil.java:181)\ - Method calls method in (AnnotationUtil.java:185)\ - Method calls method in (JavadocUtil.java:185)\ - Method calls method in (AnnotationUtil.java:186)\ @@ -1324,13 +1324,13 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:57)\ - Static Initializer ()> references class object in (TokenUtil.java:60)\ - Method calls method in (ScopeUtil.java:73)\ + - Method references class object in (ModuleReflectionUtil.java:76)\ - Static Initializer ()> references class object in (JavadocUtil.java:79)\ - Method calls method in (BlockCommentPosition.java:85)\ - Method calls method in (BlockCommentPosition.java:88)\ - Method calls method in (ScopeUtil.java:88)\ - Method calls method in (BlockCommentPosition.java:89)\ - Method calls method in (BlockCommentPosition.java:92)\ - - Method references class object in (ModuleReflectionUtil.java:94)\ - Method calls method in (AnnotationUtil.java:95)\ - Method calls method in (CheckUtil.java:95)\ - Method calls method in (CheckUtil.java:96)\ @@ -1344,6 +1344,7 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:107)\ - Method calls method in (ScopeUtil.java:107)\ - Method calls method in (CheckUtil.java:108)\ + - Method references class object in (ModuleReflectionUtil.java:108)\ - Method gets field in (ScopeUtil.java:108)\ - Method calls method in (ScopeUtil.java:110)\ - Method gets field in (ScopeUtil.java:111)\ @@ -1352,16 +1353,17 @@ Cycle detected: Slice api -> \ - Method gets field in (ScopeUtil.java:118)\ - Method calls method in (JavadocUtil.java:119)\ - Method calls method in (JavadocUtil.java:119)\ + - Method references class object in (ModuleReflectionUtil.java:119)\ - Method gets field in (ScopeUtil.java:121)\ - Method calls method in (CheckUtil.java:122)\ - Method calls method in (CheckUtil.java:124)\ - - Method references class object in (ModuleReflectionUtil.java:126)\ + - Method references class object in (ModuleReflectionUtil.java:130)\ - Method calls method in (ScopeUtil.java:134)\ - Method calls method in (CheckUtil.java:135)\ - Method calls method in (ScopeUtil.java:136)\ - - Method references class object in (ModuleReflectionUtil.java:137)\ - Method calls method in (ScopeUtil.java:137)\ - Method calls method in (ScopeUtil.java:140)\ + - Method references class object in (ModuleReflectionUtil.java:141)\ - Method calls method in (AnnotationUtil.java:142)\ - Method gets field in (ScopeUtil.java:145)\ - Method calls method in (XpathUtil.java:145)\ @@ -1371,13 +1373,12 @@ Cycle detected: Slice api -> \ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (AnnotationUtil.java:148)\ - Method calls method in (CheckUtil.java:148)\ - - Method references class object in (ModuleReflectionUtil.java:148)\ - Method calls method in (AnnotationUtil.java:151)\ + - Method references class object in (ModuleReflectionUtil.java:152)\ - Method calls method in (XpathUtil.java:157)\ - - Method references class object in (ModuleReflectionUtil.java:159)\ + - Method references class object in (ModuleReflectionUtil.java:163)\ - Method calls method in (XpathUtil.java:167)\ - Method calls method in (XpathUtil.java:168)\ - - Method references class object in (ModuleReflectionUtil.java:170)\ - Method calls method in (BlockCommentPosition.java:171)\ - Method calls method in (BlockCommentPosition.java:172)\ - Method calls method in (JavadocUtil.java:173)\ @@ -1385,7 +1386,6 @@ Cycle detected: Slice api -> \ - Method calls method in (JavadocUtil.java:174)\ - Method calls method in (BlockCommentPosition.java:175)\ - Method calls method in (BlockCommentPosition.java:175)\ - - Method references class object in (ModuleReflectionUtil.java:181)\ - Method calls method in (AnnotationUtil.java:185)\ - Method calls method in (JavadocUtil.java:185)\ - Method calls method in (AnnotationUtil.java:186)\ 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(); }