mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-170033 Support raw-types when converting Iterable.forEach to loop
This commit is contained in:
+4
-4
@@ -168,7 +168,7 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
PsiExpression qualifier = call.getMethodExpression().getQualifierExpression();
|
||||
if(qualifier != null) {
|
||||
PsiType elementType = StreamApiUtil.getStreamElementType(qualifier.getType());
|
||||
if (!isValidElementType(elementType, call)) return null;
|
||||
if (!isValidElementType(elementType, call, false)) return null;
|
||||
Operation op = Operation.createIntermediate(name, args, outVar, elementType, supportUnknownSources);
|
||||
if (op != null) return op;
|
||||
op = TerminalOperation.createTerminal(name, args, elementType, callType, isVoidContext(call.getParent()));
|
||||
@@ -179,8 +179,8 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
return SourceOperation.createSource(call, supportUnknownSources);
|
||||
}
|
||||
|
||||
private static boolean isValidElementType(PsiType elementType, PsiElement context) {
|
||||
if(elementType == null || ((elementType instanceof PsiClassType) && ((PsiClassType)elementType).isRaw())) {
|
||||
private static boolean isValidElementType(PsiType elementType, PsiElement context, boolean allowRaw) {
|
||||
if(elementType == null || (!allowRaw && (elementType instanceof PsiClassType) && ((PsiClassType)elementType).isRaw())) {
|
||||
// Raw type in any stream step is not supported
|
||||
return false;
|
||||
}
|
||||
@@ -213,7 +213,7 @@ public class StreamToLoopInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
FunctionHelper fn = FunctionHelper.create(args[0], 1, true);
|
||||
if (fn == null) return null;
|
||||
PsiType elementType = PsiUtil.substituteTypeParameter(type, CommonClassNames.JAVA_LANG_ITERABLE, 0, false);
|
||||
if(!isValidElementType(elementType, terminalCall)) return null;
|
||||
if(!isValidElementType(elementType, terminalCall, true)) return null;
|
||||
elementType = GenericsUtil.getVariableTypeByExpressionType(elementType);
|
||||
TerminalOperation terminal = new TerminalOperation.ForEachTerminalOperation(fn);
|
||||
SourceOperation source = new SourceOperation.ForEachSource(qualifier);
|
||||
|
||||
+6
@@ -25,6 +25,12 @@ public class Main {
|
||||
return collection;
|
||||
}
|
||||
|
||||
void testRawTypeSupport(List<List> list) {
|
||||
for (List l : list) {
|
||||
System.out.println(l.size());
|
||||
}
|
||||
}
|
||||
|
||||
public interface SomeInterface {
|
||||
|
||||
Set<? extends SomeInterface> nodes();
|
||||
|
||||
+4
@@ -19,6 +19,10 @@ public class Main {
|
||||
return collection;
|
||||
}
|
||||
|
||||
void testRawTypeSupport(List<List> list) {
|
||||
list.forEach(l -> System.out.println(l.size()));
|
||||
}
|
||||
|
||||
public interface SomeInterface {
|
||||
|
||||
Set<? extends SomeInterface> nodes();
|
||||
|
||||
Reference in New Issue
Block a user