mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix foreach matching
This commit is contained in:
+5
-7
@@ -40,10 +40,6 @@ public class SimplifyForEachInspection extends BaseJavaBatchLocalInspectionTool
|
||||
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM, "forEachOrdered").parameterCount(1);
|
||||
private static final CallMatcher STREAM_FOREACH =
|
||||
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM, "forEach", "forEachOrdered").parameterCount(1);
|
||||
private static final CallMatcher FOREACH = CallMatcher.anyOf(
|
||||
STREAM_FOREACH,
|
||||
ITERABLE_FOREACH
|
||||
);
|
||||
|
||||
|
||||
@Nls
|
||||
@@ -136,13 +132,15 @@ public class SimplifyForEachInspection extends BaseJavaBatchLocalInspectionTool
|
||||
@Nullable
|
||||
static PsiLambdaExpression extractLambdaFromForEach(PsiMethodCallExpression call) {
|
||||
PsiExpression qualifier = call.getMethodExpression().getQualifierExpression();
|
||||
if (qualifier == null ||
|
||||
!FOREACH.test(call) ||
|
||||
!InheritanceUtil.isInheritor(qualifier.getType(), CommonClassNames.JAVA_UTIL_COLLECTION)) return null;
|
||||
if (qualifier == null || !(STREAM_FOREACH.test(call) || isCollectionForEach(call, qualifier))) return null;
|
||||
PsiExpression arg = call.getArgumentList().getExpressions()[0];
|
||||
return tryCast(PsiUtil.skipParenthesizedExprDown(arg), PsiLambdaExpression.class);
|
||||
}
|
||||
|
||||
private static boolean isCollectionForEach(PsiMethodCallExpression call, PsiExpression qualifier) {
|
||||
return ITERABLE_FOREACH.test(call) && InheritanceUtil.isInheritor(qualifier.getType(), CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
}
|
||||
|
||||
static class LightExpressionStatement extends LightElement implements PsiExpressionStatement {
|
||||
@NotNull private final PsiExpression myExpression;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user