mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
anonymous -> lambda: enable casts again (IDEA-157960)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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(""))
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Replace with lambda" "false"
|
||||
// "Replace with lambda" "true"
|
||||
class A {
|
||||
{
|
||||
bar(new Throwabl<caret>eComputable<String, Exception>() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Replace with lambda" "false"
|
||||
// "Replace with lambda" "true"
|
||||
import java.util.*;
|
||||
class Test2 {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Replace with lambda" "false"
|
||||
// "Replace with lambda" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Replace with lambda" "false"
|
||||
// "Replace with lambda" "true"
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user