[java-inspections] Do not remove sorting before takeWhile/dropWhile (IDEA-315563)

GitOrigin-RevId: cf48ecc1c050ce3dbafc04c3500dcdb286f9206e
This commit is contained in:
Tagir Valeev
2023-03-20 17:26:12 +00:00
committed by intellij-monorepo-bot
parent 380117325f
commit a2989f2a84
3 changed files with 11 additions and 17 deletions
@@ -45,7 +45,7 @@ public class RedundantStreamOptionalCallInspection extends AbstractBaseJavaLocal
private static final Map<String, String> CALLS_MAKING_SORT_USELESS_PARALLEL = Map.of("findAny", "findFirst",
"forEach", "forEachOrdered");
private static final Set<String> CALLS_KEEPING_SORT_ORDER =
Set.of("filter", "distinct", "boxed", "asLongStream", "asDoubleStream", "takeWhile", "dropWhile");
Set.of("filter", "distinct", "boxed", "asLongStream", "asDoubleStream");
private static final Set<String> CALLS_KEEPING_ELEMENTS_DISTINCT =
Set.of("filter", "boxed", "asLongStream", "limit", "skip", "sorted", "takeWhile", "dropWhile");
private static final Set<String> CALLS_AFFECTING_PARALLELIZATION = Set.of("sequential", "parallel");
@@ -89,6 +89,14 @@ public class RedundantStreamOptionalCall {
// another stream
c.parallelStream().sorted().findFirst().get().chars().parallel().forEach(System.out::println);
}
void dropWhileAndSort() {
List<String> collect = Stream.of("E", "D", "C", "B")
.sorted()
.dropWhile(x -> !x.equals("D"))
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
}
void parallelSorted(Collection<String> c) {
c.stream().sorted().forEach(x -> {});
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInspection;
import com.intellij.JavaTestUtil;
@@ -44,7 +30,7 @@ public class RedundantStreamOptionalCallInspectionTest extends LightJavaInspecti
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
return JAVA_17;
}
public static class RedundantStreamOptionalCallFixTest extends LightQuickFixParameterizedTestCase {