Java inspection: Simplify stream API call chains (IDEA-140724, IDEA-156324)

This commit is contained in:
Pavel Dolgov
2016-05-25 14:34:32 +03:00
parent 0d167a1012
commit 0b542e981c
12 changed files with 341 additions and 0 deletions
@@ -0,0 +1,9 @@
// "Replace Arrays.asList().stream() with Arrays.stream()" "true"
import java.util.Arrays;
class AsListArrayStream {
String max(String[] args) {
return Arrays.stream(args).max(String::compareTo);
}
}
@@ -0,0 +1,10 @@
// "Replace Arrays.asList().stream() with Stream.of()" "true"
import java.util.Arrays;
import java.util.stream.Stream;
class AsListLiteralStream {
Stream<String> abc() {
return Stream.of("a", "b", "c");
}
}
@@ -0,0 +1,11 @@
// "Replace Collection.stream().forEach() with Collection.forEach()" "true"
import java.util.Arrays;
import java.util.Collection;
class Test {
void print() {
Collection<Character> def = Arrays.asList('d', 'e', 'f');
def.forEach(c -> System.out.print(" " + c));
}
}
@@ -0,0 +1,11 @@
// "Replace Collection.stream().forEach() with Collection.forEach()" "true"
import java.util.Arrays;
import java.util.Collection;
class Test {
void print() {
Collection<Character> def = Arrays.asList('d', 'e', 'f');
def.forEach(System.out::print);
}
}
@@ -0,0 +1,9 @@
// "Replace Arrays.asList().stream() with Arrays.stream()" "true"
import java.util.Arrays;
class AsListArrayStream {
String max(String[] args) {
return Arrays.asL<caret>ist(args).stream().max(String::compareTo);
}
}
@@ -0,0 +1,10 @@
// "Replace Arrays.asList().stream() with Stream.of()" "true"
import java.util.Arrays;
import java.util.stream.Stream;
class AsListLiteralStream {
Stream<String> abc() {
return Arrays.asList("a", "b", "c").stre<caret>am();
}
}
@@ -0,0 +1,11 @@
// "Replace Collection.stream().forEach() with Collection.forEach()" "true"
import java.util.Arrays;
import java.util.Collection;
class Test {
void print() {
Collection<Character> def = Arrays.asList('d', 'e', 'f');
def.st<caret>ream().forEach(c -> System.out.print(" " + c));
}
}
@@ -0,0 +1,11 @@
// "Replace Collection.stream().forEach() with Collection.forEach()" "true"
import java.util.Arrays;
import java.util.Collection;
class Test {
void print() {
Collection<Character> def = Arrays.asList('d', 'e', 'f');
def.stream().forE<caret>ach(System.out::print);
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2000-2016 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.
*/
package com.intellij.codeInspection;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NotNull;
/**
* @author Pavel.Dolgov
*/
public class SimplifyStreamApiCallChainsInspectionTest extends LightQuickFixParameterizedTestCase {
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new SimplifyStreamApiCallChainsInspection()};
}
public void test() throws Exception {
doAllTests();
}
@Override
protected Sdk getProjectJDK() {
return IdeaTestUtil.getMockJdk18();
}
@Override
protected String getBasePath() {
return "/inspection/streamApiCallChains";
}
}