Skip to content

Commit

Permalink
(Sonar) Fixed finding: "Stream.toList() should be used instead of `…
Browse files Browse the repository at this point in the history
…collectors`"
  • Loading branch information
pixeebot-test[bot] authored Jul 21, 2024
1 parent 6670a3d commit 422ab0d
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private List<CodemodChange> processWebXml(final CodemodInvocationContext context

// add the weaves to the context
List<CodemodChange> changes =
linesAffected.stream().map(CodemodChange::from).collect(Collectors.toList());
linesAffected.stream().map(CodemodChange::from).toList();

// overwrite the previous web.xml with the new one
Files.copy(xmlChange.transformedXml(), file, StandardCopyOption.REPLACE_EXISTING);
Expand Down Expand Up @@ -109,6 +109,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC
public List<CodeTFReference> getReferences() {
return reporter.getReferences().stream()
.map(u -> new CodeTFReference(u, u))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public Integer call() throws IOException {
String.join(" ", args),
sarifs == null
? List.of()
: sarifs.stream().map(Path::of).collect(Collectors.toList()),
: sarifs.stream().map(Path::of).toList(),
results,
elapsed);
ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static CodemodReporterStrategy getCodemodReporterStrategy(
List<String> references =
StreamSupport.stream(referencesNode.spliterator(), false)
.map(JsonNode::asText)
.collect(Collectors.toList());
.toList();

return new CodemodReporterStrategy() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private FilesUpdateResult updateFiles(
.map(CodemodChange::getDependenciesNeeded)
.flatMap(Collection::stream)
.distinct()
.collect(Collectors.toList());
.toList();

List<CodeTFPackageAction> pkgActions;
List<CodeTFChangesetEntry> dependencyChangesetEntries = Collections.emptyList();
Expand All @@ -253,7 +253,7 @@ private FilesUpdateResult updateFiles(
.map(
change ->
translateCodemodChangetoCodeTFChange(codeChanger, filePath, change, pkgActions))
.collect(Collectors.toList());
.toList();

// make sure we add the file's entry first, then the dependency entries, so the causality
// is clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Optional<XPathStreamProcessChange> process(
DocumentHelper.selectNodes(xpathExpression, doc).stream()
.map(node -> (LocationAwareElement) node)
.map(element -> new Position(element.getLine(), element.getColumn()))
.collect(Collectors.toUnmodifiableList());
.toList();

if (httpMethodPositions.isEmpty()) {
return Optional.empty();
Expand Down Expand Up @@ -97,7 +97,7 @@ public Optional<XPathStreamProcessChange> process(
// remove the empty leftover lines affected by our changes if there are any
Set<Integer> linesAffected =
httpMethodPositions.stream().map(pos -> pos.line()).collect(Collectors.toUnmodifiableSet());
List<String> lines = transformedXml.lines().collect(Collectors.toUnmodifiableList());
List<String> lines = transformedXml.lines().toList();
List<String> updatedLines = new ArrayList<>(lines.size() - linesAffected.size());
for (int i = 1; i <= lines.size(); i++) {
String actualLine = lines.get(i - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void configure() {
this.injectableParameters.stream()
.filter(param -> param.isAnnotationPresent(CodemodParameter.class))
.filter(param -> param.getType().equals(Parameter.class))
.collect(Collectors.toUnmodifiableList());
.toList();

for (java.lang.reflect.Parameter param : codemodParameters) {
CodemodParameter codemodParameter = param.getAnnotation(CodemodParameter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC
public List<CodeTFReference> getReferences() {
return reporter.getReferences().stream()
.map(u -> new CodeTFReference(u, u))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC
public List<CodeTFReference> getReferences() {
return reporter.getReferences().stream()
.map(u -> new CodeTFReference(u, u))
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static Optional<VersionQueryResponse> queryVersions(ProjectModel projectModel)
if (queryVersionResult.size() == 1) {
List<VersionDefinition> queryVersionResultList =
queryVersionResult != null && !queryVersionResult.isEmpty()
? queryVersionResult.stream().collect(Collectors.toList())
? queryVersionResult.stream().toList()
: Collections.emptyList();
Version mappedVersion = mapVersion(queryVersionResultList.get(0).getValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ProjectModelFactory withPomFile(POMDocument pomFile) {
public ProjectModelFactory withParentPomFiles(Collection<POMDocument> parentPomFiles) {
this.parentPomFiles =
new ArrayList<>(
parentPomFiles.stream().filter(Objects::nonNull).collect(Collectors.toList()));
parentPomFiles.stream().filter(Objects::nonNull).toList());
return this;
}

Expand Down

0 comments on commit 422ab0d

Please sign in to comment.