Skip to content

Commit

Permalink
Merge pull request ballerina-platform#42894 from Shadow-Devil/use-str…
Browse files Browse the repository at this point in the history
…eam-tolist

Replace `collect(Collectors.toList())` with `toList()`
  • Loading branch information
hasithaa authored Jun 11, 2024
2 parents 969823f + 4f6d8fc commit 1cadb9e
Show file tree
Hide file tree
Showing 95 changed files with 150 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Invoker that invokes a command to evaluate a list of snippets.
Expand Down Expand Up @@ -391,8 +390,8 @@ protected void executeProject(JBallerinaBackend jBallerinaBackend) throws Invoke
List<String> stacktrace = Arrays.stream(panicError.getCause().getStackTrace())
.filter(element -> !(element.toString().contains(MODULE_STATEMENT_METHOD_NAME) ||
element.toString().contains(MODULE_RUN_METHOD_NAME)))
.collect(Collectors.toList())
.stream().map(element -> "at " + element.getMethodName() + "()").collect(Collectors.toList());
.toList()
.stream().map(element -> "at " + element.getMethodName() + "()").toList();
errorStream.println("panic: " + StringUtils.getErrorStringValue(panicError.getCause()));
stacktrace.forEach(errorStream::println);
addErrorDiagnostic("Execution aborted due to unhandled runtime error.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static io.ballerina.runtime.api.PredefinedTypes.TYPE_ANY;
import static io.ballerina.runtime.api.PredefinedTypes.TYPE_ANYDATA;
Expand Down Expand Up @@ -1013,7 +1012,7 @@ static BField getTableConstraintField(Type constraintType, String fieldName) {
BUnionType unionType = (BUnionType) constraintType;
List<Type> memTypes = unionType.getMemberTypes();
List<BField> fields = memTypes.stream().map(type -> getTableConstraintField(type, fieldName))
.filter(Objects::nonNull).collect(Collectors.toList());
.filter(Objects::nonNull).toList();

if (fields.size() != memTypes.size()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.stream.Collectors;

/**
* Registry for keeping metrics by name.
Expand Down Expand Up @@ -191,7 +190,7 @@ private <M extends Metric> void unregister(Metric registerMetric, Class<M> metri
*/
public void remove(String name) {
List<MetricId> ids = metrics.keySet().stream()
.filter(id -> id.getName().equals(name)).collect(Collectors.toList());
.filter(id -> id.getName().equals(name)).toList();
ids.forEach(metrics::remove);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static void addModules(Path balaPath, Path projectPath, String packageNa
Path moduleMdDirRoot = balaPath.resolve("docs").resolve(ProjectConstants.MODULES_ROOT);
List<Path> modulesList;
try (Stream<Path> pathStream = Files.list(modulesRoot)) {
modulesList = pathStream.collect(Collectors.toList());
modulesList = pathStream.toList();
}
for (Path moduleRoot : modulesList) {
Path moduleDir = Optional.of(moduleRoot.getFileName()).get();
Expand Down Expand Up @@ -326,7 +326,7 @@ private static void copyIcon(Path balaPath, Path projectPath) {
try (Stream<Path> pathStream = Files.walk(docsPath, 1)) {
List<Path> icon = pathStream
.filter(FileSystems.getDefault().getPathMatcher("glob:**.png")::matches)
.collect(Collectors.toList());
.toList();
if (!icon.isEmpty()) {
Path projectDocsDir = projectPath.resolve(ProjectConstants.BALA_DOCS_DIR);
Files.createDirectory(projectDocsDir);
Expand Down Expand Up @@ -485,7 +485,7 @@ public static void writeBallerinaToml(Path balTomlPath, PackageJson packageJson,
Files.writeString(balTomlPath, "\nversion = \"" + packageJson.getVersion() + "\"",
StandardOpenOption.APPEND);
List<String> newModuleNames = packageJson.getExport().stream().map(module ->
module.replaceFirst(packageJson.getName(), packageName)).collect(Collectors.toList());
module.replaceFirst(packageJson.getName(), packageName)).toList();

StringJoiner stringJoiner = new StringJoiner(",");
for (String newModuleName : newModuleNames) {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public static List<PackageVersion> getPackageVersions(Path balaPackagePath) {
} catch (IOException e) {
throw new RuntimeException("Error while accessing Distribution cache: " + e.getMessage());
}
versions.addAll(collectVersions.collect(Collectors.toList()));
versions.addAll(collectVersions.toList());
}
return pathToVersions(versions);
}
Expand Down Expand Up @@ -1091,7 +1091,7 @@ public static String checkTemplateFilesExists(String template, Path packagePath)
IOException {
Path templateDir = getTemplatePath().resolve(template);
Stream<Path> paths = Files.list(templateDir);
List<Path> templateFilePathList = paths.collect(Collectors.toList());
List<Path> templateFilePathList = paths.toList();
StringBuilder existingFiles = new StringBuilder();
for (Path path : templateFilePathList) {
Optional<String> fileNameOptional = Optional.ofNullable(path.getFileName()).map(path1 -> path1.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.ballerinalang.central.client.CentralClientConstants.APPLICATION_JSON;
import static org.ballerinalang.central.client.CentralClientConstants.BALLERINA_DEV_CENTRAL;
Expand Down Expand Up @@ -457,7 +456,7 @@ private static void extractBala(Path balaFilePath, Path balaFileDestPath, String

try (FileSystem zipFileSystem = FileSystems.newFileSystem(zipURI, new HashMap<>())) {
Path packageRoot = zipFileSystem.getPath("/");
List<Path> paths = Files.walk(packageRoot).filter(path -> path != packageRoot).collect(Collectors.toList());
List<Path> paths = Files.walk(packageRoot).filter(path -> path != packageRoot).toList();
for (Path path : paths) {
Path destPath = balaFileDestPath.resolve(packageRoot.relativize(path).toString());
// Handle overwriting existing bala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ public Optional<TypeSymbol> transform(ClientResourceAccessActionNode clientResou
//`params` contains path params and path rest params as well. We need to skip those
List<BVarSymbol> params = symbol.params.stream().filter(param ->
param.getKind() != SymbolKind.PATH_PARAMETER
&& param.getKind() != SymbolKind.PATH_REST_PARAMETER).collect(Collectors.toList());
&& param.getKind() != SymbolKind.PATH_REST_PARAMETER).toList();
BVarSymbol restPram = ((BInvokableSymbol) bLangInvocation.symbol).restParam;
TypeSymbol restParamMemberType = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* A util class for creating type param resolved version of the lang lib functions.
Expand Down Expand Up @@ -126,7 +125,7 @@ private BInvokableType duplicateType(BInvokableType original, List<BVarSymbol> n

List<BType> paramTypes = new ArrayList<>();
if (newParams.size() == original.paramTypes.size()) {
paramTypes.addAll(newParams.stream().map(BSymbol::getType).collect(Collectors.toList()));
paramTypes.addAll(newParams.stream().map(BSymbol::getType).toList());
} else {
paramTypes.addAll(original.paramTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.ballerinalang.model.symbols.SymbolOrigin.BUILTIN;
import static org.ballerinalang.model.symbols.SymbolOrigin.COMPILED_SOURCE;
Expand Down Expand Up @@ -136,7 +135,7 @@ public List<TypeDefinitionSymbol> typeDefinitions() {
this.typeDefs = this.allSymbols().stream()
.filter(symbol -> symbol.kind() == SymbolKind.TYPE_DEFINITION)
.map(symbol -> (TypeDefinitionSymbol) symbol)
.collect(Collectors.toUnmodifiableList());
.toList();
}

return this.typeDefs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.stream.Collectors;

/**
* Represents an implementation of a path segment list.
Expand Down Expand Up @@ -69,7 +68,7 @@ public List<PathParameterSymbol> pathParameters() {
List<PathParameterSymbol> pathParams = new ArrayList<>();

int internalPathParamCount = 0;
List<Name> segments = this.internalPathSegmentSymbols.stream().map(s -> s.name).collect(Collectors.toList());
List<Name> segments = this.internalPathSegmentSymbols.stream().map(s -> s.name).toList();
for (int i = 0; i < segments.size(); i++) {
Name internalSegment = segments.get(i);
BResourcePathSegmentSymbol pathSegSymbol = this.internalPathSegmentSymbols.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ private void sortAndCopyJars(Collection<JarLibrary> jarLibraries, ZipArchiveOutp

List<JarLibrary> sortedJarLibraries = jarLibraries.stream()
.sorted(Comparator.comparing(jarLibrary -> jarLibrary.path().getFileName()))
.collect(Collectors.toList());
.toList();

// Copy all the jars
for (JarLibrary library : sortedJarLibraries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Responsible for creating the dependency graph with automatic version updates.
Expand Down Expand Up @@ -163,7 +162,7 @@ private Collection<DependencyNode> resolvePackages(Collection<ModuleLoadRequest>

private void populateStaticDependencyGraph(Collection<DependencyNode> directDependencies) {
List<DependencyNode> errorNodes = directDependencies.stream()
.filter(DependencyNode::errorNode).collect(Collectors.toList());
.filter(DependencyNode::errorNode).toList();
for (DependencyNode errorNode : errorNodes) {
graphBuilder.addErroneousDependency(
rootPkgDesc, errorNode.pkgDesc, errorNode.scope, errorNode.resolutionType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.ballerina.compiler.syntax.tree.TransactionalExpressionNode;

import java.util.List;
import java.util.stream.Collectors;

/**
* This class will check whether an import statement to internal transaction repo is needed or not.
Expand Down Expand Up @@ -72,7 +71,7 @@ public void visit(RetryStatementNode retryStatementNode) {
@Override
public void visit(FunctionDefinitionNode functionDefinitionNode) {
List<String> qualifiers = functionDefinitionNode.qualifierList().stream().map(Token::text)
.collect(Collectors.toList());
.toList();
if (qualifiers.contains(SyntaxKind.TRANSACTIONAL_KEYWORD.stringValue()) &&
qualifiers.contains(SyntaxKind.RESOURCE_KEYWORD.stringValue())) {
importTransactionPackage = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ private ImportModuleResponse getImportModuleLoadResponse(ImportModuleRequest imp
// If the module is not found in the possible packages locked in the Dependencies.toml
// we continue looking for the module in the remaining possible packages.
List<PackageName> existing = importModuleRequest.possiblePackages().stream().map(PackageDescriptor::name)
.collect(Collectors.toList());
.toList();
List<PackageName> remainingPackageNames = ProjectUtils.getPossiblePackageNames(
importModuleRequest.packageOrg(), importModuleRequest.moduleName()).stream()
.filter(o -> !existing.contains(o)).collect(Collectors.toList());
.filter(o -> !existing.contains(o)).toList();

for (PackageName possiblePackageName : remainingPackageNames) {
List<PackageVersion> packageVersions = getPackageVersions(importModuleRequest.packageOrg(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static io.ballerina.projects.util.ProjectConstants.BALLERINA_TOML;
Expand Down Expand Up @@ -170,7 +169,7 @@ public static void deletePath(Path path) throws IOException {
}

if (Files.isDirectory(path)) {
for (Path dir : Files.list(path).collect(Collectors.toList())) {
for (Path dir : Files.list(path).toList()) {
deletePath(dir);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public List<String> getEntryNames() {
try {
List<Path> files = Files.walk(this.pkgPath, 1).filter(
Files::isRegularFile).filter(e -> e.getFileName().toString().endsWith(BAL_SOURCE_EXT)).
collect(Collectors.toList());
toList();
this.cachedEntryNames = new ArrayList<>(files.size());
files.stream().forEach(e -> this.cachedEntryNames.add(e.getFileName().toString()));
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getTargetPlatform(String moduleName) {
List<Library> deps = platform.libraries.stream().filter(library -> {
return library.getModules() == null ||
Arrays.stream(library.getModules()).anyMatch(moduleName::equals);
}).collect(Collectors.toList());
}).toList();
// If not return any
if (!deps.isEmpty()) {
return platform.target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static org.wso2.ballerinalang.compiler.bir.writer.BIRWriterUtils.writeConstValue;

Expand Down Expand Up @@ -132,7 +131,7 @@ private void writeTypeDefs(ByteBuf buf, BIRTypeWriter typeWriter,
private void writeTypeDefBodies(ByteBuf buf, BIRTypeWriter typeWriter,
List<BIRTypeDefinition> birTypeDefList) {
List<BIRTypeDefinition> filtered = birTypeDefList.stream().filter(t -> t.type.tag == TypeTags.OBJECT
|| t.type.tag == TypeTags.RECORD).collect(Collectors.toList());
|| t.type.tag == TypeTags.RECORD).toList();
buf.writeInt(filtered.size());
filtered.forEach(typeDef -> {
writeFunctions(buf, typeWriter, typeDef.attachedFuncs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7015,7 +7015,7 @@ private BLangInvocation createInvocationForPathParams(
if (pathSegmentCount > 0 && lastPathSegmentSym.kind != SymbolKind.RESOURCE_ROOT_PATH_SEGMENT) {
invocationParams.addAll(pathSegmentSymbols.subList(0, pathSegmentCount).stream()
.map(s -> new BVarSymbol(0, Names.EMPTY, this.env.scope.owner.pkgID, s.type,
this.env.scope.owner, s.pos, VIRTUAL)).collect(Collectors.toList()));
this.env.scope.owner, s.pos, VIRTUAL)).toList());
}

invokableSymbol.params = invocationParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -89,7 +88,7 @@ public Stream<Path> getLatestVersion(Path path, PackageID packageID) {
.sorted(Comparator.reverseOrder())
.limit(1)
.map(SortablePath::getPath)
.collect(Collectors.toList());
.toList();
}
if (packageID != null) {
if (packageID.version.value.isEmpty() && !packageID.orgName.equals(Names.BUILTIN_ORG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipError;

Expand Down Expand Up @@ -114,7 +113,7 @@ public Stream<Path> getLatestVersion(Path path, PackageID packageID) {
.sorted(Comparator.reverseOrder())
.limit(1)
.map(SortablePath::getPath)
.collect(Collectors.toList());
.toList();
}
if (packageID.version.value.isEmpty() && !packageID.orgName.equals(Names.BUILTIN_ORG)
&& !packageID.orgName.equals(Names.ANON_ORG) && !pathList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ private List<BLangExpression> getVarRefs(BLangErrorVarRef varRef) {
if (varRef.cause != null) {
varRefs.add(varRef.cause);
}
varRefs.addAll(varRef.detail.stream().map(e -> e.expr).collect(Collectors.toList()));
varRefs.addAll(varRef.detail.stream().map(e -> e.expr).toList());
if (varRef.restVar != null) {
varRefs.add(varRef.restVar);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ private List<BLangExpression> getVarRefs(BLangErrorVarRef varRef) {
if (varRef.cause != null) {
varRefs.add(varRef.cause);
}
varRefs.addAll(varRef.detail.stream().map(e -> e.expr).collect(Collectors.toList()));
varRefs.addAll(varRef.detail.stream().map(e -> e.expr).toList());
varRefs.add(varRef.restVar);
return varRefs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ public void visit(BLangErrorVariable varNode, AnalyzerData data) {
List<BErrorType> errorMembers = members.stream()
.filter(m -> Types.getImpliedType(m).tag == TypeTags.ERROR)
.map(m -> (BErrorType) Types.getImpliedType(m))
.collect(Collectors.toList());
.toList();

if (errorMembers.isEmpty()) {
dlog.error(varNode.pos, DiagnosticErrorCode.INVALID_ERROR_MATCH_PATTERN);
Expand Down Expand Up @@ -2470,7 +2470,7 @@ private void checkRecordVarRefEquivalency(Location pos, BLangRecordVarRef lhsVar
for (BField rhsField : rhsRecordType.fields.values()) {
List<BLangRecordVarRefKeyValue> expField = lhsVarRef.recordRefFields.stream()
.filter(field -> field.variableName.value.equals(rhsField.name.toString()))
.collect(Collectors.toList());
.toList();

if (expField.isEmpty()) {
continue;
Expand Down
Loading

0 comments on commit 1cadb9e

Please sign in to comment.