mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-167578 Uncompilable code after convertion forEach -> Loop with generics wildcard
This commit is contained in:
+1
@@ -199,6 +199,7 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
if (fn == null) return null;
|
||||
PsiType elementType = PsiUtil.substituteTypeParameter(type, CommonClassNames.JAVA_LANG_ITERABLE, 0, false);
|
||||
if(elementType == null) return null;
|
||||
elementType = GenericsUtil.getVariableTypeByExpressionType(elementType);
|
||||
TerminalOperation terminal = new TerminalOperation.ForEachTerminalOperation(fn);
|
||||
SourceOperation source = new SourceOperation.ForEachSource(qualifier);
|
||||
OperationRecord terminalRecord = new OperationRecord();
|
||||
|
||||
+21
-3
@@ -1,8 +1,6 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -19,4 +17,24 @@ public class Main {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends Collection<?>> T test(T collection) {
|
||||
for (Object o : collection) {
|
||||
System.out.println(o);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public interface SomeInterface {
|
||||
|
||||
Set<? extends SomeInterface> nodes();
|
||||
|
||||
default void accept(Visitor visitor) {
|
||||
for (SomeInterface child : new LinkedHashSet<>(this.nodes())) {
|
||||
child.accept(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
interface Visitor { }
|
||||
}
|
||||
}
|
||||
+17
-3
@@ -1,8 +1,6 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -15,4 +13,20 @@ public class Main {
|
||||
List<String> list = Arrays.asList("a", "b");
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public static <T extends Collection<?>> T test(T collection) {
|
||||
collection.forEach(System.out::println);
|
||||
return collection;
|
||||
}
|
||||
|
||||
public interface SomeInterface {
|
||||
|
||||
Set<? extends SomeInterface> nodes();
|
||||
|
||||
default void accept(Visitor visitor) {
|
||||
new LinkedHashSet<>(this.nodes()).forEach(child -> child.accept(visitor));
|
||||
}
|
||||
|
||||
interface Visitor { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user