Skip to content

Commit 9d4ae8a

Browse files
SONARPY-1745 Update remaining usages of Collectors.toList() to toList() (#1755)
1 parent ffb57ca commit 9d4ae8a

File tree

79 files changed

+149
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+149
-150
lines changed

its/plugin/it-python-plugin-test/src/test/java/com/sonar/python/it/plugin/RuffReportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void import_report() {
4949
.setProjectDir(new File("projects/ruff_project")));
5050

5151
List<Issues.Issue> issues = issues(PROJECT).stream().sorted(Comparator.comparing(Issues.Issue::getRule))
52-
.collect(Collectors.toList());
52+
.toList();
5353
assertThat(issues).hasSize(2);
5454

5555
Issues.Issue firstIssue = issues.get(0);

python-checks/src/main/java/org/sonar/python/checks/ConsistentReturnCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void initialize(Context context) {
5454

5555
List<Tree> returnsWithValue = endStatements.stream()
5656
.filter(s -> s.is(Kind.RETURN_STMT) && hasValue((ReturnStatement) s))
57-
.collect(Collectors.toList());
57+
.toList();
5858

5959
if (returnsWithValue.size() != endStatements.size() && !returnsWithValue.isEmpty()) {
6060
addIssue(ctx, functionDef, endStatements);
@@ -64,7 +64,7 @@ public void initialize(Context context) {
6464

6565
private static boolean hasExceptOrFinally(ControlFlowGraph cfg) {
6666
return cfg.blocks().stream().anyMatch(block ->
67-
block instanceof CfgBranchingBlock && ((CfgBranchingBlock) block).branchingTree().is(Kind.EXCEPT_CLAUSE, Kind.FINALLY_CLAUSE));
67+
block instanceof CfgBranchingBlock cfgBranchingBlock && cfgBranchingBlock.branchingTree().is(Kind.EXCEPT_CLAUSE, Kind.FINALLY_CLAUSE));
6868
}
6969

7070
private static boolean isWhileTrue(Statement statement) {

python-checks/src/main/java/org/sonar/python/checks/DeadStoreCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ private static void raiseIssue(SubscriptionContext ctx, DeadStoreUtils.Unnecessa
132132
.map(DeadStoreCheck::mapToParentAssignmentStatementOrExpression)
133133
.forEach(tree -> issue.secondary(tree, String.format(SECONDARY_MESSAGE_TEMPLATE, symbolName)));
134134

135-
if (element instanceof Statement && !isExceptionForQuickFix((Statement) element)) {
135+
if (element instanceof Statement statement && !isExceptionForQuickFix(statement)) {
136136
if (element.is(Tree.Kind.ASSIGNMENT_STMT) && ((AssignmentStatement) element).lhsExpressions().size() > 1) {
137137
addMultipleAssignmentStatementQuickFix((AssignmentStatement) element, issue, unnecessaryAssignment.symbol);
138138
} else {
139139
issue.addQuickFix(PythonQuickFix.newQuickFix(QUICK_FIX_MESSAGE,
140-
TextEditUtils.removeStatement((Statement) element)));
140+
TextEditUtils.removeStatement(statement)));
141141
}
142142
}
143143

python-checks/src/test/java/org/sonar/python/checks/CheckListTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ void validate_sqKey_field_in_json() throws IOException {
8888
List<Path> jsonList = fileStream
8989
.filter(path -> !path.toString().endsWith("Sonar_way_profile.json"))
9090
.sorted()
91-
.collect(Collectors.toList());
91+
.toList();
9292

9393
List<String> fileNames = jsonList.stream()
9494
.map(Path::getFileName)
9595
.map(Path::toString)
9696
.map(name -> name.replaceAll("\\.json$", ""))
97-
.collect(Collectors.toList());
97+
.toList();
9898

9999
List<String> sqKeys = jsonList.stream()
100100
.map(CheckListTest::extractSqKey)
101-
.collect(Collectors.toList());
101+
.toList();
102102

103103
assertThat(fileNames).isEqualTo(sqKeys);
104104
}
@@ -107,7 +107,7 @@ void validate_sqKey_field_in_json() throws IOException {
107107
@Test
108108
void test_no_deprecated_rule_in_default_profile() throws IOException, ParseException {
109109
try (Stream<Path> fileStream = Files.find(METADATA_DIR, 1, (path, attr) -> path.toString().endsWith(".json"))) {
110-
List<Path> jsonList = fileStream.collect(Collectors.toList());
110+
List<Path> jsonList = fileStream.toList();
111111

112112
Path sonarWayProfilePath = jsonList.stream().filter(path -> path.toString().endsWith("Sonar_way_profile.json")).findFirst().get();
113113
List<String> keysInDefaultProfile = getKeysInDefaultProfile(sonarWayProfilePath);
@@ -171,7 +171,7 @@ private static List<String> getKeysInDefaultProfile(Path sonarWayPath) throws IO
171171
JSONParser jsonParser = new JSONParser();
172172
JSONObject sonarWayJson = (JSONObject) jsonParser.parse(new InputStreamReader(in, UTF_8));
173173
JSONArray sonarWayKeys = (JSONArray) sonarWayJson.get("ruleKeys");
174-
return (List<String>) sonarWayKeys.stream().sorted().collect(Collectors.toList());
174+
return (List<String>) sonarWayKeys.stream().sorted().toList();
175175
}
176176

177177
private static String extractSqKey(Path jsonFile) {

python-checks/src/test/java/org/sonar/python/checks/quickfix/PythonQuickFixVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static void verify(Function<String, PythonVisitorContext> createVisitorCo
9696

9797
List<String> appliedQuickFix = issue.quickFixes().stream()
9898
.map(quickFix -> applyQuickFix(codeWithIssue, quickFix))
99-
.collect(Collectors.toList());
99+
.toList();
100100

101101
assertThat(appliedQuickFix)
102102
.as("The code with the quickfix applied is not the expected result.\n" +

python-frontend/src/main/java/org/sonar/plugins/python/api/cfg/ControlFlowGraph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public String toString() {
9898

9999
Function<Collection<CfgBlock>, List<CfgBlock>> sortedByDisplayString = list -> list.stream()
100100
.sorted(Comparator.comparing(Object::toString))
101-
.collect(Collectors.toList());
101+
.toList();
102102

103103
List<CfgBlock> sortedBlocks = sortedByDisplayString.apply(blocks);
104104
int graphNodeId = 0;

python-frontend/src/main/java/org/sonar/python/cfg/fixpoint/ReachingDefinitionsAnalysis.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void updateProgramState(Tree element, Map<Symbol, Set<Expression>> out)
205205
private void updateStateForAssignment(AssignmentStatement element, Map<Symbol, Set<Expression>> programState) {
206206
List<Expression> lhsExpressions = element.lhsExpressions().stream()
207207
.flatMap(exprList -> exprList.expressions().stream())
208-
.collect(Collectors.toList());
208+
.toList();
209209
performUpdate(programState, lhsExpressions, element::assignedValue);
210210
}
211211

python-frontend/src/main/java/org/sonar/python/index/DescriptorUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static ClassDescriptor classDescriptor(ClassSymbol classSymbol) {
6565
.withName(classSymbol.name())
6666
.withFullyQualifiedName(classSymbol.fullyQualifiedName())
6767
.withMembers(classSymbol.declaredMembers().stream().map(DescriptorUtils::descriptor).collect(Collectors.toSet()))
68-
.withSuperClasses(classSymbol.superClasses().stream().map(Symbol::fullyQualifiedName).filter(Objects::nonNull).collect(Collectors.toList()))
68+
.withSuperClasses(classSymbol.superClasses().stream().map(Symbol::fullyQualifiedName).filter(Objects::nonNull).toList())
6969
.withDefinitionLocation(classSymbol.definitionLocation())
7070
.withHasMetaClass(((ClassSymbolImpl) classSymbol).hasMetaClass())
7171
.withHasSuperClassWithoutDescriptor(((ClassSymbolImpl) classSymbol).hasSuperClassWithoutSymbol() ||
@@ -114,7 +114,7 @@ private static List<FunctionDescriptor.Parameter> parameters(List<FunctionSymbol
114114
parameter.isPositionalVariadic(),
115115
parameter.isKeywordVariadic(),
116116
parameter.location()
117-
)).collect(Collectors.toList());
117+
)).toList();
118118
}
119119

120120
// TODO SONARPY-958: Cleanup the symbol construction from descriptors by extracting this logic in a builder class
@@ -169,7 +169,7 @@ private static void addMembers(ClassSymbolImpl classSymbol, ClassDescriptor clas
169169
}
170170
return member;
171171
})
172-
.collect(Collectors.toList()));
172+
.toList());
173173
}
174174

175175
private static void addSuperClasses(ClassSymbolImpl classSymbol, ClassDescriptor classDescriptor,

python-frontend/src/main/java/org/sonar/python/index/DescriptorsToProtobuf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static DescriptorsProtos.ClassDescriptor toProtobuf(ClassDescriptor class
127127
public static DescriptorsProtos.FunctionDescriptor toProtobuf(FunctionDescriptor functionDescriptor) {
128128
DescriptorsProtos.FunctionDescriptor.Builder builder = DescriptorsProtos.FunctionDescriptor.newBuilder()
129129
.setName(functionDescriptor.name())
130-
.addAllParameters(functionDescriptor.parameters().stream().map(DescriptorsToProtobuf::toProtobuf).collect(Collectors.toList()))
130+
.addAllParameters(functionDescriptor.parameters().stream().map(DescriptorsToProtobuf::toProtobuf).toList())
131131
.setIsAsynchronous(functionDescriptor.isAsynchronous())
132132
.setIsInstanceMethod(functionDescriptor.isInstanceMethod())
133133
.addAllDecorators(functionDescriptor.decorators())

python-frontend/src/main/java/org/sonar/python/quickfix/TextEditUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static List<PythonTextEdit> shiftLeft(StatementList statementList) {
9797
.map(statement -> shiftLeft(statement, offset))
9898
.flatMap(List::stream)
9999
.distinct()
100-
.collect(Collectors.toList());
100+
.toList();
101101
}
102102

103103
/**
@@ -110,7 +110,7 @@ public static List<PythonTextEdit> shiftLeft(Tree tree, int offset) {
110110
.map(Token::line)
111111
.distinct()
112112
.map(line -> removeRange(line, 0, line, offset))
113-
.collect(Collectors.toList());
113+
.toList();
114114
}
115115

116116
public static PythonTextEdit removeRange(int startLine, int startColumn, int endLine, int endColumn) {

0 commit comments

Comments
 (0)