anonymous -> lambda: enable casts again (IDEA-157960)

This commit is contained in:
Anna Kozlova
2016-06-29 12:44:18 +03:00
parent 3cfd5be8c0
commit 153255f9d2
8 changed files with 69 additions and 25 deletions

View File

@@ -140,14 +140,6 @@ public class AnonymousCanBeLambdaInspection extends BaseJavaBatchLocalInspection
return true;
}
PsiType inferenceMethodReturnType = LambdaUtil.getFunctionalInterfaceReturnType(inferredType);
PsiType existingMethodReturnType = method.getReturnType();
if (existingMethodReturnType == null ||
inferenceMethodReturnType != null &&
!PsiType.VOID.equals(inferenceMethodReturnType) && !TypeConversionUtil.isAssignable(existingMethodReturnType, inferenceMethodReturnType)) {
return true;
}
final ForbiddenRefsChecker checker = new ForbiddenRefsChecker(method, aClass);
final PsiCodeBlock body = method.getBody();
LOG.assertTrue(body != null);

View File

@@ -0,0 +1,28 @@
// "Replace with lambda" "true"
import java.util.*;
import java.util.function.Function;
import static java.util.Collections.emptyList;
class Ambiguous {
public void setRoots(List<String> roots) {}
public static <T> List<T> concat(Iterable<? extends Collection<T>> list) {
return new ArrayList<T>();
}
public static <T> List<T> concat(List<List<? extends T>> lists) {
return new ArrayList<T>();
}
public static <T,V> List<V> map(Collection<? extends T> iterable, Function<T, V> mapping) {
return emptyList();
}
public void anonymousToLambda(HashSet<String> modules) {
setRoots(Ambiguous.concat(Ambiguous.map(modules, (Function<String, List<String>>) s -> null)
));
}
}

View File

@@ -0,0 +1,28 @@
// "Replace with lambda" "true"
import java.util.*;
import java.util.function.Function;
import static java.util.Collections.emptyList;
class Ambiguous {
public void setRoots(List<String> roots) {}
public static <T> List<T> concat(Iterable<? extends Collection<T>> list) {
return new ArrayList<T>();
}
public static <T> List<T> concat(List<List<? extends T>> lists) {
return new ArrayList<T>();
}
public static <T,V> List<V> map(Collection<? extends T> iterable, Function<T, V> mapping) {
return emptyList();
}
public void anonymousToLambda(HashSet<String> modules) {
setRoots(Ambiguous.concat(Ambiguous.map(modules, (Function<String, List<String>>) s -> Arrays.asList(""))
));
}
}

View File

@@ -1,4 +1,4 @@
// "Replace with lambda" "false"
// "Replace with lambda" "true"
class A {
{
bar(new Throwabl<caret>eComputable<String, Exception>() {

View File

@@ -1,4 +1,4 @@
// "Replace with lambda" "false"
// "Replace with lambda" "true"
import java.util.*;
class Test2 {

View File

@@ -1,4 +1,4 @@
// "Replace with lambda" "false"
// "Replace with lambda" "true"
import java.util.*;
import java.util.function.Function;

View File

@@ -1,4 +1,4 @@
// "Replace with lambda" "false"
// "Replace with lambda" "true"
import java.util.*;
import java.util.function.Function;

View File

@@ -1,5 +1,4 @@
import java.util.ArrayList;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -8,19 +7,16 @@ class A {
ArrayList<String> strings = new ArrayList<String>();
Stream<String> it = strings.stream();
int i = (int) it.flatMap((o) -> StreamSupport.stream(new Function<String, Iterable<String>>() {
@Override
public Iterable<String> apply(String o) {
if ('a' > 2) {
return getIterable();
} else if ('c' < 123) {
ArrayList<String> strings1 = new ArrayList<>();
strings1.add(o);
return strings1;
}
return null;
int i = (int) it.flatMap(o -> {
if ('a' > 2) {
return StreamSupport.stream(getIterable().spliterator(), false);
} else if ('c' < 123) {
ArrayList<String> strings1 = new ArrayList<>();
strings1.add(o);
return strings1.stream();
}
}.apply(o).spliterator(), false)).count();
return null;
}).count();
}