From 0e815d234248d60f4c509fd708b62066f2f654e7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 5 Jul 2023 09:38:54 +0100 Subject: [PATCH] Polish "Use Stream.toList()" See gh-36167 --- .../boot/build/architecture/ArchitectureCheck.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java index c544f20aac..4f9217847e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.List; +import java.util.stream.Collectors; import java.util.stream.Stream; import com.tngtech.archunit.base.DescribedPredicate; @@ -74,7 +75,7 @@ public abstract class ArchitectureCheck extends DefaultTask { allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(), allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(), noClassesShouldCallStepVerifierStepVerifyComplete(), - noClassesShouldConfigureDefaultStepVerifierTimeout()) + noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList()) .map((rule) -> rule.evaluate(javaClasses)) .filter(EvaluationResult::hasViolation) .toList(); @@ -177,6 +178,13 @@ public abstract class ArchitectureCheck extends DefaultTask { .because("expectComplete().verify(Duration) should be used instead"); } + private ArchRule noClassesShouldCallCollectorsToList() { + return ArchRuleDefinition.noClasses() + .should() + .callMethod(Collectors.class, "toList") + .because("java.util.stream.Stream.toList() should be used instead"); + } + public void setClasses(FileCollection classes) { this.classes = classes; }